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 +5 -2
- package/package.json +1 -1
- package/strnum.js +9 -4
- package/tests/strnum_test.js +2 -0
- package/tests/temp.js +8 -0
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
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 (
|
|
101
|
-
//
|
|
102
|
-
|
|
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
|
-
}
|
|
109
|
+
}
|
|
105
110
|
} else {
|
|
106
111
|
return str;
|
|
107
112
|
}
|
package/tests/strnum_test.js
CHANGED
|
@@ -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", () => {
|