Skip to content
/ intl-data Public

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

License

Notifications You must be signed in to change notification settings

ozum/intl-data

Repository files navigation

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

Table of contents

Interfaces

Functions

Functions

getCurrency

getCurrency<T>(currencyCode: T, locale?: string): T

Type parameters:

| Name | Type | | ---- | ----------- | ------ | | T | undefined | null |

Parameters:

Name Type
currencyCode T
locale? string

Returns: T

Defined in: intl-data.ts:37

getCurrency(currencyCode: string | null | undefined, locale?: string): Currency | null | undefined

Parameters:

| Name | Type | | -------------- | -------- | ------ | ----------- | | currencyCode | string | null | undefined | | locale? | string |

Returns: Currency | null | undefined

Defined in: intl-data.ts:38


getLocale

getLocale(localeCode: string): Locale

Parameters:

Name Type
localeCode string

Returns: Locale

Defined in: intl-data.ts:79

getLocale<T>(localeCode: T): T

Type parameters:

| Name | Type | | ---- | ----------- | ------ | | T | undefined | null |

Parameters:

Name Type
localeCode T

Returns: T

Defined in: intl-data.ts:80

getLocale(localeCode: string | null | undefined): Locale | undefined | null

Parameters:

| Name | Type | | ------------ | -------- | ------ | ----------- | | localeCode | string | null | undefined |

Returns: Locale | undefined | null

Defined in: intl-data.ts:81

Interfaces

intl-data / Currency

Interface: Currency

Information about currency

Hierarchy

  • Currency

Table of contents

Properties

Properties

code

code: string

ISO 4217 currency codes

Defined in: intl-data.ts:27


decimalPlaces

decimalPlaces: number

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

Defined in: intl-data.ts:29


name

name: string

Name of the currency.

Defined in: intl-data.ts:25


symbol

symbol: string

Currency symbol such as , $,

Defined in: intl-data.ts:31

intl-data / Locale

Interface: Locale

Information about locale.

Hierarchy

  • Locale

Table of contents

Properties

Properties

code

code: string

BCP 47 language tag of the locale. This is simply string provided to get locale. Example: tr-TR

Defined in: intl-data.ts:9


currencySymbolPlacement

currencySymbolPlacement: p | s

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

Defined in: intl-data.ts:15


decimalCharacter

decimalCharacter: string

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

Defined in: intl-data.ts:11


digitGroupSeparator

digitGroupSeparator: string

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

Defined in: intl-data.ts:13


percentSymbol

percentSymbol: string

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

Defined in: intl-data.ts:19


percentSymbolPlacement

percentSymbolPlacement: p | s

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

Defined in: intl-data.ts:17

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published