strnum 2.0.2 → 2.0.4
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 +6 -0
- package/package.json +1 -1
- package/strnum.js +2 -1
- package/strnum.test.js +1 -0
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
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
|
@@ -6,6 +6,7 @@ describe("Should convert all the valid numeric strings to number", () => {
|
|
|
6
6
|
expect(toNumber(null)).toEqual(null);
|
|
7
7
|
expect(toNumber("")).toEqual("");
|
|
8
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");
|