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

Function normalizeKey

lib/index.js:3246–3279  ·  view source on GitHub ↗
(key)

Source from the content-addressed store, hash-verified

3244// couch considers null/NaN/Infinity/-Infinity === undefined,
3245// for the purposes of mapreduce indexes. also, dates get stringified.
3246function normalizeKey(key) {
3247 switch (typeof key) {
3248 case 'undefined':
3249 return null;
3250 case 'number':
3251 if (key === Infinity || key === -Infinity || isNaN(key)) {
3252 return null;
3253 }
3254 return key;
3255 case 'object':
3256 var origKey = key;
3257 if (Array.isArray(key)) {
3258 var len = key.length;
3259 key = new Array(len);
3260 for (var i = 0; i < len; i++) {
3261 key[i] = normalizeKey(origKey[i]);
3262 }
3263 /* istanbul ignore next */
3264 } else if (key instanceof Date) {
3265 return key.toJSON();
3266 } else if (key !== null) { // generic object
3267 key = {};
3268 for (var k in origKey) {
3269 if (Object.prototype.hasOwnProperty.call(origKey, k)) {
3270 var val = origKey[k];
3271 if (typeof val !== 'undefined') {
3272 key[k] = normalizeKey(val);
3273 }
3274 }
3275 }
3276 }
3277 }
3278 return key;
3279}
3280
3281function indexify(key) {
3282 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…