builderman verion 0.1.0, initial commit/release.
This commit is contained in:
5
node_modules/strnum/.github/SECURITY.md
generated
vendored
Normal file
5
node_modules/strnum/.github/SECURITY.md
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
If you believe you have found a security vulnerability in this repository which can be potentially harful for the users in anyway, please do not report security vulnerabilities through public GitHub issues. Instead, please report it to us as described below.
|
||||
|
||||
## Security contact information
|
||||
|
||||
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
|
||||
25
node_modules/strnum/.vscode/launch.json
generated
vendored
Normal file
25
node_modules/strnum/.vscode/launch.json
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Jasmine Tests",
|
||||
"program": "${workspaceFolder}/node_modules/jasmine/bin/jasmine.js",
|
||||
"args": [
|
||||
"${workspaceFolder}/spec/attr_spec.js"
|
||||
],
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Jasmine Tests current test file",
|
||||
"program": "${workspaceFolder}/node_modules/jasmine/bin/jasmine.js",
|
||||
"args": [
|
||||
"${file}"
|
||||
],
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
}
|
||||
]
|
||||
|
||||
}
|
||||
33
node_modules/strnum/CHANGELOG.md
generated
vendored
Normal file
33
node_modules/strnum/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
**2.1.1 / 2025-05-15**
|
||||
- remove unnecessary check to remove lint error
|
||||
|
||||
**2.1.0 / 2025-05-01**
|
||||
- fix e-notation
|
||||
- to return string when invalid enotation is found. Eg `E24`
|
||||
- to return valid number when only leading zero before e char is present
|
||||
|
||||
**2.0.5 / 2025-02-27**
|
||||
- changes done in 1.1.2
|
||||
|
||||
**1.1.2 / 2025-02-27**
|
||||
- fix skiplike for 0
|
||||
|
||||
**1.1.1 / 2025-02-21**
|
||||
- All recent fixes of version 2
|
||||
|
||||
**2.0.4 / 2025-02-20**
|
||||
- remove console log
|
||||
|
||||
**2.0.3 / 2025-02-20**
|
||||
- fix for string which are falsly identified as e-notation
|
||||
|
||||
**2.0.1 / 2025-02-20**
|
||||
- fix: handle only zeros
|
||||
- fix: return original string when NaN
|
||||
|
||||
**2.0.0 / 2025-02-20**
|
||||
- Migrating to ESM modules. No functional change
|
||||
|
||||
**1.1.0 / 2025-02-20**
|
||||
- fix (#9): support missing floating point and e notations
|
||||
21
node_modules/strnum/LICENSE
generated
vendored
Normal file
21
node_modules/strnum/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Natural Intelligence
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
97
node_modules/strnum/README.md
generated
vendored
Normal file
97
node_modules/strnum/README.md
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
# strnum
|
||||
Parse string into Number based on configuration
|
||||
|
||||
## Users
|
||||
|
||||
<a href="https://github.com/aws-amplify" target="_blank"><img src="https://avatars.githubusercontent.com/u/41077760?s=100&v=4"></a>
|
||||
<a href="https://github.com/astrapay" target="_blank"><img src="https://avatars.githubusercontent.com/u/90901882?s=100&v=4"></a>
|
||||
<a href="https://github.com/process-analytics" target="_blank"><img src="https://avatars.githubusercontent.com/u/60110287?s=100&v=4"></a>
|
||||
<a href="https://github.com/NaturalIntelligence" target="_blank"><img src="https://avatars.githubusercontent.com/u/16322633?s=100&v=4"></a>
|
||||
Many React Native projects and plugins
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
npm install strnum
|
||||
```
|
||||
```js
|
||||
const toNumber = require("strnum");
|
||||
|
||||
toNumber(undefined) // undefined
|
||||
toNumber(null)) //null
|
||||
toNumber("")) // ""
|
||||
toNumber("string"); //"string")
|
||||
toNumber("12,12"); //"12,12")
|
||||
toNumber("12 12"); //"12 12")
|
||||
toNumber("12-12"); //"12-12")
|
||||
toNumber("12.12.12"); //"12.12.12")
|
||||
toNumber("0x2f"); //47)
|
||||
toNumber("-0x2f"); //-47)
|
||||
toNumber("0x2f", { hex : true}); //47)
|
||||
toNumber("-0x2f", { hex : true}); //-47)
|
||||
toNumber("0x2f", { hex : false}); //"0x2f")
|
||||
toNumber("-0x2f", { hex : false}); //"-0x2f")
|
||||
toNumber("06"); //6)
|
||||
toNumber("06", { leadingZeros : true}); //6)
|
||||
toNumber("06", { leadingZeros : false}); //"06")
|
||||
|
||||
toNumber("006"); //6)
|
||||
toNumber("006", { leadingZeros : true}); //6)
|
||||
toNumber("006", { leadingZeros : false}); //"006")
|
||||
toNumber("0.0"); //0)
|
||||
toNumber("00.00"); //0)
|
||||
toNumber("0.06"); //0.06)
|
||||
toNumber("00.6"); //0.6)
|
||||
toNumber(".006"); //0.006)
|
||||
toNumber("6.0"); //6)
|
||||
toNumber("06.0"); //6)
|
||||
|
||||
toNumber("0.0", { leadingZeros : false}); //0)
|
||||
toNumber("00.00", { leadingZeros : false}); //"00.00")
|
||||
toNumber("0.06", { leadingZeros : false}); //0.06)
|
||||
toNumber("00.6", { leadingZeros : false}); //"00.6")
|
||||
toNumber(".006", { leadingZeros : false}); //0.006)
|
||||
toNumber("6.0" , { leadingZeros : false}); //6)
|
||||
toNumber("06.0" , { leadingZeros : false}); //"06.0")
|
||||
toNumber("-06"); //-6)
|
||||
toNumber("-06", { leadingZeros : true}); //-6)
|
||||
toNumber("-06", { leadingZeros : false}); //"-06")
|
||||
|
||||
toNumber("-0.0"); //-0)
|
||||
toNumber("-00.00"); //-0)
|
||||
toNumber("-0.06"); //-0.06)
|
||||
toNumber("-00.6"); //-0.6)
|
||||
toNumber("-.006"); //-0.006)
|
||||
toNumber("-6.0"); //-6)
|
||||
toNumber("-06.0"); //-6)
|
||||
|
||||
toNumber("-0.0" , { leadingZeros : false}); //-0)
|
||||
toNumber("-00.00", { leadingZeros : false}); //"-00.00")
|
||||
toNumber("-0.06", { leadingZeros : false}); //-0.06)
|
||||
toNumber("-00.6", { leadingZeros : false}); //"-00.6")
|
||||
toNumber("-.006", {leadingZeros : false}); //-0.006)
|
||||
toNumber("-6.0" , { leadingZeros : false}); //-6)
|
||||
toNumber("-06.0" , { leadingZeros : false}); //"-06.0")
|
||||
toNumber("420926189200190257681175017717") ; //4.209261892001902e+29)
|
||||
toNumber("000000000000000000000000017717" , { leadingZeros : false}); //"000000000000000000000000017717")
|
||||
toNumber("000000000000000000000000017717" , { leadingZeros : true}); //17717)
|
||||
toNumber("01.0e2" , { leadingZeros : false}); //"01.0e2")
|
||||
toNumber("-01.0e2" , { leadingZeros : false}); //"-01.0e2")
|
||||
toNumber("01.0e2") ; //100)
|
||||
toNumber("-01.0e2") ; //-100)
|
||||
toNumber("1.0e2") ; //100)
|
||||
|
||||
toNumber("-1.0e2") ; //-100)
|
||||
toNumber("1.0e-2"); //0.01)
|
||||
|
||||
toNumber("+1212121212"); // 1212121212
|
||||
toNumber("+1212121212", { skipLike: /\+[0-9]{10}/} )); //"+1212121212"
|
||||
```
|
||||
|
||||
Supported Options
|
||||
```js
|
||||
hex: true, //when hexadecimal string should be parsed
|
||||
leadingZeros: true, //when number with leading zeros like 08 should be parsed. 0.0 is not impacted
|
||||
eNotation: true, //when number with eNotation or number parsed in eNotation should be considered
|
||||
skipLike: /regex/ //when string should not be parsed when it matches the specified regular expression
|
||||
```
|
||||
84
node_modules/strnum/algo.stflow
generated
vendored
Normal file
84
node_modules/strnum/algo.stflow
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
|
||||
FLOW: toNumber
|
||||
input: x, options
|
||||
IF not string
|
||||
END x
|
||||
ELSE_IF should skip
|
||||
END x
|
||||
ELSE_IF 0
|
||||
END 0
|
||||
ELSE_IF hex is supported AND x is hex
|
||||
END int of x of base 16
|
||||
ELSE_IF possible e notation
|
||||
FOLLOW: resolve enotation (x, trimmed x, options)
|
||||
ELSE
|
||||
IF match numeric pattern
|
||||
separate sign, leading zeros, pure number
|
||||
IF x doesn't starts with "[+-]0."
|
||||
END number(x)
|
||||
IF leading zeros are not allowed
|
||||
IF leading zeros > 1
|
||||
#00.1
|
||||
END x
|
||||
ELSE_IF leading zeros == 1 AND decimal is not adjacent to leading zeros
|
||||
#06.5
|
||||
#but not 0.65, .65, 6.0
|
||||
END x
|
||||
ELSE_IF str has only zeros
|
||||
END 0
|
||||
ELSE
|
||||
parse x to number
|
||||
IF parsed x == 0 or -0
|
||||
END parsed x
|
||||
ELSE_IF parsed x is eNotation
|
||||
IF conversion to enotation is allowed
|
||||
END parsed x
|
||||
ELSE
|
||||
END x
|
||||
ELSE_IF floating number
|
||||
IF parsed x is 0
|
||||
END parsed x
|
||||
ELSE_IF parsed x == number without leading 0s
|
||||
#0.456. 0.79000
|
||||
END parsed x
|
||||
ELSE_IF parsed x is negative AND == parsed x == number without leading 0s
|
||||
END parsed x
|
||||
ELSE
|
||||
END x
|
||||
ELSE_IF leading 0s are present
|
||||
IF parsed x == x without leading 0s
|
||||
END parsed x
|
||||
ELSE
|
||||
END x
|
||||
ELSE
|
||||
IF parsed x == x (consider sign)
|
||||
END parsed x
|
||||
ELSE
|
||||
END x
|
||||
|
||||
ELSE
|
||||
END x
|
||||
|
||||
|
||||
|
||||
FLOW: resolve enotation
|
||||
input: x, trimmed x, options
|
||||
IF eNotation has not to be evaluated
|
||||
END x
|
||||
IF match eNotation pattern
|
||||
extract sign, eChar, leading zeros
|
||||
find if eChar adjacent to leading zeros
|
||||
|
||||
IF leading zeros > 1 AND eChar adjacent to leading zeros
|
||||
# 00e, -00e
|
||||
END x
|
||||
ELSE_IF exp is `0e`, `0.e`, `-0.e`, `-0e`
|
||||
END number(x);
|
||||
ELSE_IF leading zeros are allowed but eChar is not adjacent to leading zeros
|
||||
# -003e2
|
||||
remove leading zeros
|
||||
END number(x)
|
||||
ELSE
|
||||
END x
|
||||
ELSE
|
||||
END x
|
||||
31
node_modules/strnum/package.json
generated
vendored
Normal file
31
node_modules/strnum/package.json
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "strnum",
|
||||
"version": "2.1.1",
|
||||
"description": "Parse String to Number based on configuration",
|
||||
"type": "module",
|
||||
"main": "strnum.js",
|
||||
"scripts": {
|
||||
"test": "jasmine strnum.test.js"
|
||||
},
|
||||
"keywords": [
|
||||
"string",
|
||||
"number",
|
||||
"parse",
|
||||
"convert"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/NaturalIntelligence/strnum"
|
||||
},
|
||||
"author": "Amit Gupta (https://amitkumargupta.work/)",
|
||||
"license": "MIT",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/NaturalIntelligence"
|
||||
}
|
||||
],
|
||||
"devDependencies": {
|
||||
"jasmine": "^5.6.0"
|
||||
}
|
||||
}
|
||||
129
node_modules/strnum/strnum.js
generated
vendored
Normal file
129
node_modules/strnum/strnum.js
generated
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
const hexRegex = /^[-+]?0x[a-fA-F0-9]+$/;
|
||||
const numRegex = /^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/;
|
||||
// const octRegex = /^0x[a-z0-9]+/;
|
||||
// const binRegex = /0x[a-z0-9]+/;
|
||||
|
||||
|
||||
const consider = {
|
||||
hex : true,
|
||||
// oct: false,
|
||||
leadingZeros: true,
|
||||
decimalPoint: "\.",
|
||||
eNotation: true,
|
||||
//skipLike: /regex/
|
||||
};
|
||||
|
||||
export default function toNumber(str, options = {}){
|
||||
options = Object.assign({}, consider, options );
|
||||
if(!str || typeof str !== "string" ) return str;
|
||||
|
||||
let trimmedStr = str.trim();
|
||||
|
||||
if(options.skipLike !== undefined && options.skipLike.test(trimmedStr)) return str;
|
||||
else if(str==="0") return 0;
|
||||
else if (options.hex && hexRegex.test(trimmedStr)) {
|
||||
return parse_int(trimmedStr, 16);
|
||||
// }else if (options.oct && octRegex.test(str)) {
|
||||
// return Number.parseInt(val, 8);
|
||||
}else if (trimmedStr.search(/.+[eE].+/)!== -1) { //eNotation
|
||||
return resolveEnotation(str,trimmedStr,options);
|
||||
// }else if (options.parseBin && binRegex.test(str)) {
|
||||
// return Number.parseInt(val, 2);
|
||||
}else{
|
||||
//separate negative sign, leading zeros, and rest number
|
||||
const match = numRegex.exec(trimmedStr);
|
||||
// +00.123 => [ , '+', '00', '.123', ..
|
||||
if(match){
|
||||
const sign = match[1] || "";
|
||||
const leadingZeros = match[2];
|
||||
let numTrimmedByZeros = trimZeros(match[3]); //complete num without leading zeros
|
||||
const decimalAdjacentToLeadingZeros = sign ? // 0., -00., 000.
|
||||
str[leadingZeros.length+1] === "."
|
||||
: str[leadingZeros.length] === ".";
|
||||
|
||||
//trim ending zeros for floating number
|
||||
if(!options.leadingZeros //leading zeros are not allowed
|
||||
&& (leadingZeros.length > 1
|
||||
|| (leadingZeros.length === 1 && !decimalAdjacentToLeadingZeros))){
|
||||
// 00, 00.3, +03.24, 03, 03.24
|
||||
return str;
|
||||
}
|
||||
else{//no leading zeros or leading zeros are allowed
|
||||
const num = Number(trimmedStr);
|
||||
const parsedStr = String(num);
|
||||
|
||||
if( num === 0) return num;
|
||||
if(parsedStr.search(/[eE]/) !== -1){ //given number is long and parsed to eNotation
|
||||
if(options.eNotation) return num;
|
||||
else return str;
|
||||
}else if(trimmedStr.indexOf(".") !== -1){ //floating number
|
||||
if(parsedStr === "0") return num; //0.0
|
||||
else if(parsedStr === numTrimmedByZeros) return num; //0.456. 0.79000
|
||||
else if( parsedStr === `${sign}${numTrimmedByZeros}`) return num;
|
||||
else return str;
|
||||
}
|
||||
|
||||
let n = leadingZeros? numTrimmedByZeros : trimmedStr;
|
||||
if(leadingZeros){
|
||||
// -009 => -9
|
||||
return (n === parsedStr) || (sign+n === parsedStr) ? num : str
|
||||
}else {
|
||||
// +9
|
||||
return (n === parsedStr) || (n === sign+parsedStr) ? num : str
|
||||
}
|
||||
}
|
||||
}else{ //non-numeric string
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const eNotationRegx = /^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;
|
||||
function resolveEnotation(str,trimmedStr,options){
|
||||
if(!options.eNotation) return str;
|
||||
const notation = trimmedStr.match(eNotationRegx);
|
||||
if(notation){
|
||||
let sign = notation[1] || "";
|
||||
const eChar = notation[3].indexOf("e") === -1 ? "E" : "e";
|
||||
const leadingZeros = notation[2];
|
||||
const eAdjacentToLeadingZeros = sign ? // 0E.
|
||||
str[leadingZeros.length+1] === eChar
|
||||
: str[leadingZeros.length] === eChar;
|
||||
|
||||
if(leadingZeros.length > 1 && eAdjacentToLeadingZeros) return str;
|
||||
else if(leadingZeros.length === 1
|
||||
&& (notation[3].startsWith(`.${eChar}`) || notation[3][0] === eChar)){
|
||||
return Number(trimmedStr);
|
||||
}else if(options.leadingZeros && !eAdjacentToLeadingZeros){ //accept with leading zeros
|
||||
//remove leading 0s
|
||||
trimmedStr = (notation[1] || "") + notation[3];
|
||||
return Number(trimmedStr);
|
||||
}else return str;
|
||||
}else{
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} numStr without leading zeros
|
||||
* @returns
|
||||
*/
|
||||
function trimZeros(numStr){
|
||||
if(numStr && numStr.indexOf(".") !== -1){//float
|
||||
numStr = numStr.replace(/0+$/, ""); //remove ending zeros
|
||||
if(numStr === ".") numStr = "0";
|
||||
else if(numStr[0] === ".") numStr = "0"+numStr;
|
||||
else if(numStr[numStr.length-1] === ".") numStr = numStr.substring(0,numStr.length-1);
|
||||
return numStr;
|
||||
}
|
||||
return numStr;
|
||||
}
|
||||
|
||||
function parse_int(numStr, base){
|
||||
//polyfill
|
||||
if(parseInt) return parseInt(numStr, base);
|
||||
else if(Number.parseInt) return Number.parseInt(numStr, base);
|
||||
else if(window && window.parseInt) return window.parseInt(numStr, base);
|
||||
else throw new Error("parseInt, Number.parseInt, window.parseInt are not supported")
|
||||
}
|
||||
173
node_modules/strnum/strnum.test.js
generated
vendored
Normal file
173
node_modules/strnum/strnum.test.js
generated
vendored
Normal file
@@ -0,0 +1,173 @@
|
||||
import toNumber from "./strnum.js";
|
||||
|
||||
describe("Should convert all the valid numeric strings to number", () => {
|
||||
it("should return undefined, null, empty string, or non-numeric as it is", () => {
|
||||
expect(toNumber(undefined)).not.toBeDefined();
|
||||
expect(toNumber(null)).toEqual(null);
|
||||
expect(toNumber("")).toEqual("");
|
||||
expect(toNumber("string")).toEqual("string");
|
||||
expect(toNumber("e89794659669cb7bb967db73a7ea6889c3891727")).toEqual("e89794659669cb7bb967db73a7ea6889c3891727");
|
||||
|
||||
});
|
||||
it("should not parse number with spaces or comma", () => {
|
||||
expect(toNumber("12,12")).toEqual("12,12");
|
||||
expect(toNumber("12 12")).toEqual("12 12");
|
||||
expect(toNumber("12-12")).toEqual("12-12");
|
||||
expect(toNumber("12.12.12")).toEqual("12.12.12");
|
||||
})
|
||||
it("should consider + sign", () => {
|
||||
expect(toNumber("+12")).toEqual(12);
|
||||
expect(toNumber("+ 12")).toEqual("+ 12");
|
||||
expect(toNumber("12+12")).toEqual("12+12");
|
||||
expect(toNumber("1212+")).toEqual("1212+");
|
||||
})
|
||||
it("should parse hexadecimal values", () => {
|
||||
expect(toNumber("0x2f")).toEqual(47);
|
||||
expect(toNumber("-0x2f")).toEqual(-47);
|
||||
expect(toNumber("0x2f", { hex : true})).toEqual(47);
|
||||
expect(toNumber("-0x2f", { hex : true})).toEqual(-47);
|
||||
expect(toNumber("0x2f", { hex : false})).toEqual("0x2f");
|
||||
expect(toNumber("-0x2f", { hex : false})).toEqual("-0x2f");
|
||||
})
|
||||
it("should not parse strings with 0x embedded", () => {
|
||||
expect(toNumber("0xzz")).toEqual("0xzz");
|
||||
expect(toNumber("iweraf0x123qwerqwer")).toEqual("iweraf0x123qwerqwer");
|
||||
expect(toNumber("1230x55")).toEqual("1230x55");
|
||||
expect(toNumber("JVBERi0xLjMNCiXi48")).toEqual("JVBERi0xLjMNCiXi48");
|
||||
})
|
||||
it("leading zeros", () => {
|
||||
expect(toNumber("0")).toEqual(0);
|
||||
expect(toNumber("00")).toEqual(0);
|
||||
expect(toNumber("00.0")).toEqual(0);
|
||||
|
||||
expect(toNumber("0",{ leadingZeros : false})).toEqual(0);
|
||||
expect(toNumber("00",{ leadingZeros : false})).toEqual("00");
|
||||
expect(toNumber("00.0",{ leadingZeros : false})).toEqual("00.0");
|
||||
|
||||
expect(toNumber("06")).toEqual(6);
|
||||
expect(toNumber("06", { leadingZeros : true})).toEqual(6);
|
||||
expect(toNumber("06", { leadingZeros : false})).toEqual("06");
|
||||
|
||||
expect(toNumber("006")).toEqual(6);
|
||||
expect(toNumber("006", { leadingZeros : true})).toEqual(6);
|
||||
expect(toNumber("006", { leadingZeros : false})).toEqual("006");
|
||||
|
||||
expect(toNumber("000000000000000000000000017717" , { leadingZeros : false})).toEqual("000000000000000000000000017717");
|
||||
expect(toNumber("000000000000000000000000017717" , { leadingZeros : true})).toEqual(17717);
|
||||
expect(toNumber("020211201030005811824") ).toEqual("020211201030005811824");
|
||||
expect(toNumber("0420926189200190257681175017717") ).toEqual(4.209261892001902e+29);
|
||||
})
|
||||
it("invalid floating number", () => {
|
||||
expect(toNumber("20.21.030") ).toEqual("20.21.030");
|
||||
expect(toNumber("0.21.030") ).toEqual("0.21.030");
|
||||
expect(toNumber("0.21.") ).toEqual("0.21.");
|
||||
});
|
||||
it("floating point and leading zeros", () => {
|
||||
expect(toNumber("0.")).toEqual(0);
|
||||
expect(toNumber("+0.")).toEqual(0);
|
||||
expect(toNumber("-0.")).toEqual(-0);
|
||||
expect(toNumber("1.") ).toEqual(1);
|
||||
expect(toNumber("00.00")).toEqual(0);
|
||||
expect(toNumber("0.06")).toEqual(0.06);
|
||||
expect(toNumber("00.6")).toEqual(0.6);
|
||||
expect(toNumber(".006")).toEqual(0.006);
|
||||
expect(toNumber("6.0")).toEqual(6);
|
||||
expect(toNumber("06.0")).toEqual(6);
|
||||
|
||||
expect(toNumber("0.0", { leadingZeros : false})).toEqual(0);
|
||||
expect(toNumber("00.00", { leadingZeros : false})).toEqual("00.00");
|
||||
expect(toNumber("0.06", { leadingZeros : false})).toEqual(0.06);
|
||||
expect(toNumber("00.6", { leadingZeros : false})).toEqual("00.6");
|
||||
expect(toNumber(".006", { leadingZeros : false})).toEqual(0.006);
|
||||
expect(toNumber("6.0" , { leadingZeros : false})).toEqual(6);
|
||||
expect(toNumber("06.0" , { leadingZeros : false})).toEqual("06.0");
|
||||
})
|
||||
it("negative number leading zeros", () => {
|
||||
expect(toNumber("+06")).toEqual(6);
|
||||
expect(toNumber("-06")).toEqual(-6);
|
||||
expect(toNumber("-06", { leadingZeros : true})).toEqual(-6);
|
||||
expect(toNumber("-06", { leadingZeros : false})).toEqual("-06");
|
||||
|
||||
expect(toNumber("-0.0")).toEqual(-0);
|
||||
expect(toNumber("-00.00")).toEqual(-0);
|
||||
expect(toNumber("-0.06")).toEqual(-0.06);
|
||||
expect(toNumber("-00.6")).toEqual(-0.6);
|
||||
expect(toNumber("-.006")).toEqual(-0.006);
|
||||
expect(toNumber("-6.0")).toEqual(-6);
|
||||
expect(toNumber("-06.0")).toEqual(-6);
|
||||
expect(toNumber("+06.0")).toEqual(6);
|
||||
|
||||
expect(toNumber("-0.0" , { leadingZeros : false})).toEqual(-0);
|
||||
expect(toNumber("-00.00", { leadingZeros : false})).toEqual("-00.00");
|
||||
expect(toNumber("-0.06", { leadingZeros : false})).toEqual(-0.06);
|
||||
expect(toNumber("-00.6", { leadingZeros : false})).toEqual("-00.6");
|
||||
expect(toNumber("-.006", {leadingZeros : false})).toEqual(-0.006);
|
||||
expect(toNumber("-6.0" , { leadingZeros : false})).toEqual(-6);
|
||||
expect(toNumber("-06.0" , { leadingZeros : false})).toEqual("-06.0");
|
||||
})
|
||||
it("long number", () => {
|
||||
expect(toNumber("020211201030005811824") ).toEqual("020211201030005811824");
|
||||
expect(toNumber("20211201030005811824") ).toEqual("20211201030005811824");
|
||||
expect(toNumber("20.211201030005811824") ).toEqual("20.211201030005811824");
|
||||
expect(toNumber("0.211201030005811824") ).toEqual("0.211201030005811824");
|
||||
});
|
||||
it("scientific notation", () => {
|
||||
expect(toNumber("01.0e2" , { leadingZeros : false})).toEqual("01.0e2");
|
||||
expect(toNumber("-01.0e2" , { leadingZeros : false})).toEqual("-01.0e2");
|
||||
expect(toNumber("01.0e2") ).toEqual(100);
|
||||
expect(toNumber("-01.0e2") ).toEqual(-100);
|
||||
expect(toNumber("1.0e2") ).toEqual(100);
|
||||
|
||||
expect(toNumber("-1.0e2") ).toEqual(-100);
|
||||
expect(toNumber("1.0e-2")).toEqual(0.01);
|
||||
|
||||
expect(toNumber("420926189200190257681175017717") ).toEqual(4.209261892001902e+29);
|
||||
expect(toNumber("420926189200190257681175017717" , { eNotation: false} )).toEqual("420926189200190257681175017717");
|
||||
|
||||
expect(toNumber("1e-2")).toEqual(0.01);
|
||||
expect(toNumber("1e+2")).toEqual(100);
|
||||
expect(toNumber("1.e+2")).toEqual(100);
|
||||
});
|
||||
|
||||
it("scientific notation with upper E", () => {
|
||||
expect(toNumber("01.0E2" , { leadingZeros : false})).toEqual("01.0E2");
|
||||
expect(toNumber("-01.0E2" , { leadingZeros : false})).toEqual("-01.0E2");
|
||||
expect(toNumber("01.0E2") ).toEqual(100);
|
||||
expect(toNumber("-01.0E2") ).toEqual(-100);
|
||||
expect(toNumber("1.0E2") ).toEqual(100);
|
||||
|
||||
expect(toNumber("-1.0E2") ).toEqual(-100);
|
||||
expect(toNumber("1.0E-2")).toEqual(0.01);
|
||||
|
||||
expect(toNumber("E-2")).toEqual("E-2");
|
||||
expect(toNumber("E2")).toEqual("E2");
|
||||
expect(toNumber("0E2")).toEqual(0);
|
||||
expect(toNumber("-0E2")).toEqual(-0);
|
||||
expect(toNumber("00E2")).toEqual("00E2");
|
||||
expect(toNumber("00E2", { leadingZeros : false})).toEqual("00E2");
|
||||
});
|
||||
|
||||
it("should skip matching pattern", () => {
|
||||
expect(toNumber("0", { skipLike: /.*/ })).toEqual("0");
|
||||
expect(toNumber("+12", { skipLike: /\+[0-9]{10}/} )).toEqual(12);
|
||||
expect(toNumber("12+12", { skipLike: /\+[0-9]{10}/} )).toEqual("12+12");
|
||||
expect(toNumber("12+1212121212", { skipLike: /\+[0-9]{10}/} )).toEqual("12+1212121212");
|
||||
expect(toNumber("+1212121212") ).toEqual(1212121212);
|
||||
expect(toNumber("+1212121212", { skipLike: /\+[0-9]{10}/} )).toEqual("+1212121212");
|
||||
})
|
||||
it("should not change string if not number", () => {
|
||||
expect(toNumber("+12 12")).toEqual("+12 12");
|
||||
expect(toNumber(" +12 12 ")).toEqual(" +12 12 ");
|
||||
})
|
||||
it("should ignore sorrounded spaces ", () => {
|
||||
expect(toNumber(" +1212 ")).toEqual(1212);
|
||||
})
|
||||
|
||||
it("negative numbers", () => {
|
||||
expect(toNumber("+1212")).toEqual(1212);
|
||||
expect(toNumber("+12.12")).toEqual(12.12);
|
||||
expect(toNumber("-12.12")).toEqual(-12.12);
|
||||
expect(toNumber("-012.12")).toEqual(-12.12);
|
||||
expect(toNumber("-012.12")).toEqual(-12.12);
|
||||
})
|
||||
});
|
||||
9
node_modules/strnum/test.js
generated
vendored
Normal file
9
node_modules/strnum/test.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import toNumber from "./strnum.js";
|
||||
|
||||
describe("Should convert all the valid numeric strings to number", () => {
|
||||
it("should return undefined, null, empty string, or non-numeric as it is", () => {
|
||||
// expect(toNumber("+ 90")).toEqual("+ 90");
|
||||
// expect(toNumber("- 90")).toEqual("- 90");
|
||||
expect(toNumber("-10E2")).toEqual(100);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user