Socket
Socket
Sign inDemoInstall

@feathersjs/commons

Package Overview
Dependencies
Maintainers
4
Versions
105
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@feathersjs/commons - npm Package Compare versions

Comparing version 1.4.1 to 1.4.3

27

CHANGELOG.md
# Change Log
## [v1.4.2](https://github.com/feathersjs/commons/tree/v1.4.2) (2018-07-25)
[Full Changelog](https://github.com/feathersjs/commons/compare/v1.4.1...v1.4.2)
**Closed issues:**
- Sort error on multiple fields [\#74](https://github.com/feathersjs/commons/issues/74)
- Cannot build with create-react-app \(again\) [\#71](https://github.com/feathersjs/commons/issues/71)
**Merged pull requests:**
- Update all dependencies [\#77](https://github.com/feathersjs/commons/pull/77) ([daffl](https://github.com/daffl))
- Use sorting algorithm from NeDB [\#76](https://github.com/feathersjs/commons/pull/76) ([daffl](https://github.com/daffl))
- Open hook workflow to custom methods [\#72](https://github.com/feathersjs/commons/pull/72) ([bertho-zero](https://github.com/bertho-zero))
## [v1.4.1](https://github.com/feathersjs/commons/tree/v1.4.1) (2018-04-12)
[Full Changelog](https://github.com/feathersjs/commons/compare/v1.4.0...v1.4.1)
**Closed issues:**
- Uncaught ReferenceError: convertGetOrRemove is not defined [\#69](https://github.com/feathersjs/commons/issues/69)
- Cannot build with create-react-app [\#68](https://github.com/feathersjs/commons/issues/68)
**Merged pull requests:**
- Make conversion functions more concise [\#70](https://github.com/feathersjs/commons/pull/70) ([daffl](https://github.com/daffl))
- Update mocha to the latest version 🚀 [\#67](https://github.com/feathersjs/commons/pull/67) ([greenkeeper[bot]](https://github.com/apps/greenkeeper))
## [v1.4.0](https://github.com/feathersjs/commons/tree/v1.4.0) (2018-01-17)

@@ -4,0 +31,0 @@ [Full Changelog](https://github.com/feathersjs/commons/compare/v1.3.1...v1.4.0)

25

lib/hooks.js

@@ -96,3 +96,3 @@ const { each, pick } = require('./utils')._;

exports.convertHookData = function convertHookData (obj) {
var hook = {};
let hook = {};

@@ -154,7 +154,4 @@ if (Array.isArray(obj)) {

};
// First step of the hook chain with the initial hook object
let promise = Promise.resolve(hookObject);
// Go through all hooks and chain them into our promise
hooks.forEach(fn => {
const promise = hooks.reduce((promise, fn) => {
const hook = fn.bind(this);

@@ -173,12 +170,10 @@

// Use the returned hook object or the old one
promise = promise.then(updateCurrentHook);
return promise.then(updateCurrentHook);
}, Promise.resolve(hookObject));
return promise.then(() => hookObject).catch(error => {
// Add the hook information to any errors
error.hook = hookObject;
throw error;
});
return promise
.then(() => hookObject)
.catch(error => {
// Add the hook information to any errors
error.hook = hookObject;
throw error;
});
};

@@ -192,3 +187,3 @@

let __hooks = {};
const __hooks = {};

@@ -195,0 +190,0 @@ types.forEach(type => {

121

lib/utils.js

@@ -59,9 +59,9 @@ // Removes all leading and trailing slashes from a path

pick (source, ...keys) {
const result = {};
keys.forEach(key => {
return keys.reduce((result, key) => {
if (source[key] !== undefined) {
result[key] = source[key];
}
});
return result;
return result;
}, {});
},

@@ -115,22 +115,2 @@

// An in-memory sorting function according to the
// $sort special query parameter
exports.sorter = function sorter ($sort) {
return function (first, second) {
let comparator = 0;
_.each($sort, (modifier, key) => {
modifier = parseInt(modifier, 10);
if (first[key] < second[key]) {
comparator -= 1 * modifier;
}
if (first[key] > second[key]) {
comparator += 1 * modifier;
}
});
return comparator;
};
};
// Duck-checks if an object looks like a promise

@@ -154,1 +134,94 @@ exports.isPromise = function isPromise (result) {

};
// Sorting algorithm taken from NeDB (https://github.com/louischatriot/nedb)
// See https://github.com/louischatriot/nedb/blob/e3f0078499aa1005a59d0c2372e425ab789145c1/lib/model.js#L189
exports.compareNSB = function (a, b) {
if (a < b) { return -1; }
if (a > b) { return 1; }
return 0;
};
exports.compareArrays = function compareArrays (a, b) {
var i, comp;
for (i = 0; i < Math.min(a.length, b.length); i += 1) {
comp = exports.compare(a[i], b[i]);
if (comp !== 0) { return comp; }
}
// Common section was identical, longest one wins
return exports.compareNSB(a.length, b.length);
};
exports.compare = function compare (a, b, compareStrings = exports.compareNSB) {
const { compareNSB, compare, compareArrays } = exports;
// undefined
if (a === undefined) { return b === undefined ? 0 : -1; }
if (b === undefined) { return a === undefined ? 0 : 1; }
// null
if (a === null) { return b === null ? 0 : -1; }
if (b === null) { return a === null ? 0 : 1; }
// Numbers
if (typeof a === 'number') { return typeof b === 'number' ? compareNSB(a, b) : -1; }
if (typeof b === 'number') { return typeof a === 'number' ? compareNSB(a, b) : 1; }
// Strings
if (typeof a === 'string') { return typeof b === 'string' ? compareStrings(a, b) : -1; }
if (typeof b === 'string') { return typeof a === 'string' ? compareStrings(a, b) : 1; }
// Booleans
if (typeof a === 'boolean') { return typeof b === 'boolean' ? compareNSB(a, b) : -1; }
if (typeof b === 'boolean') { return typeof a === 'boolean' ? compareNSB(a, b) : 1; }
// Dates
if (a instanceof Date) { return b instanceof Date ? compareNSB(a.getTime(), b.getTime()) : -1; }
if (b instanceof Date) { return a instanceof Date ? compareNSB(a.getTime(), b.getTime()) : 1; }
// Arrays (first element is most significant and so on)
if (Array.isArray(a)) { return Array.isArray(b) ? compareArrays(a, b) : -1; }
if (Array.isArray(b)) { return Array.isArray(a) ? compareArrays(a, b) : 1; }
// Objects
const aKeys = Object.keys(a).sort();
const bKeys = Object.keys(b).sort();
let comp = 0;
for (let i = 0; i < Math.min(aKeys.length, bKeys.length); i += 1) {
comp = compare(a[aKeys[i]], b[bKeys[i]]);
if (comp !== 0) { return comp; }
}
return compareNSB(aKeys.length, bKeys.length);
};
// An in-memory sorting function according to the
// $sort special query parameter
exports.sorter = function sorter ($sort) {
const criteria = Object.keys($sort).map(key => {
const direction = $sort[key];
return { key, direction };
});
return function (a, b) {
let compare;
for (let i = 0; i < criteria.length; i++) {
const criterion = criteria[i];
compare = criterion.direction * exports.compare(a[criterion.key], b[criterion.key]);
if (compare !== 0) {
return compare;
}
}
return 0;
};
};
{
"name": "@feathersjs/commons",
"version": "1.4.1",
"version": "1.4.3",
"description": "Shared Feathers utility functions",

@@ -49,7 +49,7 @@ "homepage": "https://github.com/feathersjs/commons",

"devDependencies": {
"chai": "^4.0.0",
"chai": "^4.1.2",
"istanbul": "^1.1.0-alpha.1",
"mocha": "^5.0.0",
"semistandard": "^12.0.0"
"mocha": "^5.2.0",
"semistandard": "^12.0.1"
}
}
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