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

numeros

v1.0.4

Published

small javascrip utility to format numbers in a short and standerd method including (currencies,timing,computer storage unit sizes, Metrics Systems)

Downloads

6

Readme

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
// in case you are not using latest es6 import syntax
const { CurrencyFormatter } = require("numeros");

// in case you are latest es6 syntax
import { CurrencyFormatter } from "numeros";

// create an instance of the class
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

// value bigger then 1 thousend dollar by default
console.log(cf.shortFormat(2000)); // USD2.0K

// value can be negative however the result will be the same
console.log(cf.shortFormat(-5250360.6)); // USD5,3M

// value can be between Trillion and few cents of a currency
console.log(cf.shortFormat(2 * 10 ** 12)); // USD2,0T
console.log(cf.shortFormat(0.35)); // USD0.53

// you can add the currency manually like this
console.log(cf.shortFormat(3500, "EUR")); // EUR3,5K

// or use the currency sign like this
// supported signes are (USD,EUR, GBP, YUA, RUB, INR, YEN)
console.log(cf.shortFormat(48350, cf.currenciesList.EUR)); // £48,4K

// you can change the seperator like this
// you can use (.)(_)( )(:) anything u like
// default will be ','
console.log(cf.shortFormat(500000), cf.currenciesList.EUR, "."); // EUR500.0K

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")); // GBP 1,800,320.00

// in case was any cents
console.log(cf.standerdFormat(2500.32)); // USD 2,500.32

// you can change the seprator like so
console.log(cf.standerdFormat(88356.36), "EUR", "."); // EUR 88.356.36
console.log(cf.standerdFormat(88356.36), "EUR", "_"); // EUR 88_356.36
  • 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");

// create an instance
const tf = new TimingFormatter();

// the value base will be in millisecond like so
console.log(tf.formate(3000)); // 3 seconds

// minutes
console.log(tf.formate(35 * 1000 * 3600)); // 35minutes

// days
console.log(tf.formate(2 * 1000 * 3600 * 24)); // 2days
  • 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");

// create an instance
const csuf = new ComputerStorageUnitFormatter();

// the base unit is the bit
console.log(csuf.formate(5)); // 5b => 5bits

// you can convert to other units by increasing the number of bits
console.log(csuf.formate(1024)); // 1024 bit => 128.0Byte

// in MB
console.log(csuf.formate(8388608)); // 8388608 bit => 8.0MB

// in GB
console.log(csuf.formate(10737418240)); // 10737418240 bit => 10.0GB

// you can change the seprator
console.log(csuf.formate(10737418240, ":")); // 10:0GB
console.log(csuf.formate(10737418240, "_")); // 10_0GB
console.log(csuf.formate(10737418240, "*")); // 10*0GB
  • 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");

// create an instance
const msu = new MetricSystemUnit();

// for mass(gram) by default or other units
// it will be same thing only the basic unit
console.log(msu.formate(15, "gram")); // 1.5deg (decagram)
console.log(msu.formate(22500.32, "gram")); // 22kg (kilogram)
console.log(msu.formate(0.25, "gram")); // 2dg (decigram)