项目作者: muratgozel

项目描述 :
Locale data generators written in node.js. Uses reliable sources. Generated data available as JS/JSON objects.
高级语言: JavaScript
项目地址: git://github.com/muratgozel/locale-util.git
创建时间: 2019-12-17T11:25:36Z
项目社区:https://github.com/muratgozel/locale-util

开源协议:MIT License

下载


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

  1. 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:

  1. import {isCountryCode, findCountry, findCallingCode, findCountryLanguages,
  2. isCurrencyCode, findCurrency, isLanguageCode, findLanguage,
  3. findCountryTimezones, findTimezoneOffset, findTerritories, findCountryTerritory
  4. } from 'locale-util'
  5. isCountryCode('TR') // true
  6. isCountryCode('XX') // false
  7. findCountry('TR') /*
  8. {
  9. 'code': 'TR',
  10. 'englishName': 'Türkiye',
  11. 'nativeName': 'Türkiye'
  12. }
  13. */
  14. findCountry('ABC') // undefined
  15. findCountryCallingCode('US') // 1
  16. findCountryCallingCode('TR') // 90
  17. findCountryCallingCode(null) // undefined
  18. findCountryLanguages('TR') // ['tr']
  19. findCountryLanguages('US') // ['en', 'es', 'haw']
  20. isCurrencyCode('TRY') // true
  21. findCurrency('TRY') /*
  22. {
  23. 'code': 'TRY',
  24. 'num': 949,
  25. 'englishName': 'Turkish',
  26. 'nativeName': 'Türkçe'
  27. }
  28. */
  29. findCountryCurrencyCode('TR') // TRY
  30. findCountryCurrencyCode('US') // USD
  31. isLanguageCode('xxx') // false
  32. isLanguageCode('tr') // true
  33. findLanguage('tr') /*
  34. {
  35. 'code': 'tr',
  36. 'nativeName': 'Türkçe',
  37. 'englishName': 'Turkish'
  38. }
  39. */
  40. findCountryTimezones('TR') /*
  41. [{
  42. 'name': 'Europe/Istanbul',
  43. 'offset': -180,
  44. 'country': 'TR'
  45. }]
  46. */
  47. findCountryTimezones('TT') /*
  48. [{
  49. 'name': 'America/Port_of_Spain',
  50. 'offset': 240,
  51. 'country': 'TT'
  52. }, {
  53. 'name': 'America/Puerto_Rico',
  54. 'offset': 240,
  55. 'country': 'TT'
  56. }]
  57. */
  58. findTimezoneOffset('America/Puerto_Rico') // 240
  59. findTimezoneOffset('Europe/Istanbul') // -180
  60. findTerritories() /*
  61. [
  62. {
  63. "code": "005",
  64. "name": "South America"
  65. },
  66. {
  67. "code": "011",
  68. "name": "Western Africa"
  69. },
  70. ...
  71. ...
  72. ]
  73. */
  74. findCountryTerritory('TR') // { code: '145', name: 'Western Asia' }
  75. 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 first, please.


Version management of this repository done by releaser 🚀


Thanks for watching 🐬

Support me on Patreon