VI18N
Simple number, currency, type and date formatters based on the Internationalization API.
Requirements
- Intl object (ECMAScript Internationalization API) see the support.
- You can include the polyfill when supporting older environments.
- Or use the Financial Times polyfill service at cdn.polyfill.io.
Installation
npm install --save vi18n
Examples
Creating a locale
; // const locale = new VI18N(culture, options); const nl = ; // Default locale is 'nl-NL' (Dutch)const uk = 'en-GB'; // overriding default settings with optionsconst ch = 'de-ch' number: maximumFractionDigits: 2 ;const nl = 'nl-NL' percent: minimumFractionDigits: 2 ;const jp = 'ja' currency: currency: 'JPY' ; const uk = 'en-GB' time: timeZone: 'etc/UTC' currency: currency: 'GBP' ; const us = 'en-US' time: hour: 'numeric' currency: currency: 'USD' ;
The options
parameter can contain the following configuration objects:
number
percent
currency
time
See MDN: NumberFormat for possible values for the number
, percent
and currency
configuration objects.
See MDN: DateTimeFormat for possible values for the time
configuration object.
Number formatting
nl; // '12,50'uk; // '12.50'
Currency formatting
nl; // '€ 12,50'uk; // '£12.50'
Percent formatting
nl; // '75%'uk; // '75%'
Date and time formatting
var date = ; nl; // '2-9-2015'uk; // '02/09/2015' nl; // '12:38:09'uk; // '12:38:09'
Decimal and thousand separator
nl; // ','nl; // '.'
Months and days
// Possible representations are 'narrow', 'short' or 'long' (default). uk // [ 'January', 'February', 'March', etc. ]uk // [ 'Jan', 'Feb', 'Mar', etc. ]uk // [ 'J', 'F', 'M', etc. ] uk // [ 'Sunday', 'Monday', 'Tuesday', etc. ]uk // [ 'Sun', 'Mon', 'Tue', etc. ]uk // [ 'S', 'M', 'T', etc. ]
Static methods
// Check for native browser support or the presence of a polyfill.VI18N;
License
MIT © VI Company