update, text, response

This commit is contained in:
2025-11-02 11:09:14 +01:00
parent 14776c86b0
commit eed8a4ddcf
2794 changed files with 156786 additions and 129204 deletions

22
node_modules/strnum/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,22 @@
**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

17
node_modules/strnum/README.md generated vendored
View File

@@ -1,6 +1,16 @@
# 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
```
@@ -80,7 +90,8 @@ toNumber("+1212121212", { skipLike: /\+[0-9]{10}/} )); //"+1212121212"
Supported Options
```js
hex : true, //when hexadecimal string should be parsed
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
```
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
```

10
node_modules/strnum/package.json generated vendored
View File

@@ -1,6 +1,6 @@
{
"name": "strnum",
"version": "1.0.5",
"version": "1.1.2",
"description": "Parse String to Number based on configuration",
"main": "strnum.js",
"scripts": {
@@ -18,7 +18,13 @@
},
"author": "Amit Gupta (https://amitkumargupta.work/)",
"license": "MIT",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/NaturalIntelligence"
}
],
"devDependencies": {
"jasmine": "^3.10.0"
"jasmine": "^5.6.0"
}
}

99
node_modules/strnum/strnum.js generated vendored
View File

@@ -1,78 +1,71 @@
const hexRegex = /^[-+]?0x[a-fA-F0-9]+$/;
const numRegex = /^([\-\+])?(0*)(\.[0-9]+([eE]\-?[0-9]+)?|[0-9]+(\.[0-9]+([eE]\-?[0-9]+)?)?)$/;
// const octRegex = /0x[a-z0-9]+/;
const numRegex = /^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/;
// const octRegex = /^0x[a-z0-9]+/;
// const binRegex = /0x[a-z0-9]+/;
//polyfill
if (!Number.parseInt && window.parseInt) {
Number.parseInt = window.parseInt;
}
if (!Number.parseFloat && window.parseFloat) {
Number.parseFloat = window.parseFloat;
}
const consider = {
hex : true,
// oct: false,
leadingZeros: true,
decimalPoint: "\.",
eNotation: true
eNotation: true,
//skipLike: /regex/
};
function toNumber(str, options = {}){
// const options = Object.assign({}, consider);
// if(opt.leadingZeros === false){
// options.leadingZeros = false;
// }else if(opt.hex === false){
// options.hex = false;
// }
options = Object.assign({}, consider, options );
if(!str || typeof str !== "string" ) return str;
let trimmedStr = str.trim();
// if(trimmedStr === "0.0") return 0;
// else if(trimmedStr === "+0.0") return 0;
// else if(trimmedStr === "-0.0") return -0;
if(options.skipLike !== undefined && options.skipLike.test(trimmedStr)) return str;
else if(str==="0") return 0;
else if (options.hex && hexRegex.test(trimmedStr)) {
return Number.parseInt(trimmedStr, 16);
// } else if (options.parseOct && octRegex.test(str)) {
return parse_int(trimmedStr, 16);
// }else if (options.oct && octRegex.test(str)) {
// return Number.parseInt(val, 8);
}else if (trimmedStr.search(/[eE]/)!== -1) { //eNotation
const notation = trimmedStr.match(/^([-\+])?(0*)([0-9]*(\.[0-9]*)?[eE][-\+]?[0-9]+)$/);
// +00.123 => [ , '+', '00', '.123', ..
if(notation){
// console.log(notation)
if(options.leadingZeros){ //accept with leading zeros
trimmedStr = (notation[1] || "") + notation[3];
}else{
if(notation[2] === "0" && notation[3][0]=== "."){ //valid number
}else{
return str;
}
}
return options.eNotation ? Number(trimmedStr) : str;
}else{
return str;
}
// }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
//trim ending zeros for floating number
const eNotation = match[4] || match[6];
if(!options.leadingZeros && leadingZeros.length > 0 && sign && trimmedStr[2] !== ".") return str; //-0123
else if(!options.leadingZeros && leadingZeros.length > 0 && !sign && trimmedStr[1] !== ".") return str; //0123
else if(options.leadingZeros && leadingZeros===str) return 0; //00
else{//no leading zeros or leading zeros are allowed
const num = Number(trimmedStr);
const numStr = "" + num;
if(numStr.search(/[eE]/) !== -1){ //given number is long and parsed to eNotation
if(options.eNotation) return num;
else return str;
}else if(eNotation){ //given number has enotation
if(options.eNotation) return num;
else return str;
}else if(trimmedStr.indexOf(".") !== -1){ //floating number
// const decimalPart = match[5].substr(1);
// const intPart = trimmedStr.substr(0,trimmedStr.indexOf("."));
// const p = numStr.indexOf(".");
// const givenIntPart = numStr.substr(0,p);
// const givenDecPart = numStr.substr(p+1);
if(numStr === "0" && (numTrimmedByZeros === "") ) return num; //0.0
else if(numStr === numTrimmedByZeros) return num; //0.456. 0.79000
else if( sign && numStr === "-"+numTrimmedByZeros) return num;
@@ -80,26 +73,11 @@ function toNumber(str, options = {}){
}
if(leadingZeros){
// if(numTrimmedByZeros === numStr){
// if(options.leadingZeros) return num;
// else return str;
// }else return str;
if(numTrimmedByZeros === numStr) return num;
else if(sign+numTrimmedByZeros === numStr) return num;
else return str;
return (numTrimmedByZeros === numStr) || (sign+numTrimmedByZeros === numStr) ? num : str
}else {
return (trimmedStr === numStr) || (trimmedStr === sign+numStr) ? num : str
}
if(trimmedStr === numStr) return num;
else if(trimmedStr === sign+numStr) return num;
// else{
// //number with +/- sign
// trimmedStr.test(/[-+][0-9]);
// }
return str;
}
// else if(!eNotation && trimmedStr && trimmedStr !== Number(trimmedStr) ) return str;
}else{ //non-numeric string
return str;
}
@@ -121,4 +99,13 @@ function trimZeros(numStr){
}
return numStr;
}
module.exports = toNumber
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")
}
module.exports = toNumber;

27
node_modules/strnum/strnum.test.js generated vendored
View File

@@ -1,4 +1,4 @@
const toNumber = require("./strnum");
const toNumber = require("./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", () => {
@@ -6,6 +6,8 @@ describe("Should convert all the valid numeric strings to number", () => {
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");
@@ -34,6 +36,14 @@ describe("Should convert all the valid numeric strings to number", () => {
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");
@@ -51,11 +61,12 @@ describe("Should convert all the valid numeric strings to 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.");
expect(toNumber("0.") ).toEqual("0.");
expect(toNumber("1.") ).toEqual("1.");
});
it("floating point and leading zeros", () => {
expect(toNumber("0.0")).toEqual(0);
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);
@@ -108,10 +119,13 @@ describe("Should convert all the valid numeric strings to number", () => {
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", () => {
@@ -126,6 +140,7 @@ describe("Should convert all the valid numeric strings to number", () => {
});
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");