Introduction
numeros is a lightweight, small, simple javascript liberary that helps you to formate your numbers
into different forms including Currency, Timing, Computer Storage Units and Metric System Units (gram, liter, meter)
Installation
npm install numeros@latest
Usage
-
Currency Format
if you have any number that specify an amount of a specific currency, use this class as following
const { CurrencyFormatter } = require("numeros");
import { CurrencyFormatter } from "numeros";
const cf = new CurrencyFormatter();
in short format
the short formate method take an amount in an currency (default is USD) and return it in a shorten way like this
console.log(cf.shortFormat(2000));
console.log(cf.shortFormat(-5250360.6));
console.log(cf.shortFormat(2 * 10 ** 12));
console.log(cf.shortFormat(0.35));
console.log(cf.shortFormat(3500, "EUR"));
console.log(cf.shortFormat(48350, cf.currenciesList.EUR));
console.log(cf.shortFormat(500000), cf.currenciesList.EUR, ".");
In standard format
standard format method has the same options as short format , however the value will remain the
same in standard format without any roundings as so:
console.log(cf.standerdFormat(1800320, "GBP"));
console.log(cf.standerdFormat(2500.32));
console.log(cf.standerdFormat(88356.36), "EUR", ".");
console.log(cf.standerdFormat(88356.36), "EUR", "_");
-
Timing Format
you will basicly use this formatter when dealing with times in milliseconds coming from a database
the value will be converted to seconds, mintues, hours... and other timing units until year
const { TimingFormatter } = require("numeros");
const tf = new TimingFormatter();
console.log(tf.formate(3000));
console.log(tf.formate(35 * 1000 * 3600));
console.log(tf.formate(2 * 1000 * 3600 * 24));
-
Computer Storage Unit Format
use this to convert between the differnet storage unit of the computer and format the number like so:
const { ComputerStorageUnitFormatter } = require("numeros");
const csuf = new ComputerStorageUnitFormatter();
console.log(csuf.formate(5));
console.log(csuf.formate(1024));
console.log(csuf.formate(8388608));
console.log(csuf.formate(10737418240));
console.log(csuf.formate(10737418240, ":"));
console.log(csuf.formate(10737418240, "_"));
console.log(csuf.formate(10737418240, "*"));
-
Metric System Format
as the name suggeset convert between the metric system units (milli, centi, deci, deca, hecto, kilo)
of the base unit gram for mass and meter for distance and liter for volume
const { MetricSystemUnit } = require("numeros");
const msu = new MetricSystemUnit();
console.log(msu.formate(15, "gram"));
console.log(msu.formate(22500.32, "gram"));
console.log(msu.formate(0.25, "gram"));