An open API service indexing awesome lists of open source software.

https://github.com/muratgozel/locale-util

Unicode CLDR data parser and module, regularly updated based on unicode.org releases.
https://github.com/muratgozel/locale-util

cldr cldr-json country-codes currency-codes i18n languages locale locale-gen localization phone-number timezones

Last synced: 5 months ago
JSON representation

Unicode CLDR data parser and module, regularly updated based on unicode.org releases.

Awesome Lists containing this project

README

        

# locale-util
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.

## Installation
```sh
npm install locale-util
```

## Usage
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:
```js
import {isCountryCode, findCountry, findCallingCode, findCountryLanguages,
isCurrencyCode, findCurrency, isLanguageCode, findLanguage,
findCountryTimezones, findTimezoneOffset, findTerritories, findCountryTerritory
} 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

findTerritories() /*
[
{
"code": "005",
"name": "South America"
},
{
"code": "011",
"name": "Western Africa"
},
...
...
]
*/

findCountryTerritory('TR') // { code: '145', name: 'Western Asia' }
findCountryTerritory('TR') // { code: '021', name: 'Northern America' }
```

Have a look at the tests, types and source for more info.

## Keeping Data Up To Date
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.

## Contributing
If you're interested in contributing, read the [CONTRIBUTING.md](https://github.com/muratgozel/muratgozel/blob/main/CONTRIBUTING.md) first, please.

---

Version management of this repository done by [releaser](https://github.com/muratgozel/node-releaser) 🚀

---

Thanks for watching 🐬

[![Support me on Patreon](https://cdn.muratgozel.com.tr/support-me-on-patreon.v1.png)](https://patreon.com/muratgozel?utm_medium=organic&utm_source=github_repo&utm_campaign=github&utm_content=join_link)