Skip to content

Instantly share code, notes, and snippets.

@killercup
Created October 25, 2015 16:46
Show Gist options
  • Save killercup/9880e1af193311cb4734 to your computer and use it in GitHub Desktop.
Save killercup/9880e1af193311cb4734 to your computer and use it in GitHub Desktop.

Intl.js on Node 4.2

$ node --version
v4.2.1
$ npm --version
3.3.8
$ npm ls
intltest@1.0.0 /Users/pascal/Downloads/intltest
├── intl@1.0.1
└── intl-locales-supported@1.0.0
$ node index.js
421,337.66
421,337.66
421,337.66
10/25/2015, 5:45:58 PM
10/25/2015, 5:45:58 PM
10/25/2015, 5:45:58 PM
var areIntlLocalesSupported = require('intl-locales-supported');
var localesMyAppSupports = ["de", "en"];
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 patch the constructors we need with the polyfill's.
var IntlPolyfill = require('intl');
Intl.NumberFormat = IntlPolyfill.NumberFormat;
Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat;
}
} else {
// No `Intl`, so use and load the polyfill.
global.Intl = require('intl');
}
var number = 421337.66;
console.log(number.toLocaleString());
console.log(number.toLocaleString("en"));
console.log(number.toLocaleString("de"));
var date = new Date();
console.log(date.toLocaleString());
console.log(date.toLocaleString("en"));
console.log(date.toLocaleString("de"));
{
"name": "intltest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Pascal Hertleif <killercup@gmail.com> (http://pascalhertleif.de/)",
"license": "MIT",
"dependencies": {
"intl": "^1.0.1",
"intl-locales-supported": "^1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment