Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

js-abbreviation-number

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-abbreviation-number - npm Package Compare versions

Comparing version 0.2.3 to 1.0.0

.prettierignore

2

.eslintrc.js

@@ -26,2 +26,2 @@ module.exports = {

}
};
};

@@ -0,28 +1,27 @@

export function abbreviateNumber(
num: number,
digit: number = 1,
symbols: Array<string> = ["", "K", "M", "G", "T", "P", "E"],
): string {
// handle negatives
const sign = Math.sign(num) >= 0;
num = Math.abs(num);
// what tier? (determines SI symbol)
const tier = (Math.log10(num) / 3) | 0;
export function abbreviateNumber(num: number, digit: number = 1, symbols: Array<string> = ["", "K", "M", "G", "T", "P", "E"]): string {
// if zero, we don't need a suffix
if (tier == 0) return num.toString();
// handle negatives
const sign = Math.sign(num) >= 0;
num = Math.abs(num);
// get suffix and determine scale
const suffix = symbols[tier];
if (!suffix) throw new RangeError();
// what tier? (determines SI symbol)
const tier = Math.log10(num) / 3 | 0;
const scale = Math.pow(10, tier * 3);
// if zero, we don't need a suffix
if(tier == 0) return num.toString();
// scale the number
const scaled = num / scale;
// get suffix and determine scale
const suffix = symbols[tier];
if(!suffix)
throw new RangeError();
const scale = Math.pow(10, tier * 3);
// scale the number
const scaled = num / scale;
// format number and add suffix
return (!sign?"-":"") + scaled.toFixed(digit) + suffix;
}
// format number and add suffix
return (!sign ? "-" : "") + scaled.toFixed(digit) + suffix;
}
{
"name": "js-abbreviation-number",
"version": "0.2.3",
"version": "1.0.0",
"description": "Abbreviate numbers in javascript",

@@ -10,3 +10,5 @@ "main": "dist/index.js",

"build": "tsc",
"lint": "./node_modules/.bin/eslint *.ts"
"lint": "./node_modules/.bin/eslint *.ts",
"prettier-write": "./node_modules/.bin/prettier --write \"*.ts\"",
"prettier-check": "./node_modules/.bin/prettier --check \"*.ts\""
},

@@ -37,2 +39,3 @@ "repository": {

"jest": "^25.1.0",
"prettier": "1.19.1",
"ts-jest": "^22.4.1",

@@ -39,0 +42,0 @@ "typescript": "^3.7.5"

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc