javascript-i18n-library
This javascript library is used to format dates, numbers and currencies. It's compatible with Node and Browsers. It depends on Moment.JS and Numbro.JS
Installation
npm install javascript-i18n-library --save
Test
npm test
To automatically launch the tests when a file is changed :
npm run-script watch-test
Configuration
The factory accept a config object to override default configuration.
referenceTimezone: 'Europe/Paris' // timezone used when no timezone is defined on the date to parse timezone: 'Europe/Paris' // timezone used to format the date offset: 120 // override the targetTimezone, add this offset (in minutes) to the parsed date locale: 'fr-FR' // locale used to format numbers, currencies and long date format currency: 'EUR' // the currency to use when formatting currencies values dateFormat: 'DMY' // generic format date (DMY, MDY or YMD) isMeridianTime: false // format the time in meridian time or 24 hours time
Configuration Node / Browserify
var i18nServiceFactory = ;var config =referenceTimezone: 'Europe/Paris'timezone: 'Europe/Paris'locale: 'fr-FR'currency: 'EUR'dateFormat: 'DMY'isMeridianTime: false;var i18nService = ;
Configuration Browser
var config =referenceTimezone: 'Europe/Paris'timezone: 'Europe/Paris'locale: 'fr-FR'currency: 'EUR'dateFormat: 'DMY'isMeridianTime: false;var i18nService = windowiadvize;
Usage
var dateToFormat = "1990-11-26T23:21:00"; // also accepts "1990-11-26 23:21:00" format // Datesi18nService; // 26/11/1990i18nService; // 26/11/1990i18nService; // 26/11/1990i18nService; // 26 novembre 1990 // Timei18nService; // 23:21i18nService; // 23:21i18nService; // 23:21:00i18nService; // 23:21:00 // DateTimei18nService; // 26/11/1990 23:21i18nService; // 26/11/1990 23:21i18nService; // 26/11/1990 23:21:00i18nService; // 26 novembre 1990 23:21:00 // TimeAgoi18nService;i18nService; // Format numbersi18nService; // '1 000'i18nService; // 1000 i18nService; // '1 000,1234'i18nService; // '1 000'i18nService; // '1 000,1' // Format currencyi18nService; // '1 000€'i18nService // 1 000$i18nService // 1 000,12$i18nService; // 1000 // Format TimeAgoi18nService; // il y a quelques secondesi18nService; // il y a quelques secondes // Libs expositioni18nServicemoment;i18nServicemomentTimezone;i18nServicenumbro;