You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

strnum

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

strnum - npm Package Compare versions

Comparing version
2.2.0
to
2.2.1
+8
tests/temp.js
import toNumber from "../strnum.js";
console.log(toNumber("1.5e3", {leadingZeros: false}))
// describe("temp", () = {
// it("scientific notation", () => {
// });
// })
+5
-2
**2.1.1 / 2025-05-15**
- remove unnecessary check to remove lint error
**2.2.1 / 2026-03-19**
- fix false positive for eNotation when no leading zeros
**2.2.0 / 2026-02-28**
- support infinity
**2.1.0 / 2025-05-01**

@@ -6,0 +9,0 @@ - fix e-notation

{
"name": "strnum",
"version": "2.2.0",
"version": "2.2.1",
"description": "Parse String to Number based on configuration",

@@ -5,0 +5,0 @@ "type": "module",

@@ -100,7 +100,12 @@ const hexRegex = /^[-+]?0x[a-fA-F0-9]+$/;

return Number(trimmedStr);
} else if (options.leadingZeros && !eAdjacentToLeadingZeros) { //accept with leading zeros
//remove leading 0s
trimmedStr = (notation[1] || "") + notation[3];
} else if (leadingZeros.length > 0) {
// Has leading zeros — only accept if leadingZeros option allows it
if (options.leadingZeros && !eAdjacentToLeadingZeros) {
trimmedStr = (notation[1] || "") + notation[3];
return Number(trimmedStr);
} else return str;
} else {
// No leading zeros — always valid e-notation, parse it
return Number(trimmedStr);
} else return str;
}
} else {

@@ -107,0 +112,0 @@ return str;

@@ -129,2 +129,4 @@ import toNumber from "../strnum.js";

expect(toNumber("1.e+2")).toEqual(100);
expect(toNumber("1.5e3", { leadingZeros: false })).toEqual(1500);
});

@@ -131,0 +133,0 @@