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.
- Host: GitHub
- URL: https://github.com/muratgozel/locale-util
- Owner: muratgozel
- License: mit
- Created: 2019-12-17T11:25:36.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-08-19T23:02:29.000Z (9 months ago)
- Last Synced: 2024-08-21T00:43:56.475Z (9 months ago)
- Topics: cldr, cldr-json, country-codes, currency-codes, i18n, languages, locale, locale-gen, localization, phone-number, timezones
- Language: TypeScript
- Homepage: https://muratgozel.github.io/locale-util/
- Size: 6.12 MB
- Stars: 9
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
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') // falsefindCountry('TR') /*
{
'code': 'TR',
'englishName': 'Türkiye',
'nativeName': 'Türkiye'
}
*/
findCountry('ABC') // undefinedfindCountryCallingCode('US') // 1
findCountryCallingCode('TR') // 90
findCountryCallingCode(null) // undefinedfindCountryLanguages('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') // USDisLanguageCode('xxx') // false
isLanguageCode('tr') // truefindLanguage('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') // -180findTerritories() /*
[
{
"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 🐬
[](https://patreon.com/muratgozel?utm_medium=organic&utm_source=github_repo&utm_campaign=github&utm_content=join_link)