ms-i18n
A fork of ms that supports multiple languages (also named as locales).
Use this package to easily convert various time formats to milliseconds.
Examples
Available languages
- fr (french)
- en (english)
- es (spanish)
- pt (portuguese)
ms-i18n only works with the two letters long code (iso 639-1 code), not the full name of a lang
Initialising
const MSi18n = ; // replace lang with an iso 639-1 codeconst ms = lang // You can also do it like this (much simpler) : // replace lang with an iso 639-1 codeconst ms = new lang;
Basic usage
Note : These examples are only for the english language (it may change in the future)
ms; // 172800000ms; // 86400000ms; // 36000000ms; // 9000000ms; // 7200000ms; // 60000ms; // 5000ms; // 31557600000ms; // 100ms; // -259200000ms; // -3600000ms; // -200
Convert from Milliseconds
ms; // "1m"ms; // "2m"ms; // "-3m"ms; // "10h"
Time Format Written-Out
ms; // "1 minute"ms; // "2 minutes"ms; // "-3 minutes"ms; // "10 hours"
Lang-related properties
// Returns the ISO 639-1 code for this langmslangIsoCode // Returns the name of the lang, in the lang itselfmslangName // Returns the english name for this langmslangEnglishName
Features
- Works only with Node.js actually, but in the future we will make it works with browser
- If a number is supplied, a string with a unit is returned
- If a string that contains the number is supplied, it returns it as a number (e.g.: it returns
100
for'100'
) - If you pass a string with a number and a valid unit, the number of equivalent milliseconds is returned
Caught a bug / want to add language that isn't available ?
If you know how to fork :
- Fork this repository to your own GitHub account and then clone it to your local device
- Link the package to the global module directory:
npm link
- Within the module you want to test your local development instance of ms-i18n, just link it to the dependencies:
npm link ms-i18n
. Instead of the default one from npm, Node.js will now use your clone of ms-i18n!
As always, you can run the tests using: npm test
If you don't know how to fork :
You can still create an issue in the repository