js-abbreviation-number
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -1,1 +0,6 @@ | ||
export declare function abbreviateNumber(num: number, digit?: number, symbols?: Array<string>): string; | ||
interface Options { | ||
padding?: boolean; | ||
symbols?: string[]; | ||
} | ||
export declare function abbreviateNumber(num: number, digit?: number, options?: Options | Options["symbols"]): string; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function abbreviateNumber(num, digit, symbols) { | ||
var defaultOptions = { | ||
padding: true, | ||
symbols: ["", "K", "M", "G", "T", "P", "E"], | ||
}; | ||
function abbreviateNumber(num, digit, options) { | ||
if (digit === void 0) { digit = 1; } | ||
if (symbols === void 0) { symbols = ["", "K", "M", "G", "T", "P", "E"]; } | ||
// Previous options style | ||
if (Array.isArray(options)) { | ||
options = { symbols: options }; | ||
} | ||
var _a = Object.assign({}, defaultOptions, options), symbols = _a.symbols, padding = _a.padding; | ||
// handle negatives | ||
@@ -21,5 +29,9 @@ var sign = Math.sign(num) >= 0; | ||
var scaled = num / scale; | ||
var rounded = scaled.toFixed(digit); | ||
if (!padding) { | ||
rounded = String(Number(rounded)); | ||
} | ||
// format number and add suffix | ||
return (!sign ? "-" : "") + scaled.toFixed(digit) + suffix; | ||
return (!sign ? "-" : "") + rounded + suffix; | ||
} | ||
exports.abbreviateNumber = abbreviateNumber; |
{ | ||
"name": "js-abbreviation-number", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Abbreviate numbers in javascript", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -26,4 +26,3 @@ <div align="center"> | ||
``` | ||
```js | ||
import { abbreviateNumber } from "js-abbreviation-number"; | ||
@@ -30,0 +29,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
110133
694
0
71