VI18N
Simple number, currency, type and date formatters based on the Internationalization API.
Requirements
Installation
npm install --save vi18n
Examples
Creating a locale
import VI18N from 'vi18n';
const nl = new VI18N();
const uk = new VI18N('en-GB');
const ch = new VI18N('de-ch', { number: { maximumFractionDigits: 2 } });
const nl = new VI18N('nl-NL', { percent: { minimumFractionDigits: 2 } });
const jp = new VI18N('ja', { currency: { currency: 'JPY' } });
const uk = new VI18N('en-GB', {
time: { timeZone: 'etc/UTC' },
currency: { currency: 'GBP' },
});
const us = new VI18N('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.formatNumber(12.50);
uk.formatNumber(12.50);
Currency formatting
nl.formatCurrency(12.50);
uk.formatCurrency(12.50);
Percent formatting
nl.formatPercent(0.75);
uk.formatPercent(0.75);
Date and time formatting
var date = new Date();
nl.formatDate(date);
uk.formatDate(date);
nl.formatTime(date);
uk.formatTime(date);
Decimal and thousand separator
nl.getDecimalSeparator();
nl.getThousandSeparator();
Months and days
uk.getMonths()
uk.getMonths('short')
uk.getMonths('narrow')
uk.getDays()
uk.getDays('short')
uk.getDays('narrow')
Static methods
VI18N.isSupported();
License
MIT © VI Company