+8
-0
| **2.4.0 / 2026-06-09** | ||
| - support unicode numerals using 'anynum' | ||
| **2.3.0 / 2026-05-07** | ||
| - support octal and binary, test with @byspec/numbers | ||
| - test with @byspec/numbers | ||
| **2.2.3 / 2026-04-07** | ||
@@ -3,0 +11,0 @@ - remove unnecessary files from npm package |
+4
-1
| { | ||
| "name": "strnum", | ||
| "version": "2.3.0", | ||
| "version": "2.4.0", | ||
| "description": "Parse String to Number based on configuration", | ||
@@ -31,3 +31,6 @@ "type": "module", | ||
| "jasmine": "^5.6.0" | ||
| }, | ||
| "dependencies": { | ||
| "anynum": "^1.0.0" | ||
| } | ||
| } |
+9
-0
| # strnum | ||
| Parse string into Number based on configuration | ||
| [](https://npm-compare.com/strnum) | ||
| [](https://www.npmjs.com/package/strnum) | ||
| [](https://github.com/NaturalIntelligence/strnum) | ||
| ## Users | ||
@@ -89,2 +93,6 @@ | ||
| toNumber("+1212121212", { skipLike: /\+[0-9]{10}/} )); //"+1212121212" | ||
| toNumber("1e1000", { unicode: true, infinity: "original" }); //"1e1000" | ||
| toNumber("1000", { unicode: true }); //1000 | ||
| toNumber("1000", { unicode: false }); //"1000" | ||
| ``` | ||
@@ -99,2 +107,3 @@ | ||
| infinity: "original", // "null", "infinity" (Infinity type), "string" ("Infinity" (the string literal)) | ||
| unicode: false, //when number with unicode numerals should be parsed | ||
| ``` | ||
@@ -101,0 +110,0 @@ |
+9
-1
@@ -6,2 +6,4 @@ const hexRegex = /^[-+]?0x[a-fA-F0-9]+$/; | ||
| import anynum from "anynum"; | ||
| const consider = { | ||
@@ -16,2 +18,3 @@ hex: true, | ||
| infinity: "original", // "null", "infinity" (Infinity type), "string" ("Infinity" (the string literal)) | ||
| unicode: false, | ||
| }; | ||
@@ -28,3 +31,8 @@ | ||
| else if (trimmedStr === "0") return 0; | ||
| else if (options.hex && hexRegex.test(trimmedStr)) { | ||
| if (options.unicode) { | ||
| trimmedStr = anynum(trimmedStr); | ||
| if (trimmedStr === "0") return 0; // re-check after normalization | ||
| } | ||
| if (options.hex && hexRegex.test(trimmedStr)) { | ||
| return parse_int(trimmedStr, 16); | ||
@@ -31,0 +39,0 @@ } else if (options.binary && binRegex.test(trimmedStr)) { |
14171
7.32%154
4.05%114
8.57%1
Infinity%+ Added
+ Added