@aws-amplify/predictions 4.0.27 → 4.0.29-unstable.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
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [4.0.28](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/predictions@4.0.27...@aws-amplify/predictions@4.0.28) (2021-12-03)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @aws-amplify/predictions
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [4.0.27](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/predictions@4.0.26...@aws-amplify/predictions@4.0.27) (2021-12-02)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @aws-amplify/predictions
|
|
@@ -93672,10 +93672,21 @@ const numRegex = /^([\-\+])?(0*)(\.[0-9]+([eE]\-?[0-9]+)?|[0-9]+(\.[0-9]+([eE]\-
|
|
|
93672
93672
|
// const octRegex = /0x[a-z0-9]+/;
|
|
93673
93673
|
// const binRegex = /0x[a-z0-9]+/;
|
|
93674
93674
|
|
|
93675
|
+
|
|
93676
|
+
//polyfill
|
|
93677
|
+
if (!Number.parseInt && window.parseInt) {
|
|
93678
|
+
Number.parseInt = window.parseInt;
|
|
93679
|
+
}
|
|
93680
|
+
if (!Number.parseFloat && window.parseFloat) {
|
|
93681
|
+
Number.parseFloat = window.parseFloat;
|
|
93682
|
+
}
|
|
93683
|
+
|
|
93684
|
+
|
|
93675
93685
|
const consider = {
|
|
93676
93686
|
hex : true,
|
|
93677
93687
|
leadingZeros: true,
|
|
93678
93688
|
decimalPoint: "\.",
|
|
93689
|
+
eNotation: true
|
|
93679
93690
|
//skipLike: /regex/
|
|
93680
93691
|
};
|
|
93681
93692
|
|
|
@@ -93691,7 +93702,10 @@ function toNumber(str, options = {}){
|
|
|
93691
93702
|
if(!str || typeof str !== "string" ) return str;
|
|
93692
93703
|
|
|
93693
93704
|
let trimmedStr = str.trim();
|
|
93694
|
-
|
|
93705
|
+
// if(trimmedStr === "0.0") return 0;
|
|
93706
|
+
// else if(trimmedStr === "+0.0") return 0;
|
|
93707
|
+
// else if(trimmedStr === "-0.0") return -0;
|
|
93708
|
+
|
|
93695
93709
|
if(options.skipLike !== undefined && options.skipLike.test(trimmedStr)) return str;
|
|
93696
93710
|
else if (options.hex && hexRegex.test(trimmedStr)) {
|
|
93697
93711
|
return Number.parseInt(trimmedStr, 16);
|
|
@@ -93703,19 +93717,79 @@ function toNumber(str, options = {}){
|
|
|
93703
93717
|
//separate negative sign, leading zeros, and rest number
|
|
93704
93718
|
const match = numRegex.exec(trimmedStr);
|
|
93705
93719
|
if(match){
|
|
93706
|
-
const
|
|
93720
|
+
const sign = match[1];
|
|
93707
93721
|
const leadingZeros = match[2];
|
|
93708
|
-
|
|
93722
|
+
let numTrimmedByZeros = trimZeros(match[3]); //complete num without leading zeros
|
|
93723
|
+
//trim ending zeros for floating number
|
|
93724
|
+
|
|
93709
93725
|
const eNotation = match[4] || match[6];
|
|
93710
|
-
if(leadingZeros.length
|
|
93711
|
-
else if(!options.leadingZeros && leadingZeros.length > 0) return str;
|
|
93712
|
-
else
|
|
93726
|
+
if(!options.leadingZeros && leadingZeros.length > 0 && sign && trimmedStr[2] !== ".") return str; //-0123
|
|
93727
|
+
else if(!options.leadingZeros && leadingZeros.length > 0 && !sign && trimmedStr[1] !== ".") return str; //0123
|
|
93728
|
+
else{//no leading zeros or leading zeros are allowed
|
|
93729
|
+
const num = Number(trimmedStr);
|
|
93730
|
+
const numStr = "" + num;
|
|
93731
|
+
if(numStr.search(/[eE]/) !== -1){ //given number is long and parsed to eNotation
|
|
93732
|
+
if(options.eNotation) return num;
|
|
93733
|
+
else return str;
|
|
93734
|
+
}else if(eNotation){ //given number has enotation
|
|
93735
|
+
if(options.eNotation) return num;
|
|
93736
|
+
else return str;
|
|
93737
|
+
}else if(trimmedStr.indexOf(".") !== -1){ //floating number
|
|
93738
|
+
// const decimalPart = match[5].substr(1);
|
|
93739
|
+
// const intPart = trimmedStr.substr(0,trimmedStr.indexOf("."));
|
|
93740
|
+
|
|
93741
|
+
|
|
93742
|
+
// const p = numStr.indexOf(".");
|
|
93743
|
+
// const givenIntPart = numStr.substr(0,p);
|
|
93744
|
+
// const givenDecPart = numStr.substr(p+1);
|
|
93745
|
+
if(numStr === "0" && (numTrimmedByZeros === "") ) return num; //0.0
|
|
93746
|
+
else if(numStr === numTrimmedByZeros) return num; //0.456. 0.79000
|
|
93747
|
+
else if( sign && numStr === "-"+numTrimmedByZeros) return num;
|
|
93748
|
+
else return str;
|
|
93749
|
+
}
|
|
93750
|
+
|
|
93751
|
+
if(leadingZeros){
|
|
93752
|
+
// if(numTrimmedByZeros === numStr){
|
|
93753
|
+
// if(options.leadingZeros) return num;
|
|
93754
|
+
// else return str;
|
|
93755
|
+
// }else return str;
|
|
93756
|
+
if(numTrimmedByZeros === numStr) return num;
|
|
93757
|
+
else if(sign+numTrimmedByZeros === numStr) return num;
|
|
93758
|
+
else return str;
|
|
93759
|
+
}
|
|
93760
|
+
|
|
93761
|
+
if(trimmedStr === numStr) return num;
|
|
93762
|
+
else if(trimmedStr === sign+numStr) return num;
|
|
93763
|
+
// else{
|
|
93764
|
+
// //number with +/- sign
|
|
93765
|
+
// trimmedStr.test(/[-+][0-9]);
|
|
93766
|
+
|
|
93767
|
+
// }
|
|
93768
|
+
return str;
|
|
93769
|
+
}
|
|
93770
|
+
// else if(!eNotation && trimmedStr && trimmedStr !== Number(trimmedStr) ) return str;
|
|
93771
|
+
|
|
93713
93772
|
}else{ //non-numeric string
|
|
93714
93773
|
return str;
|
|
93715
93774
|
}
|
|
93716
93775
|
}
|
|
93717
93776
|
}
|
|
93718
93777
|
|
|
93778
|
+
/**
|
|
93779
|
+
*
|
|
93780
|
+
* @param {string} numStr without leading zeros
|
|
93781
|
+
* @returns
|
|
93782
|
+
*/
|
|
93783
|
+
function trimZeros(numStr){
|
|
93784
|
+
if(numStr && numStr.indexOf(".") !== -1){//float
|
|
93785
|
+
numStr = numStr.replace(/0+$/, ""); //remove ending zeros
|
|
93786
|
+
if(numStr === ".") numStr = "0";
|
|
93787
|
+
else if(numStr[0] === ".") numStr = "0"+numStr;
|
|
93788
|
+
else if(numStr[numStr.length-1] === ".") numStr = numStr.substr(0,numStr.length-1);
|
|
93789
|
+
return numStr;
|
|
93790
|
+
}
|
|
93791
|
+
return numStr;
|
|
93792
|
+
}
|
|
93719
93793
|
module.exports = toNumber
|
|
93720
93794
|
|
|
93721
93795
|
|