MCPcopy
hub / github.com/autoNumeric/autoNumeric / parseStr

Method parseStr

src/AutoNumericHelper.js:1101–1164  ·  view source on GitHub ↗

* Function to parse minimumValue, maximumValue & the input value to prepare for testing to determine if the value falls within the min / max range. * Return an object example: minimumValue: "999999999999999.99" returns the following "{s: -1, e: 12, c: Array[15]}". * * This function is

(value)

Source from the content-addressed store, hash-verified

1099 * @returns {Big}
1100 */
1101 static parseStr(value) {
1102 if (AutoNumericHelper.isUndefinedOrNullOrEmpty(value)) {
1103 return { s: 1, e: 0, c: [0] }; // Return the representation for null/undefined
1104 }
1105
1106 const result = {}; // A Big number instance.
1107 let e;
1108 let i;
1109 let nL;
1110 let j;
1111
1112 // Minus zero?
1113 if (value === 0 && 1 / value < 0) {
1114 value = '-0';
1115 }
1116
1117 // Determine sign. 1 positive, -1 negative
1118 value = value.toString();
1119 if (this.isNegativeStrict(value, '-')) {
1120 value = value.slice(1);
1121 result.s = -1;
1122 } else {
1123 result.s = 1;
1124 }
1125
1126 // Decimal point?
1127 e = value.indexOf('.');
1128 if (e > -1) {
1129 value = value.replace('.', '');
1130 }
1131
1132 // Length of string if no decimal character
1133 if (e < 0) {
1134 // Integer
1135 e = value.length;
1136 }
1137
1138 // Determine leading zeros
1139 i = (value.search(/[1-9]/i) === -1) ? value.length : value.search(/[1-9]/i);
1140 nL = value.length;
1141 if (i === nL) {
1142 // Zero
1143 result.e = 0;
1144 result.c = [0];
1145 } else {
1146 // Determine trailing zeros
1147 for (j = nL - 1; value.charAt(j) === '0'; j -= 1) {
1148 nL -= 1;
1149 }
1150 nL -= 1;
1151
1152 // Decimal location
1153 result.e = e - i - 1;
1154 result.c = [];
1155
1156 // Convert string to array of digits without leading/trailing zeros
1157 for (e = 0; i <= nL; i += 1) {
1158 result.c[e] = +value.charAt(i);

Callers 6

_onPasteMethod · 0.80
_checkIfInRangeMethod · 0.80

Calls 2

isNegativeStrictMethod · 0.95

Tested by

no test coverage detected