pouchdb-collate
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -11,4 +11,10 @@ !function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.pouchCollate=e():"undefined"!=typeof global?global.pouchCollate=e():"undefined"!=typeof self&&(self.pouchCollate=e())}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
exports.collate = function (a, b) { | ||
if (a === b) { | ||
return 0; | ||
} | ||
a = exports.normalizeKey(a); | ||
b = exports.normalizeKey(b); | ||
var ai = collationIndex(a); | ||
@@ -44,4 +50,25 @@ var bi = collationIndex(b); | ||
return key; | ||
case 'object': | ||
var origKey = key; | ||
if (Array.isArray(key)) { | ||
var len = key.length; | ||
key = new Array(len); | ||
for (var i = 0; i < len; i++) { | ||
key[i] = exports.normalizeKey(origKey[i]); | ||
} | ||
} else if (key instanceof Date) { | ||
return key.toJSON(); | ||
} else if (key !== null) { // generic object | ||
key = {}; | ||
for (var k in origKey) { | ||
if (origKey.hasOwnProperty(k)) { | ||
var val = origKey[k]; | ||
if (typeof val !== 'undefined') { | ||
key[k] = exports.normalizeKey(val); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return key instanceof Date ? key.toJSON() : key; | ||
return key; | ||
}; | ||
@@ -163,2 +190,6 @@ | ||
if (num === 0) { | ||
return '1'; | ||
} | ||
// convert number to exponential format for easier and | ||
@@ -171,6 +202,2 @@ // more succinct string sorting | ||
if (num === 0) { | ||
return '1'; | ||
} | ||
var result = neg ? '0' : '2'; | ||
@@ -177,0 +204,0 @@ |
@@ -10,4 +10,10 @@ 'use strict'; | ||
exports.collate = function (a, b) { | ||
if (a === b) { | ||
return 0; | ||
} | ||
a = exports.normalizeKey(a); | ||
b = exports.normalizeKey(b); | ||
var ai = collationIndex(a); | ||
@@ -43,4 +49,25 @@ var bi = collationIndex(b); | ||
return key; | ||
case 'object': | ||
var origKey = key; | ||
if (Array.isArray(key)) { | ||
var len = key.length; | ||
key = new Array(len); | ||
for (var i = 0; i < len; i++) { | ||
key[i] = exports.normalizeKey(origKey[i]); | ||
} | ||
} else if (key instanceof Date) { | ||
return key.toJSON(); | ||
} else if (key !== null) { // generic object | ||
key = {}; | ||
for (var k in origKey) { | ||
if (origKey.hasOwnProperty(k)) { | ||
var val = origKey[k]; | ||
if (typeof val !== 'undefined') { | ||
key[k] = exports.normalizeKey(val); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return key instanceof Date ? key.toJSON() : key; | ||
return key; | ||
}; | ||
@@ -162,2 +189,6 @@ | ||
if (num === 0) { | ||
return '1'; | ||
} | ||
// convert number to exponential format for easier and | ||
@@ -170,6 +201,2 @@ // more succinct string sorting | ||
if (num === 0) { | ||
return '1'; | ||
} | ||
var result = neg ? '0' : '2'; | ||
@@ -176,0 +203,0 @@ |
{ | ||
"name": "pouchdb-collate", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -7,2 +7,3 @@ 'use strict'; | ||
var normalizeKey = pouchCollate.normalizeKey; | ||
var toIndexableString = pouchCollate.toIndexableString; | ||
var utils = require('../lib/utils'); | ||
@@ -281,2 +282,37 @@ | ||
}); | ||
it('verify deep normalization', function () { | ||
var a = { | ||
list : [undefined, '1982-11-30T00:00:00.000Z'], | ||
obj : { | ||
foo: null, | ||
date: '1982-11-30T00:00:00.000Z' | ||
}, | ||
brokenList : [undefined, 1, 2, undefined, 3, 4, 5, undefined] | ||
}; | ||
var b = { | ||
list : [null, new Date('1982-11-30T00:00:00.000Z')], | ||
obj : { | ||
foo: NaN, | ||
date: new Date('1982-11-30T00:00:00.000Z') | ||
}, | ||
ignoredParam : undefined, | ||
brokenList : [null, 1, 2, null, 3, 4, 5, null] | ||
}; | ||
// sanity check | ||
JSON.stringify(a).should.equal(JSON.stringify(b), 'stringify a,b'); | ||
toIndexableString(a).should.equal(toIndexableString(b), 'string a,b'); | ||
toIndexableString(a).should.equal(toIndexableString(b), 'string a,a'); | ||
toIndexableString(b).should.equal(toIndexableString(b), 'string b,b'); | ||
normalizeKey(a).should.deep.equal(normalizeKey(b), 'normalize a,b'); | ||
normalizeKey(a).should.deep.equal(normalizeKey(a), 'normalize a,a'); | ||
normalizeKey(b).should.deep.equal(normalizeKey(b), 'normalize b,b'); | ||
collate(a, b).should.equal(0, 'collate a,b'); | ||
collate(a, a).should.equal(0, 'collate a,a'); | ||
collate(b, b).should.equal(0, 'collate b,b'); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59268
21
843
1