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

Function normalizeKey

lib/index-browser.js:3406–3439  ·  view source on GitHub ↗
(key)

Source from the content-addressed store, hash-verified

3404// couch considers null/NaN/Infinity/-Infinity === undefined,
3405// for the purposes of mapreduce indexes. also, dates get stringified.
3406function normalizeKey(key) {
3407 switch (typeof key) {
3408 case 'undefined':
3409 return null;
3410 case 'number':
3411 if (key === Infinity || key === -Infinity || isNaN(key)) {
3412 return null;
3413 }
3414 return key;
3415 case 'object':
3416 var origKey = key;
3417 if (Array.isArray(key)) {
3418 var len = key.length;
3419 key = new Array(len);
3420 for (var i = 0; i < len; i++) {
3421 key[i] = normalizeKey(origKey[i]);
3422 }
3423 /* istanbul ignore next */
3424 } else if (key instanceof Date) {
3425 return key.toJSON();
3426 } else if (key !== null) { // generic object
3427 key = {};
3428 for (var k in origKey) {
3429 if (Object.prototype.hasOwnProperty.call(origKey, k)) {
3430 var val = origKey[k];
3431 if (typeof val !== 'undefined') {
3432 key[k] = normalizeKey(val);
3433 }
3434 }
3435 }
3436 }
3437 }
3438 return key;
3439}
3440
3441function indexify(key) {
3442 if (key !== null) {

Callers 3

collateFunction · 0.70
toIndexableStringFunction · 0.70
emitFunction · 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…