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

comma-separator

v1.0.9

Published

A package for separating numbers in hundreds, thousands, millions, billions and trillions and converts long numbers to readable strings

Downloads

48

Readme

comma-separator

Separate numbers in hundreds, thousands, millions, billions and trillions and converts long numbers to readable strings.

Install

$ npm install comma-separator

Import

Nodejs Applications

const { addComma } = require("comma-separator");

Reactjs Applications

import { addComma } from "comma-separator";

Usage

Add comma to numbers

const { addComma } = require("comma-separator");

addComma(5000000); // "5,000,000"
addComma(-10000); // "-10,000"

addComma(1000); // "1,000"
addComma(-1000); // "-1,000"

addComma(1000.12); // "1,000.12"
addComma(-1000.12); // "-1,000.12"

addComma("-200000000M"); // "-200,000,000M"

Remove comma from numbers

const { removeComma } = require("comma-separator");

removeComma("5,000,000"); // 5000000
removeComma("-10,000"); // -10000

removeComma("1,000"); // 1000
removeComma("-1,000"); // -1000

removeComma("-100,000,000 Millions"); // -100000000

strict add comma to numbers

const { strictAddComma } = require("comma-separator");

strictAddComma(5000000); // "5,000,000"
stritAddComma(-10000); // "10,000"

strictAddComma(-10000000); // "10,000,000"

strictAddComma("10000000M"); // "10,000,000"

strictAddComma("1000 thousand naira"); // "1,000"

strictAddComma("-200000000M"); // "200,000,000"

strict remove comma from numbers

const { strictRemoveComma } = require("comma-separator");

strictRemoveComma("5,000,000"); // 5000000
strictRemoveComma("-10,000"); // 10000

strictRemoveComma("1,000"); // 1000
strictRemoveComma("-1,000"); // 1000

strictRemoveComma("1,000Thousand"); // 1000
strictRemoveComma("-100,000,000 Millions"); // 100000000

strictRemoveComma("-20.00,000,000Millions"); // 2000000000

Convert Long numbers to readable strings

const { convert } = require("comma-separator");

convert(5000); // 5K
convert(10000); //10K
convert(100000); //100K

convert(1000000); // 1M
convert(20000000); // 20M

convert(5000000000); // 5B
convert(100000000000); //100B

convert(5000000000000); // 5T

Examples

Remove Comma Example

const { removeComma } = require("comma-separator");

const ex1 = "10,000";
const ex2 = "-3,000";
const ex3 = 1000;
const ex4 = "1,000 naira";

const calculateSum = (...rest) => {
  let arr = [];
  rest.forEach((item) => {
    arr.push(removeComma(item));
  });

  return arr.reduce((acc, item) => {
    return acc + item;
  }, 0);
};

const response = calculateSum(ex1, ex2, ex3, ex4);
console.log(response);

`Result = 9000`;
const { removeComma } = require("comma-separator");

const ex1 = "10,000";
const ex2 = "3,000";
const ex3 = 1000;
const ex4 = "1,000 naira";

const calculateSum = (...rest) => {
  let arr = [];
  rest.forEach((item) => {
    arr.push(removeComma(item));
  });

  return arr.reduce((acc, item) => {
    return acc + item;
  }, 0);
};

const response = calculateSum(ex1, ex2, ex3, ex4);
console.log(response);

`Result = 15000`;

------------------------------------------------------------------

Remove Strict Comma Example

const { strictRemoveComma } = require("comma-separator");

const ex1 = "10,000";
const ex2 = "-3,000";
const ex3 = 1000;
const ex4 = "1,000 naira";

const calculateSum = (...rest) => {
  let arr = [];
  rest.forEach((item) => {
    arr.push(strictRemoveComma(item));
  });

  return arr.reduce((acc, item) => {
    return acc + item;
  }, 0);
};

const response = calculateSum(ex1, ex2, ex3, ex4);
console.log(response);

`Result = 15000`;