Tiny module to retrieve locale and currency data from native builtin Intl object without locale data transfer or additional locale files.


Keywords
locale, currency, intl, native
License
MIT
Install
npm install intl-data@1.0.11

Documentation

intl-data

Tiny module to retrieve locale and currency data from native builtin Intl object without locale data transfer or additional locale files.

Installation

Format Instructions
TypeScript import { ... } from "intl-data";
Node (CommonJS) const { ... } = require("intl-data");
ES Modules (Browsers, webpack) import { ... } from "intl-data";
UMD (Browser Global) <script src="path/to/umd/intl-data.js"></script>
UMD (Browser Global) (min) <script src="path/to/umd/intl-data.min.js"></script>

All unminified and minified bundle files are located in respective directories named after format (cjs, esm, umd) in dist (dist/cjs/intl-data.js and intl-data.min.js)

Synopsis

import { getLocale, getCurrency } from "intl-data";

const locale = getLocale("tr-TR");            // { digitGroupSeparator: ".", decimalCharacter: ",", currencySymbolPlacement: "p", percentSymbolPlacement: "p", percentSymbol: "%" }
const currency = getCurrency("TRY");          // { symbol: "₺", decimalPlaces: 2 }
const currency = getCurrency("TRY", "en-US"); // { symbol: '₺', decimalPlaces: 2, name: 'Turkish Lira' }

Details

Retrieves locale and currency.

Modern browsers and node.js have builtin Intl object, and this module uses this object. As a result it does not need to transfer additional locale files or data.

API

intl-data

intl-data

Functions

getCurrency

getCurrency(currencyCode: string): CurrencyWithoutName

Defined in intl-data.ts:42

Returns currency details for given currency and optionally locale. Throws error for unknown currency codes.

Parameters:

Name Type Description
currencyCode string is the currency to use in currency formatting. Possible values are the ISO 4217 currency codes, such as "USD" for the US dollar.

Returns: CurrencyWithoutName

currency details for requested currency. Also returns null for null input and undefined for undefined input.

getCurrency(currencyCode: string, locale: string): Currency

Defined in intl-data.ts:43

Returns currency details for given currency and optionally locale. Throws error for unknown currency codes.

Parameters:

Name Type Description
currencyCode string is the currency to use in currency formatting. Possible values are the ISO 4217 currency codes, such as "USD" for the US dollar.
locale string is the optional string with a BCP 47 language tag. If provided returned object contains currency name in given locale.

Returns: Currency

currency details for requested currency. Also returns null for null input and undefined for undefined input.

getCurrency<T>(currencyCode: T): T

Defined in intl-data.ts:44

Returns currency details for given currency and optionally locale. Throws error for unknown currency codes.

Type parameters:

T: null | undefined

Parameters:

Name Type Description
currencyCode T is the currency to use in currency formatting. Possible values are the ISO 4217 currency codes, such as "USD" for the US dollar.

Returns: T

currency details for requested currency. Also returns null for null input and undefined for undefined input.


getLocale

getLocale(locale: string, options?: undefined | object): Locale

Defined in intl-data.ts:88

Returns locale details for given locale. Throws error for unsupported locales.

Parameters:

Name Type Description
locale string is the string with a BCP 47 language tag. If provided returned object contains currency name in given locale.
options? undefined | object -

Returns: Locale

locale data for requested locale. Also returns null for null input and undefined for undefined input.

getLocale<T>(locale: T): T

Defined in intl-data.ts:89

Returns locale details for given locale. Throws error for unsupported locales.

Type parameters:

T: null | undefined

Parameters:

Name Type Description
locale T is the string with a BCP 47 language tag. If provided returned object contains currency name in given locale.

Returns: T

locale data for requested locale. Also returns null for null input and undefined for undefined input.

Interfaces

intl-dataCurrency

Interface: Currency

Information about currency including it's name.

Hierarchy

Properties

decimalPlaces

decimalPlaces: number

Inherited from CurrencyWithoutName.decimalPlaces

Defined in intl-data.ts:23

Number of digits used in decimal (fractional) part of the currency.


name

name: string

Defined in intl-data.ts:31

Name of the currency.


symbol

symbol: string

Inherited from CurrencyWithoutName.symbol

Defined in intl-data.ts:25

Currency symbol such as , $,

intl-dataCurrencyWithoutName

Interface: CurrencyWithoutName

Information about currency excluding it's name.

Hierarchy

Properties

decimalPlaces

decimalPlaces: number

Defined in intl-data.ts:23

Number of digits used in decimal (fractional) part of the currency.


symbol

symbol: string

Defined in intl-data.ts:25

Currency symbol such as , $,

intl-dataLocale

Interface: Locale

Information about locale.

Hierarchy

  • Locale

Properties

currencySymbolPlacement

currencySymbolPlacement: "p" | "s"

Defined in intl-data.ts:13

Place of currency symbol: p for prefix such as $1.95, or s for suffix such as 1.95$


decimalCharacter

decimalCharacter: string

Defined in intl-data.ts:9

Character to separate decimal (fraction) parts of the number from integer parts.


digitGroupSeparator

digitGroupSeparator: string

Defined in intl-data.ts:11

Grouping separators for integer parts, such as thousands separators or thousand/lakh/crore separators.


percentSymbol

percentSymbol: string

Defined in intl-data.ts:17

Percent symbol. Some locales contains spcae for percent symbol such as 12 %, and some not 12%. This is used to differenciate them.


percentSymbolPlacement

percentSymbolPlacement: "p" | "s"

Defined in intl-data.ts:15

Place of percent symbol: p for prefix such as %12, or s for suffix such as 12%