npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

javascript-i18n-library

v1.6.0

Published

This javascript library is used to format dates, numbers and currencies. It's compatible with Node and Browsers.

Downloads

920

Readme

javascript-i18n-library Circle CI npm version

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 = require('javascript-i18n-library');
var config = {
    referenceTimezone: 'Europe/Paris',
    timezone: 'Europe/Paris',
    locale: 'fr-FR',
    currency: 'EUR',
    dateFormat: 'DMY',
    isMeridianTime: false
};

var i18nService = i18nServiceFactory(config);

Configuration Browser

var config = {
    referenceTimezone: 'Europe/Paris',
    timezone: 'Europe/Paris',
    locale: 'fr-FR',
    currency: 'EUR',
    dateFormat: 'DMY',
    isMeridianTime: false
};

var i18nService = window.iadvize.i18nServiceFactory(config);

Usage

var dateToFormat = "1990-11-26T23:21:00"; // also accepts "1990-11-26 23:21:00" format

// Dates
i18nService.formatDate(dateToFormat);                            // 26/11/1990
i18nService.formatDate(dateToFormat, i18nService.formats.SHORT); // 26/11/1990
i18nService.formatDate(dateToFormat, i18nService.formats.MEDIUM); // 26/11/1990
i18nService.formatDate(dateToFormat, i18nService.formats.LONG);  // 26 novembre 1990

// Time
i18nService.formatTime(dateToFormat);                            // 23:21
i18nService.formatTime(dateToFormat, i18nService.formats.SHORT); // 23:21
i18nService.formatTime(dateToFormat, i18nService.formats.MEDIUM); // 23:21:00
i18nService.formatTime(dateToFormat, i18nService.formats.LONG);  // 23:21:00

// DateTime
i18nService.formatDateTime(dateToFormat);                            // 26/11/1990 23:21
i18nService.formatDateTime(dateToFormat, i18nService.formats.SHORT); // 26/11/1990 23:21
i18nService.formatDateTime(dateToFormat, i18nService.formats.MEDIUM); // 26/11/1990 23:21:00
i18nService.formatDateTime(dateToFormat, i18nService.formats.LONG);  // 26 novembre 1990 23:21:00

// TimeAgo
i18nService.getTimeAgoFromTimestamp(1444227494000 /* millis */);
i18nService.getTimeAgoFromDateTime(dateToFormat);

// Format numbers
i18nService.formatNumber(1000); // '1 000'
i18nService.unformat('1 000'); // 1000

i18nService.formatNumber(1000.1234); // '1 000,1234'
i18nService.formatNumber(1000.1234, 0); // '1 000'
i18nService.formatNumber(1000.1234, 1); // '1 000,1'

// Format currency
i18nService.formatCurrency(1000); // '1 000€'
i18nService.formatCurrency(1000, '$'), // 1 000$
i18nService.formatCurrency(1000.1234, 2, '$'), // 1 000,12$
i18nService.unformat('1 000€'); // 1000

// Format TimeAgo
i18nService.formatTimeAgoFromDateTime(dateToFormat); // il y a quelques secondes
i18nService.formatTimeAgoFromTimestamp(1444227494000 /* millis */); // il y a quelques secondes

// Libs exposition
i18nService.moment;
i18nService.momentTimezone;
i18nService.numbro;