Comparing version 1.5.1 to 1.5.2
@@ -1,1 +0,1 @@ | ||
{"name":"fast-sort","version":"1.5.1","description":"Fast and powerful array sorting. Sort by any property in any direction with easy to read syntax.","main":"sort.js","author":"Stefan Novakovic <stefan.novakovich@gmail.com>","license":"MIT","homepage":"https://github.com/snovakovic/fast-sort#readme","scripts":{"test":"node integration_test/index.js","publish":"node publish"},"repository":{"type":"git","url":"git+https://github.com/snovakovic/js-flock.git"},"bugs":{"url":"https://github.com/snovakovic/js-flock/issues"},"keywords":["sort","sortBy","order","orderBy"]} | ||
{"name":"fast-sort","version":"1.5.2","description":"Fast and powerful array sorting. Sort by any property in any direction with easy to read syntax.","main":"sort.js","author":"Stefan Novakovic <stefan.novakovich@gmail.com>","license":"MIT","homepage":"https://github.com/snovakovic/fast-sort#readme","scripts":{"test":"node integration_test/index.js","publish":"node publish"},"repository":{"type":"git","url":"git+https://github.com/snovakovic/js-flock.git"},"bugs":{"url":"https://github.com/snovakovic/js-flock/issues"},"keywords":["sort","sortBy","order","orderBy"]} |
@@ -144,6 +144,16 @@ (function (global, factory) { | ||
if (!Array.isArray(sortBy) || sortBy.length < 2) { | ||
throw Error('sort: Invalid usage of \'by\' sorter.\n \'by\' sorter should be used only for sorting in multiple directions.\n Did you mean to use \'asc\' or \'desc\' sorter instead?'); | ||
if (!Array.isArray(sortBy)) { | ||
throw Error('sort: Invalid usage of \'by\' sorter. Array syntax is required.\n Did you mean to use \'asc\' or \'desc\' sorter instead?'); | ||
} | ||
// Unwrap sort by to faster path | ||
if (sortBy.length === 1) { | ||
var direction = sortBy[0].asc ? 1 : -1; | ||
var sortOnProp = sortBy[0].asc || sortBy[0].desc; | ||
if (!sortOnProp) { | ||
throw Error('sort: Invalid \'by\' sorting onfiguration.\n Expecting object with \'asc\' or \'desc\' key'); | ||
} | ||
return sort(direction, ctx, sortOnProp); | ||
} | ||
var _sorter = multiPropObjectSorter.bind(undefined, sortBy.shift(), sortBy, 0, undefined); | ||
@@ -150,0 +160,0 @@ return ctx.sort(_sorter); |
@@ -1,1 +0,1 @@ | ||
!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(r.sort=r.sort||{},r.sort.js=n())}(this,function(){"use strict";var e=function(r,n){if(Array.isArray(r))return r;if(Symbol.iterator in Object(r))return function(r,n){var t=[],o=!0,e=!1,i=void 0;try{for(var u,f=r[Symbol.iterator]();!(o=(u=f.next()).done)&&(t.push(u.value),!n||t.length!==n);o=!0);}catch(r){e=!0,i=r}finally{try{!o&&f.return&&f.return()}finally{if(e)throw i}}return t}(r,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")},t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},f=function(r,n,t){return n===t?0:n<t?-r:null==n?1:null==t?-1:r},o=function(r,n,t,o,e,i){return c(r(e),r(i),n,t,o,e,i)},i=function(r,n,t,o,e,i){return c(e[r],i[r],n,t,o,e,i)},u=function(r,n,t,o,e,i){var u=r.asc||r.desc,f=r.asc?1:-1;if(!u)throw Error("sort: Invalid 'by' sorting onfiguration.\n Expecting object with 'asc' or 'desc' key");return s(u)(u,n,t,f,e,i)},s=function(r){var n=void 0===r?"undefined":t(r);return"string"===n?i:"function"===n?o:u},c=function(r,n,t,o,e,i,u){return r===n||null==r&&null==n?t.length>o?s(t[o])(t[o],t,o+1,e,i,u):0:f(e,r,n)},n=function(r,n,t){if(!Array.isArray(n))return n;Array.isArray(t)&&t.length<2&&(t=e(t,1)[0]);var o=void 0;return o=t?"string"==typeof t?function(r,n,t,o){return f(r,t[n],o[n])}.bind(void 0,r,t):"function"==typeof t?function(r,n,t,o){return f(r,n(t),n(o))}.bind(void 0,r,t):s(t[0]).bind(void 0,t.shift(),t,0,r):f.bind(void 0,r),n.sort(o)};return function(t){return{asc:function(r){return n(1,t,r)},desc:function(r){return n(-1,t,r)},by:function(r){if(!Array.isArray(t))return t;if(!Array.isArray(r)||r.length<2)throw Error("sort: Invalid usage of 'by' sorter.\n 'by' sorter should be used only for sorting in multiple directions.\n Did you mean to use 'asc' or 'desc' sorter instead?");var n=u.bind(void 0,r.shift(),r,0,void 0);return t.sort(n)}}}}); | ||
!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(r.sort=r.sort||{},r.sort.js=n())}(this,function(){"use strict";var e=function(r,n){if(Array.isArray(r))return r;if(Symbol.iterator in Object(r))return function(r,n){var t=[],o=!0,e=!1,i=void 0;try{for(var u,f=r[Symbol.iterator]();!(o=(u=f.next()).done)&&(t.push(u.value),!n||t.length!==n);o=!0);}catch(r){e=!0,i=r}finally{try{!o&&f.return&&f.return()}finally{if(e)throw i}}return t}(r,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")},t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},f=function(r,n,t){return n===t?0:n<t?-r:null==n?1:null==t?-1:r},o=function(r,n,t,o,e,i){return c(r(e),r(i),n,t,o,e,i)},i=function(r,n,t,o,e,i){return c(e[r],i[r],n,t,o,e,i)},u=function(r,n,t,o,e,i){var u=r.asc||r.desc,f=r.asc?1:-1;if(!u)throw Error("sort: Invalid 'by' sorting onfiguration.\n Expecting object with 'asc' or 'desc' key");return s(u)(u,n,t,f,e,i)},s=function(r){var n=void 0===r?"undefined":t(r);return"string"===n?i:"function"===n?o:u},c=function(r,n,t,o,e,i,u){return r===n||null==r&&null==n?t.length>o?s(t[o])(t[o],t,o+1,e,i,u):0:f(e,r,n)},a=function(r,n,t){if(!Array.isArray(n))return n;Array.isArray(t)&&t.length<2&&(t=e(t,1)[0]);var o=void 0;return o=t?"string"==typeof t?function(r,n,t,o){return f(r,t[n],o[n])}.bind(void 0,r,t):"function"==typeof t?function(r,n,t,o){return f(r,n(t),n(o))}.bind(void 0,r,t):s(t[0]).bind(void 0,t.shift(),t,0,r):f.bind(void 0,r),n.sort(o)};return function(e){return{asc:function(r){return a(1,e,r)},desc:function(r){return a(-1,e,r)},by:function(r){if(!Array.isArray(e))return e;if(!Array.isArray(r))throw Error("sort: Invalid usage of 'by' sorter. Array syntax is required.\n Did you mean to use 'asc' or 'desc' sorter instead?");if(1===r.length){var n=r[0].asc?1:-1,t=r[0].asc||r[0].desc;if(!t)throw Error("sort: Invalid 'by' sorting onfiguration.\n Expecting object with 'asc' or 'desc' key");return a(n,e,t)}var o=u.bind(void 0,r.shift(),r,0,void 0);return e.sort(o)}}}}); |
16
sort.js
@@ -128,8 +128,18 @@ /* eslint no-use-before-define: 0 */ | ||
if (!Array.isArray(sortBy) || sortBy.length < 2) { | ||
throw Error(`sort: Invalid usage of 'by' sorter. | ||
'by' sorter should be used only for sorting in multiple directions. | ||
if (!Array.isArray(sortBy)) { | ||
throw Error(`sort: Invalid usage of 'by' sorter. Array syntax is required. | ||
Did you mean to use 'asc' or 'desc' sorter instead?`); | ||
} | ||
// Unwrap sort by to faster path | ||
if (sortBy.length === 1) { | ||
const direction = sortBy[0].asc ? 1 : -1; | ||
const sortOnProp = sortBy[0].asc || sortBy[0].desc; | ||
if (!sortOnProp) { | ||
throw Error(`sort: Invalid 'by' sorting onfiguration. | ||
Expecting object with 'asc' or 'desc' key`); | ||
} | ||
return sort(direction, ctx, sortOnProp); | ||
} | ||
const _sorter = multiPropObjectSorter.bind(undefined, sortBy.shift(), sortBy, 0, undefined); | ||
@@ -136,0 +146,0 @@ return ctx.sort(_sorter); |
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
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
18956
268