strnum 2.0.4 → 2.0.5

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,13 @@
1
1
 
2
+ **2.0.5 / 2025-02-27**
3
+ - changes done in 1.1.2
4
+
5
+ **1.1.2 / 2025-02-27**
6
+ - fix skiplike for 0
7
+
8
+ **1.1.1 / 2025-02-21**
9
+ - All recent fixes of version 2
10
+
2
11
  **2.0.4 / 2025-02-20**
3
12
  - remove console log
4
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strnum",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "Parse String to Number based on configuration",
5
5
  "type": "module",
6
6
  "main": "strnum.js",
package/strnum.js CHANGED
@@ -16,11 +16,11 @@ const consider = {
16
16
  export default function toNumber(str, options = {}){
17
17
  options = Object.assign({}, consider, options );
18
18
  if(!str || typeof str !== "string" ) return str;
19
- else if(str==="0") return 0;
20
-
19
+
21
20
  let trimmedStr = str.trim();
22
-
21
+
23
22
  if(options.skipLike !== undefined && options.skipLike.test(trimmedStr)) return str;
23
+ else if(str==="0") return 0;
24
24
  else if (options.hex && hexRegex.test(trimmedStr)) {
25
25
  return parse_int(trimmedStr, 16);
26
26
  // }else if (options.oct && octRegex.test(str)) {
@@ -106,4 +106,4 @@ function parse_int(numStr, base){
106
106
  else if(Number.parseInt) return Number.parseInt(numStr, base);
107
107
  else if(window && window.parseInt) return window.parseInt(numStr, base);
108
108
  else throw new Error("parseInt, Number.parseInt, window.parseInt are not supported")
109
- }
109
+ }
package/strnum.test.js CHANGED
@@ -7,6 +7,7 @@ describe("Should convert all the valid numeric strings to number", () => {
7
7
  expect(toNumber("")).toEqual("");
8
8
  expect(toNumber("string")).toEqual("string");
9
9
  expect(toNumber("e89794659669cb7bb967db73a7ea6889c3891727")).toEqual("e89794659669cb7bb967db73a7ea6889c3891727");
10
+
10
11
  });
11
12
  it("should not parse number with spaces or comma", () => {
12
13
  expect(toNumber("12,12")).toEqual("12,12");
@@ -139,6 +140,7 @@ describe("Should convert all the valid numeric strings to number", () => {
139
140
  });
140
141
 
141
142
  it("should skip matching pattern", () => {
143
+ expect(toNumber("0", { skipLike: /.*/ })).toEqual("0");
142
144
  expect(toNumber("+12", { skipLike: /\+[0-9]{10}/} )).toEqual(12);
143
145
  expect(toNumber("12+12", { skipLike: /\+[0-9]{10}/} )).toEqual("12+12");
144
146
  expect(toNumber("12+1212121212", { skipLike: /\+[0-9]{10}/} )).toEqual("12+1212121212");