MCPcopy Create free account
hub / github.com/apache/pouchdb / parseNumber

Function parseNumber

lib/index.js:3332–3379  ·  view source on GitHub ↗
(str, i)

Source from the content-addressed store, hash-verified

3330}
3331
3332function parseNumber(str, i) {
3333 var originalIdx = i;
3334 var num;
3335 var zero = str[i] === '1';
3336 if (zero) {
3337 num = 0;
3338 i++;
3339 } else {
3340 var neg = str[i] === '0';
3341 i++;
3342 var numAsString = '';
3343 var magAsString = str.substring(i, i + MAGNITUDE_DIGITS);
3344 var magnitude = parseInt(magAsString, 10) + MIN_MAGNITUDE;
3345 /* istanbul ignore next */
3346 if (neg) {
3347 magnitude = -magnitude;
3348 }
3349 i += MAGNITUDE_DIGITS;
3350 while (true) {
3351 var ch = str[i];
3352 if (ch === '\u0000') {
3353 break;
3354 } else {
3355 numAsString += ch;
3356 }
3357 i++;
3358 }
3359 numAsString = numAsString.split('.');
3360 if (numAsString.length === 1) {
3361 num = parseInt(numAsString, 10);
3362 } else {
3363 /* istanbul ignore next */
3364 num = parseFloat(numAsString[0] + '.' + numAsString[1]);
3365 }
3366 /* istanbul ignore next */
3367 if (neg) {
3368 num = num - 10;
3369 }
3370 /* istanbul ignore next */
3371 if (magnitude !== 0) {
3372 // parseFloat is more reliable than pow due to rounding errors
3373 // e.g. Number.MAX_VALUE would return Infinity if we did
3374 // num * Math.pow(10, magnitude);
3375 num = parseFloat(num + 'e' + magnitude);
3376 }
3377 }
3378 return {num, length : i - originalIdx};
3379}
3380
3381// move up the stack while parsing
3382// this function moved outside of parseIndexableString for performance

Callers 1

parseIndexableStringFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…