strnum 1.1.1 → 1.1.2

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,10 @@
1
1
 
2
+ **1.1.2 / 2025-02-27**
3
+ - fix skiplike for 0
4
+
5
+ **1.1.1 / 2025-02-21**
6
+ - All recent fixes of version 2
7
+
2
8
  **2.0.4 / 2025-02-20**
3
9
  - remove console log
4
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strnum",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Parse String to Number based on configuration",
5
5
  "main": "strnum.js",
6
6
  "scripts": {
package/strnum.js CHANGED
@@ -16,11 +16,11 @@ const consider = {
16
16
  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)) {
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");