strnum 2.2.1 → 2.2.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,8 @@
1
1
 
2
+ **2.2.2 / 2026-03-23**
3
+ - fix for space string
4
+
5
+
2
6
  **2.2.1 / 2026-03-19**
3
7
  - fix false positive for eNotation when no leading zeros
4
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strnum",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "Parse String to Number based on configuration",
5
5
  "type": "module",
6
6
  "main": "strnum.js",
package/strnum.js CHANGED
@@ -20,8 +20,9 @@ export default function toNumber(str, options = {}) {
20
20
 
21
21
  let trimmedStr = str.trim();
22
22
 
23
- if (options.skipLike !== undefined && options.skipLike.test(trimmedStr)) return str;
24
- else if (str === "0") return 0;
23
+ if (trimmedStr.length === 0) return str;
24
+ else if (options.skipLike !== undefined && options.skipLike.test(trimmedStr)) return str;
25
+ else if (trimmedStr === "0") return 0;
25
26
  else if (options.hex && hexRegex.test(trimmedStr)) {
26
27
  return parse_int(trimmedStr, 16);
27
28
  // }else if (options.oct && octRegex.test(str)) {
@@ -5,6 +5,7 @@ describe("Should convert all the valid numeric strings to number", () => {
5
5
  expect(toNumber(undefined)).not.toBeDefined();
6
6
  expect(toNumber(null)).toEqual(null);
7
7
  expect(toNumber("")).toEqual("");
8
+ expect(toNumber(" ")).toEqual(" ");
8
9
  expect(toNumber("string")).toEqual("string");
9
10
  expect(toNumber("e89794659669cb7bb967db73a7ea6889c3891727")).toEqual("e89794659669cb7bb967db73a7ea6889c3891727");
10
11
  });