Unicode CLDR data parser and module, regularly updated based on https://github.com/unicode-org/cldr releases. Refer to https://muratgozel.github.io/locale-util/ for full api docs.
npm install locale-util
The package contains large amount of data which is not suitable for browser environment. Benefit from tree-shaking might work if you are interested in small chunks of it.
Here are the methods that you can use to interact with the data:
import {isCountryCode, findCountry, findCallingCode, findCountryLanguages,
isCurrencyCode, findCurrency, isLanguageCode, findLanguage,
findCountryTimezones, findTimezoneOffset} from 'locale-util'
isCountryCode('TR') // true
isCountryCode('XX') // false
findCountry('TR') /*
{
'code': 'TR',
'englishName': 'Türkiye',
'nativeName': 'Türkiye'
}
*/
findCountry('ABC') // undefined
findCountryCallingCode('US') // 1
findCountryCallingCode('TR') // 90
findCountryCallingCode(null) // undefined
findCountryLanguages('TR') // ['tr']
findCountryLanguages('US') // ['en', 'es', 'haw']
isCurrencyCode('TRY') // true
findCurrency('TRY') /*
{
'code': 'TRY',
'num': 949,
'englishName': 'Turkish',
'nativeName': 'Türkçe'
}
*/
findCountryCurrencyCode('TR') // TRY
findCountryCurrencyCode('US') // USD
isLanguageCode('xxx') // false
isLanguageCode('tr') // true
findLanguage('tr') /*
{
'code': 'tr',
'nativeName': 'Türkçe',
'englishName': 'Turkish'
}
*/
findCountryTimezones('TR') /*
[{
'name': 'Europe/Istanbul',
'offset': -180,
'country': 'TR'
}]
*/
findCountryTimezones('TT') /*
[{
'name': 'America/Port_of_Spain',
'offset': 240,
'country': 'TT'
}, {
'name': 'America/Puerto_Rico',
'offset': 240,
'country': 'TT'
}]
*/
findTimezoneOffset('America/Puerto_Rico') // 240
findTimezoneOffset('Europe/Istanbul') // -180
Have a look at the tests, types and source for more info.
Data updates published regularly as minor releases so you only need to update the package as new version comes in. If you have a kind of manual setup, download the release you wish from https://github.com/unicode-org/cldr/releases and copy the common
directory under cldr-data-common
. Then run npm run setup
, compile
, build
and test
to parse the new data.
If you're interested in contributing, read the CONTRIBUTING.md first, please.
Version management of this repository done by releaser 🚀
Thanks for watching 🐬
Generated using TypeDoc