@fnmain/number
Advanced tools
Comparing version 1.5.2 to 1.6.0
@@ -15,4 +15,6 @@ type Options = { | ||
export declare function isNotNumber(value: any): boolean; | ||
export declare function formatWithCommas(value: any): string; | ||
export declare function formatWithCommas(value: any, { strNaN }?: { | ||
strNaN: string; | ||
}): string; | ||
export {}; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -114,4 +114,7 @@ "use strict"; | ||
exports.isNotNumber = isNotNumber; | ||
function formatWithCommas(value) { | ||
function formatWithCommas(value, { strNaN } = { strNaN: "NaN" }) { | ||
const val = parseNumber(value); | ||
if (isNaN(val)) { | ||
return strNaN; | ||
} | ||
return val.toString().replace(/(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ","); | ||
@@ -118,0 +121,0 @@ } |
@@ -33,2 +33,4 @@ "use strict"; | ||
console.log((0, index_1.formatWithCommas)("12345.6789")); // 12,345.6789 | ||
console.log((0, index_1.formatWithCommas)("abc")); // "NaN" | ||
console.log((0, index_1.formatWithCommas)("abc", { strNaN: "" })); // "" | ||
//# sourceMappingURL=test.js.map |
{ | ||
"name": "@fnmain/number", | ||
"version": "1.5.2", | ||
"version": "1.6.0", | ||
"description": "number utils", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -138,5 +138,8 @@ type Options = { | ||
export function formatWithCommas(value: any): string { | ||
export function formatWithCommas(value: any, { strNaN } = { strNaN: "NaN" }): string { | ||
const val = parseNumber(value); | ||
if (isNaN(val)) { | ||
return strNaN; | ||
} | ||
return val.toString().replace(/(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ","); | ||
} |
@@ -37,1 +37,3 @@ import { formatWithCommas, isNotNumber, isNumber, parseNumber, toAuto, toPercent } from "./index"; | ||
console.log(formatWithCommas("12345.6789")); // 12,345.6789 | ||
console.log(formatWithCommas("abc")); // "NaN" | ||
console.log(formatWithCommas("abc", { strNaN: "" })); // "" |
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
21478
334