Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pouchdb-collate

Package Overview
Dependencies
Maintainers
3
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pouchdb-collate - npm Package Compare versions

Comparing version 1.2.0 to 6.0.0

LICENSE

77

lib/index.js
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function pad(str, padWith, upToLength) {
var padding = '';
var targetLength = upToLength - str.length;
/* istanbul ignore next */
while (padding.length < targetLength) {
padding += padWith;
}
return padding;
}
function padLeft(str, padWith, upToLength) {
var padding = pad(str, padWith, upToLength);
return padding + str;
}
var MIN_MAGNITUDE = -324; // verified by -Number.MIN_VALUE

@@ -7,6 +24,4 @@ var MAGNITUDE_DIGITS = 3; // ditto

var utils = require('./utils');
function collate(a, b) {
exports.collate = function (a, b) {
if (a === b) {

@@ -16,4 +31,4 @@ return 0;

a = exports.normalizeKey(a);
b = exports.normalizeKey(b);
a = normalizeKey(a);
b = normalizeKey(b);

@@ -37,7 +52,7 @@ var ai = collationIndex(a);

return Array.isArray(a) ? arrayCollate(a, b) : objectCollate(a, b);
};
}
// couch considers null/NaN/Infinity/-Infinity === undefined,
// for the purposes of mapreduce indexes. also, dates get stringified.
exports.normalizeKey = function (key) {
function normalizeKey(key) {
switch (typeof key) {

@@ -57,4 +72,5 @@ case 'undefined':

for (var i = 0; i < len; i++) {
key[i] = exports.normalizeKey(origKey[i]);
key[i] = normalizeKey(origKey[i]);
}
/* istanbul ignore next */
} else if (key instanceof Date) {

@@ -68,3 +84,3 @@ return key.toJSON();

if (typeof val !== 'undefined') {
key[k] = exports.normalizeKey(val);
key[k] = normalizeKey(val);
}

@@ -76,3 +92,3 @@ }

return key;
};
}

@@ -104,3 +120,3 @@ function indexify(key) {

while (++i < len) {
result += exports.toIndexableString(arr[i]);
result += toIndexableString(arr[i]);
}

@@ -110,4 +126,4 @@ } else {

var objKey = arr[i];
result += exports.toIndexableString(objKey) +
exports.toIndexableString(key[objKey]);
result += toIndexableString(objKey) +
toIndexableString(key[objKey]);
}

@@ -124,7 +140,7 @@ }

// sorting is the same given by the collate() function.
exports.toIndexableString = function (key) {
function toIndexableString(key) {
var zero = '\u0000';
key = exports.normalizeKey(key);
key = normalizeKey(key);
return collationIndex(key) + SEP + indexify(key) + zero;
};
}

@@ -144,2 +160,3 @@ function parseNumber(str, i) {

var magnitude = parseInt(magAsString, 10) + MIN_MAGNITUDE;
/* istanbul ignore next */
if (neg) {

@@ -162,7 +179,10 @@ magnitude = -magnitude;

} else {
/* istanbul ignore next */
num = parseFloat(numAsString[0] + '.' + numAsString[1]);
}
/* istanbul ignore next */
if (neg) {
num = num - 10;
}
/* istanbul ignore next */
if (magnitude !== 0) {

@@ -203,3 +223,3 @@ // parseFloat is more reliable than pow due to rounding errors

exports.parseIndexableString = function (str) {
function parseIndexableString(str) {
var stack = [];

@@ -209,2 +229,3 @@ var metaStack = []; // stack for arrays and objects

/*eslint no-constant-condition: ["error", { "checkLoops": false }]*/
while (true) {

@@ -235,2 +256,3 @@ var collationIndex = str[i++];

var parsedStr = '';
/*eslint no-constant-condition: ["error", { "checkLoops": false }]*/
while (true) {

@@ -261,8 +283,10 @@ var ch = str[i];

break;
/* istanbul ignore next */
default:
throw new Error(
'bad collationIndex or unexpectedly reached end of input: ' + collationIndex);
'bad collationIndex or unexpectedly reached end of input: ' +
collationIndex);
}
}
};
}

@@ -272,3 +296,3 @@ function arrayCollate(a, b) {

for (var i = 0; i < len; i++) {
var sort = exports.collate(a[i], b[i]);
var sort = collate(a[i], b[i]);
if (sort !== 0) {

@@ -292,3 +316,3 @@ return sort;

// First sort the keys
var sort = exports.collate(ak[i], bk[i]);
var sort = collate(ak[i], bk[i]);
if (sort !== 0) {

@@ -298,3 +322,3 @@ return sort;

// if the keys are equal sort the values
sort = exports.collate(a[ak[i]], b[bk[i]]);
sort = collate(a[ak[i]], b[bk[i]]);
if (sort !== 0) {

@@ -325,2 +349,3 @@ return sort;

}
/* istanbul ignore next */
if (Array.isArray(x)) {

@@ -354,3 +379,3 @@ return 5;

var magForComparison = ((neg ? -magnitude : magnitude) - MIN_MAGNITUDE);
var magString = utils.padLeft((magForComparison).toString(), '0', MAGNITUDE_DIGITS);
var magString = padLeft((magForComparison).toString(), '0', MAGNITUDE_DIGITS);

@@ -361,2 +386,3 @@ result += SEP + magString;

var factor = Math.abs(parseFloat(expFormat[0])); // [1..10)
/* istanbul ignore next */
if (neg) { // for negative reverse ordering

@@ -375,1 +401,6 @@ factor = 10 - factor;

}
exports.collate = collate;
exports.normalizeKey = normalizeKey;
exports.toIndexableString = toIndexableString;
exports.parseIndexableString = parseIndexableString;
{
"name": "pouchdb-collate",
"version": "1.2.0",
"description": "",
"version": "6.0.0",
"description": "Collation functions for PouchDB map/reduce",
"main": "lib/index.js",
"repository": {
"type": "git",
"url": "https://github.com/pouchdb/collate.git"
},
"keywords": [

@@ -16,17 +12,8 @@ "pouchdb",

],
"scripts": {
"test": "./node_modules/.bin/jshint -c .jshintrc lib/*.js test/*.js && ./node_modules/istanbul/lib/cli.js test ./node_modules/mocha/bin/_mocha test/test.js",
"build": "mkdir -p dist && browserify lib/index.js -s pouchCollate -o dist/pouchdb-collate.js"
},
"license": "Apache",
"bugs": {
"url": "https://github.com/pouchdb/collate/issues"
},
"devDependencies": {
"chai": "~1.8.1",
"mocha": "~1.15.1",
"istanbul": "~0.1.46",
"browserify": "~2.36.1",
"jshint": "~2.3.0"
}
"license": "Apache-2.0",
"jsnext:main": "./src/index.js",
"files": [
"lib",
"src"
]
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc