strnum 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,9 @@
1
1
 
2
- **2.1.1 / 2025-05-15**
3
- - remove unnecessary check to remove lint error
2
+ **2.2.1 / 2026-03-19**
3
+ - fix false positive for eNotation when no leading zeros
4
+
5
+ **2.2.0 / 2026-02-28**
6
+ - support infinity
4
7
 
5
8
  **2.1.0 / 2025-05-01**
6
9
  - fix e-notation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strnum",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "Parse String to Number based on configuration",
5
5
  "type": "module",
6
6
  "main": "strnum.js",
package/strnum.js CHANGED
@@ -97,11 +97,16 @@ function resolveEnotation(str, trimmedStr, options) {
97
97
  else if (leadingZeros.length === 1
98
98
  && (notation[3].startsWith(`.${eChar}`) || notation[3][0] === eChar)) {
99
99
  return Number(trimmedStr);
100
- } else if (options.leadingZeros && !eAdjacentToLeadingZeros) { //accept with leading zeros
101
- //remove leading 0s
102
- trimmedStr = (notation[1] || "") + notation[3];
100
+ } else if (leadingZeros.length > 0) {
101
+ // Has leading zeros — only accept if leadingZeros option allows it
102
+ if (options.leadingZeros && !eAdjacentToLeadingZeros) {
103
+ trimmedStr = (notation[1] || "") + notation[3];
104
+ return Number(trimmedStr);
105
+ } else return str;
106
+ } else {
107
+ // No leading zeros — always valid e-notation, parse it
103
108
  return Number(trimmedStr);
104
- } else return str;
109
+ }
105
110
  } else {
106
111
  return str;
107
112
  }
@@ -126,6 +126,8 @@ describe("Should convert all the valid numeric strings to number", () => {
126
126
  expect(toNumber("1e-2")).toEqual(0.01);
127
127
  expect(toNumber("1e+2")).toEqual(100);
128
128
  expect(toNumber("1.e+2")).toEqual(100);
129
+
130
+ expect(toNumber("1.5e3", { leadingZeros: false })).toEqual(1500);
129
131
  });
130
132
 
131
133
  it("scientific notation with upper E", () => {
package/tests/temp.js ADDED
@@ -0,0 +1,8 @@
1
+ import toNumber from "../strnum.js";
2
+
3
+ console.log(toNumber("1.5e3", {leadingZeros: false}))
4
+ // describe("temp", () = {
5
+
6
+ // it("scientific notation", () => {
7
+ // });
8
+ // })