### Install intl-number-helper Source: https://github.com/thiagodp/intl-number-helper/blob/master/readme.md Install the intl-number-helper package using npm. This package does not polyfill Intl.NumberFormat. ```bash npm i intl-number-helper ``` -------------------------------- ### ESM/NodeJS Examples Source: https://github.com/thiagodp/intl-number-helper/blob/master/readme.md Provides various examples of using the formatNumber function in an ESM or NodeJS environment. It showcases different formatting patterns for currency, decimal, percentage, and unit notations. ```typescript import { formatNumber } from 'intl-number-helper'; // US$123,456.00 console.log( formatNumber( 123456, 'en-US', '$' ) ); ``` ```typescript // R$ 123.456,00 console.log( formatNumber( 123456, 'pt-BR', '$7.2' ) ); ``` ```typescript // 123,456.00 American dollars console.log( formatNumber( 123456, 'en-US', 'n' ) ); ``` ```typescript // 123,456.00 console.log( formatNumber( 123456, 'en-US', 'd.2' ) ); ``` ```typescript // 123,456 console.log( formatNumber( 123456, 'en-US', 'd' ) ); ``` ```typescript // 123456 console.log( formatNumber( 123456, 'en-US', 'd#' ) ); ``` ```typescript // 75% console.log( formatNumber( 0.75, 'en-US', '%' ) ); ``` ```typescript // 100 kilometers per hour console.log( formatNumber( 100, 'en-US', 'u', { unit: 'kilometer-per-hour', unitDisplay: 'long' } ) ); ``` -------------------------------- ### Browser Usage Source: https://github.com/thiagodp/intl-number-helper/blob/master/readme.md Demonstrates how to include and use the intl-number-helper library in a web browser via a script tag. It shows a basic example of formatting a number. ```html ``` -------------------------------- ### DenoJS Usage Source: https://github.com/thiagodp/intl-number-helper/blob/master/readme.md Shows how to import and use the intl-number-helper library in a DenoJS environment, utilizing an import map for the module. It provides a simple formatting example. ```typescript // Alternatively, use an import map and include it like NodeJS import { formatNumber } from "https://unpkg.com/intl-number-helper/index.esm.js"; console.log( formatNumber( 123456, 'en-US', 'd' ) ); // 123,456 ``` -------------------------------- ### Make Options API Source: https://github.com/thiagodp/intl-number-helper/blob/master/readme.md Creates an Intl.NumberFormatOptions object from a given pattern string. This is useful for programmatically generating formatting options. An example demonstrates its usage with Intl.NumberFormat. ```typescript /** * Creates a `Intl.NumberFormatOptions` object from a given pattern. * @param pattern Pattern. Optional. It generates an empty options object by default. * @param additionalOptions Options to be added to those generated from the pattern. Optional. Useful for units. * * @example * const options = makeOptions( '$', { currency: 'USD' } ); * const numberStr = new Intl.NumberFormat( 'en-US', options ).format( 123456 ); * */ function makeOptions( pattern?: string, additionalOptions?: Intl.NumberFormatOptions ): Intl.NumberFormatOptions; ``` -------------------------------- ### Basic Usage of formatNumber Source: https://github.com/thiagodp/intl-number-helper/blob/master/readme.md Demonstrates the basic usage of the formatNumber function, comparing it to the standard Intl.NumberFormat options. It shows how to format a number with a currency symbol. ```typescript const options = { style: 'currency', currencyDisplay: 'symbol', currency: 'USD' }; const numberStr = new Intl.NumberFormat( 'en-US', options ).format( 123456 ); ``` ```typescript const numberStr = formatNumber( 123456, 'en-US', '$' ); // Guesses the currency code ``` -------------------------------- ### makeOptions Source: https://github.com/thiagodp/intl-number-helper/blob/master/readme.md Creates an Intl.NumberFormatOptions object from a given pattern string and additional options. This is useful for pre-configuring formatting options. ```APIDOC ## makeOptions ### Description Creates a `Intl.NumberFormatOptions` object from a given pattern. ### Parameters #### Path Parameters - **pattern** (string) - Optional - Pattern. It generates an empty options object by default. - **additionalOptions** (Intl.NumberFormatOptions) - Optional - Options to be added to those generated from the pattern. Useful for units. ### Example ```typescript const options = makeOptions( '$', { currency: 'USD' } ); const numberStr = new Intl.NumberFormat( 'en-US', options ).format( 123456 ); ``` ``` -------------------------------- ### formatNumber Source: https://github.com/thiagodp/intl-number-helper/blob/master/readme.md Formats a number according to the specified locale and pattern. It can also accept additional options for customization. ```APIDOC ## formatNumber ### Description Formats a number. ### Parameters #### Path Parameters - **value** (number) - Required - Value to be formatted. - **locale** (string) - Required - Locale. When `pattern` uses currency, it guesses the currency from the country code. - **pattern** (string) - Optional - Pattern. It generates an empty options object by default. - **additionalOptions** (Intl.NumberFormatOptions) - Optional - Options to be added to those generated from the pattern. Useful for units. ### Throws - Error When ``` -------------------------------- ### isPatternCorrect Source: https://github.com/thiagodp/intl-number-helper/blob/master/readme.md Validates if a given pattern string is correctly formatted according to the library's rules. ```APIDOC ## isPatternCorrect ### Description Indicates if the given pattern is correct. ### Parameters #### Path Parameters - **pattern** (string) - Required - Pattern ``` -------------------------------- ### Format Number API Source: https://github.com/thiagodp/intl-number-helper/blob/master/readme.md Formats a number using a specified locale and an optional pattern. The pattern can influence locale-specific formatting rules. Additional options can be provided for further customization. ```typescript /** * Formats a number. * * @param value Value to be formatted. * @param locale Locale. When `pattern` uses currency, it guesses the currency from the country code. * @param pattern Pattern. Optional. It generates an empty options object by default. * @param additionalOptions Options to be added to those generated from the pattern. Optional. Useful for units. * * @throws Error When */ function formatNumber( value: number, locale: string, pattern?: string, additionalOptions?: Intl.NumberFormatOptions ): string; ``` -------------------------------- ### Is Pattern Correct API Source: https://github.com/thiagodp/intl-number-helper/blob/master/readme.md Validates if a given pattern string is correctly formatted according to the library's rules. This function helps in ensuring that patterns used for number formatting are valid before attempting to use them. ```typescript /** * Indicates if the given pattern is correct. * * @param pattern Pattern */ function isPatternCorrect( pattern: string ): boolean; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.