intl-locales-supported
Version:
Utility to help you polyfill the Node.js runtime when the Intl APIs are missing, or if the built-in Intl is missing locale data that you need.
46 lines (33 loc) • 1.56 kB
Markdown
intl-locales-supported
======================
Utility to help you polyfill the Node.js runtime when the [`Intl`][Intl] APIs are missing, or if the built-in `Intl` is missing locale data that you need.
[![npm Version][npm-badge]][npm]
```js
var areIntlLocalesSupported = require('intl-locales-supported');
var localesMyAppSupports = [
/* list locales here */
];
if (global.Intl) {
// Determine if the built-in `Intl` has the locale data we need.
if (!areIntlLocalesSupported(localesMyAppSupports)) {
// `Intl` exists, but it doesn't have the data we need, so load the
// polyfill and replace the constructors we need with the polyfill's.
require('intl');
Intl.NumberFormat = IntlPolyfill.NumberFormat;
Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat;
}
} else {
// No `Intl`, so use and load the polyfill.
global.Intl = require('intl');
}
```
For more details, see the [FormatJS guide on polyfillying `Intl` in Node.js](http://formatjs.io/guides/runtime-environments/#polyfill-node).
This software is free to use under the Yahoo! Inc. BSD license.
See the [LICENSE file][LICENSE] for license text and copyright information.
[]: https://www.npmjs.org/package/intl-locales-supported
[]: https://img.shields.io/npm/v/intl-locales-supported.svg?style=flat-square
[]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl
[]: http://formatjs.io/
[]: https://github.com/formatjs/formatjs/blob/master/LICENSE