Comparing version
**1.1.2 / 2025-02-27** | ||
- fix skiplike for 0 | ||
**1.1.1 / 2025-02-21** | ||
- All recent fixes of version 2 | ||
**2.0.4 / 2025-02-20** | ||
@@ -3,0 +9,0 @@ - remove console log |
{ | ||
"name": "strnum", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Parse String to Number based on configuration", | ||
@@ -5,0 +5,0 @@ "main": "strnum.js", |
@@ -19,7 +19,7 @@ const hexRegex = /^[-+]?0x[a-fA-F0-9]+$/; | ||
if(!str || typeof str !== "string" ) return str; | ||
else if(str==="0") return 0; | ||
let trimmedStr = str.trim(); | ||
if(options.skipLike !== undefined && options.skipLike.test(trimmedStr)) return str; | ||
else if(str==="0") return 0; | ||
else if (options.hex && hexRegex.test(trimmedStr)) { | ||
@@ -26,0 +26,0 @@ return parse_int(trimmedStr, 16); |
@@ -10,2 +10,3 @@ const toNumber = require("./strnum.js"); | ||
expect(toNumber("e89794659669cb7bb967db73a7ea6889c3891727")).toEqual("e89794659669cb7bb967db73a7ea6889c3891727"); | ||
}); | ||
@@ -143,2 +144,3 @@ it("should not parse number with spaces or comma", () => { | ||
it("should skip matching pattern", () => { | ||
expect(toNumber("0", { skipLike: /.*/ })).toEqual("0"); | ||
expect(toNumber("+12", { skipLike: /\+[0-9]{10}/} )).toEqual(12); | ||
@@ -145,0 +147,0 @@ expect(toNumber("12+12", { skipLike: /\+[0-9]{10}/} )).toEqual("12+12"); |
19247
0.95%270
0.37%