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 +4 -0
- package/package.json +1 -1
- package/strnum.js +3 -2
- package/tests/strnum_test.js +1 -0
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
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 (
|
|
24
|
-
else if (
|
|
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)) {
|
package/tests/strnum_test.js
CHANGED
|
@@ -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
|
});
|