strnum 2.0.2 → 2.0.3

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,4 +1,7 @@
1
1
 
2
+ **2.0.2 / 2025-02-20**
3
+ - fix for string which are falsly identified as e-notation
4
+
2
5
  **2.0.1 / 2025-02-20**
3
6
  - fix: handle only zeros
4
7
  - fix: return original string when NaN
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strnum",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "Parse String to Number based on configuration",
5
5
  "type": "module",
6
6
  "main": "strnum.js",
package/strnum.js CHANGED
@@ -26,9 +26,10 @@ export default function toNumber(str, options = {}){
26
26
  // }else if (options.oct && octRegex.test(str)) {
27
27
  // return Number.parseInt(val, 8);
28
28
  }else if (trimmedStr.search(/[eE]/)!== -1) { //eNotation
29
- const notation = trimmedStr.match(/^([-\+])?(0*)([0-9]*(\.[0-9]*)?[eE][-\+]?[0-9]+)/);
29
+ const notation = trimmedStr.match(/^([-\+])?(0*)([0-9]*(\.[0-9]*)?[eE][-\+]?[0-9]+)$/);
30
30
  // +00.123 => [ , '+', '00', '.123', ..
31
31
  if(notation){
32
+ console.log(notation)
32
33
  if(options.leadingZeros){ //accept with leading zeros
33
34
  trimmedStr = (notation[1] || "") + notation[3];
34
35
  }else{
package/strnum.test.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import toNumber from "./strnum.js";
2
2
 
3
3
  describe("Should convert all the valid numeric strings to number", () => {
4
- it("should return undefined, null, empty string, or non-numeric as it is", () => {
5
- expect(toNumber(undefined)).not.toBeDefined();
6
- expect(toNumber(null)).toEqual(null);
7
- expect(toNumber("")).toEqual("");
8
- expect(toNumber("string")).toEqual("string");
4
+ fit("should return undefined, null, empty string, or non-numeric as it is", () => {
5
+ // expect(toNumber(undefined)).not.toBeDefined();
6
+ // expect(toNumber(null)).toEqual(null);
7
+ // expect(toNumber("")).toEqual("");
8
+ // expect(toNumber("string")).toEqual("string");
9
+ expect(toNumber("e89794659669cb7bb967db73a7ea6889c3891727")).toEqual("e89794659669cb7bb967db73a7ea6889c3891727");
9
10
  });
10
11
  it("should not parse number with spaces or comma", () => {
11
12
  expect(toNumber("12,12")).toEqual("12,12");