MCPcopy Index your code
hub / github.com/apache/pouchdb / numToIndexableString

Function numToIndexableString

lib/index.js:3538–3575  ·  view source on GitHub ↗
(num)

Source from the content-addressed store, hash-verified

3536// y = exponent (for negative numbers negated) moved so that it's >= 0
3537// z = mantisse
3538function numToIndexableString(num) {
3539
3540 if (num === 0) {
3541 return '1';
3542 }
3543
3544 // convert number to exponential format for easier and
3545 // more succinct string sorting
3546 var expFormat = num.toExponential().split(/e\+?/);
3547 var magnitude = parseInt(expFormat[1], 10);
3548
3549 var neg = num < 0;
3550
3551 var result = neg ? '0' : '2';
3552
3553 // first sort by magnitude
3554 // it's easier if all magnitudes are positive
3555 var magForComparison = ((neg ? -magnitude : magnitude) - MIN_MAGNITUDE);
3556 var magString = padLeft((magForComparison).toString(), '0', MAGNITUDE_DIGITS);
3557
3558 result += SEP + magString;
3559
3560 // then sort by the factor
3561 var factor = Math.abs(parseFloat(expFormat[0])); // [1..10)
3562 /* istanbul ignore next */
3563 if (neg) { // for negative reverse ordering
3564 factor = 10 - factor;
3565 }
3566
3567 var factorStr = factor.toFixed(20);
3568
3569 // strip zeros from the end
3570 factorStr = factorStr.replace(/\.?0+$/, '');
3571
3572 result += SEP + factorStr;
3573
3574 return result;
3575}
3576
3577// create a comparator based on the sort object
3578function createFieldSorter(sort) {

Callers 1

indexifyFunction · 0.70

Calls 2

padLeftFunction · 0.70
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…