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

fast-sort

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-sort - npm Package Compare versions

Comparing version 2.1.0 to 2.1.1

47

dist/sort.es.js

@@ -20,23 +20,25 @@ // >>> HELPERS <<<

// >>> SORTERS <<<
var multiPropertySorter = function (sortBy, sortByArray, depth, order, comparer, a, b) {
var valA;
var valB;
if (typeof sortBy === 'string') {
valA = a[sortBy];
valB = b[sortBy];
}
else if (typeof sortBy === 'function') {
valA = sortBy(a);
valB = sortBy(b);
}
else {
var objectSorterConfig = unpackObjectSorter(sortBy);
return multiPropertySorter(objectSorterConfig.sortBy, sortByArray, depth, objectSorterConfig.order, objectSorterConfig.comparer || comparer, a, b);
}
var equality = comparer(valA, valB, order);
if (sortByArray.length > depth &&
(equality === 0 || (valA == null && valB == null))) {
return multiPropertySorter(sortByArray[depth], sortByArray, depth + 1, order, comparer, a, b);
}
return equality;
var multiPropertySorterProvider = function (defaultComparer) {
return function multiPropertySorter(sortBy, sortByArray, depth, order, comparer, a, b) {
var valA;
var valB;
if (typeof sortBy === 'string') {
valA = a[sortBy];
valB = b[sortBy];
}
else if (typeof sortBy === 'function') {
valA = sortBy(a);
valB = sortBy(b);
}
else {
var objectSorterConfig = unpackObjectSorter(sortBy);
return multiPropertySorter(objectSorterConfig.sortBy, sortByArray, depth, objectSorterConfig.order, objectSorterConfig.comparer || defaultComparer, a, b);
}
var equality = comparer(valA, valB, order);
if (sortByArray.length > depth &&
(equality === 0 || (valA == null && valB == null))) {
return multiPropertySorter(sortByArray[depth], sortByArray, depth + 1, order, comparer, a, b);
}
return equality;
};
};

@@ -66,3 +68,4 @@ var sort = function (order, ctx, sortBy, comparer) {

else if (Array.isArray(sortBy)) {
sorter = multiPropertySorter.bind(undefined, sortBy[0], sortBy, 1, order, comparer);
sorter = multiPropertySorterProvider(comparer)
.bind(undefined, sortBy[0], sortBy, 1, order, comparer);
}

@@ -69,0 +72,0 @@ else {

@@ -26,23 +26,25 @@ (function (global, factory) {

// >>> SORTERS <<<
var multiPropertySorter = function (sortBy, sortByArray, depth, order, comparer, a, b) {
var valA;
var valB;
if (typeof sortBy === 'string') {
valA = a[sortBy];
valB = b[sortBy];
}
else if (typeof sortBy === 'function') {
valA = sortBy(a);
valB = sortBy(b);
}
else {
var objectSorterConfig = unpackObjectSorter(sortBy);
return multiPropertySorter(objectSorterConfig.sortBy, sortByArray, depth, objectSorterConfig.order, objectSorterConfig.comparer || comparer, a, b);
}
var equality = comparer(valA, valB, order);
if (sortByArray.length > depth &&
(equality === 0 || (valA == null && valB == null))) {
return multiPropertySorter(sortByArray[depth], sortByArray, depth + 1, order, comparer, a, b);
}
return equality;
var multiPropertySorterProvider = function (defaultComparer) {
return function multiPropertySorter(sortBy, sortByArray, depth, order, comparer, a, b) {
var valA;
var valB;
if (typeof sortBy === 'string') {
valA = a[sortBy];
valB = b[sortBy];
}
else if (typeof sortBy === 'function') {
valA = sortBy(a);
valB = sortBy(b);
}
else {
var objectSorterConfig = unpackObjectSorter(sortBy);
return multiPropertySorter(objectSorterConfig.sortBy, sortByArray, depth, objectSorterConfig.order, objectSorterConfig.comparer || defaultComparer, a, b);
}
var equality = comparer(valA, valB, order);
if (sortByArray.length > depth &&
(equality === 0 || (valA == null && valB == null))) {
return multiPropertySorter(sortByArray[depth], sortByArray, depth + 1, order, comparer, a, b);
}
return equality;
};
};

@@ -72,3 +74,4 @@ var sort = function (order, ctx, sortBy, comparer) {

else if (Array.isArray(sortBy)) {
sorter = multiPropertySorter.bind(undefined, sortBy[0], sortBy, 1, order, comparer);
sorter = multiPropertySorterProvider(comparer)
.bind(undefined, sortBy[0], sortBy, 1, order, comparer);
}

@@ -75,0 +78,0 @@ else {

@@ -1,1 +0,1 @@

!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(r=r||self)["fast-sort"]=n()}(this,function(){"use strict";function u(t){return function(r,n,e){return t(r,n,e)*e}}function f(r){throw Error("Invalid sort config: "+r)}function d(r){var n=r||{},e=n.asc,t=n.desc,o=e?1:-1,i=e||t;if(e&&t)throw f("Ambiguous object with `asc` and `desc` config properties");return i||f("Expected `asc` or `desc` property"),{order:o,sortBy:i,comparer:r.comparer&&u(r.comparer)}}var p=function(r,n,e,t,o,i,u){var f,c;if("string"==typeof r)f=i[r],c=u[r];else{if("function"!=typeof r){var s=d(r);return p(s.sortBy,n,e,s.order,s.comparer||o,i,u)}f=r(i),c=r(u)}var a=o(f,c,t);return n.length>e&&(0===a||null==f&&null==c)?p(n[e],n,e+1,t,o,i,u):a},c=function(e,r,t,o){var n;if(!Array.isArray(r))return r;if(Array.isArray(t)&&t.length<2&&(t=t[0]),void 0===t||!0===t)n=function(r,n){return o(r,n,e)};else if("string"==typeof t){if(t.includes("."))throw f("String syntax not allowed for nested properties.");n=function(r,n){return o(r[t],n[t],e)}}else if("function"==typeof t)n=function(r,n){return o(t(r),t(n),e)};else{if(!Array.isArray(t)){var i=d(t);return c(i.order,r,i.sortBy,i.comparer||o)}n=p.bind(void 0,t[0],t,1,e,o)}return r.sort(n)};function r(r){var e=u(r.comparer);return function(n){return{asc:function(r){return c(1,n,r,e)},desc:function(r){return c(-1,n,r,e)},by:function(r){return c(1,n,r,e)}}}}var n=r({comparer:function(r,n,e){return null==r?e:null==n?-e:r<n?-1:r===n?0:1}});return n.createNewInstance=r,n});
!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(r=r||self)["fast-sort"]=n()}(this,function(){"use strict";function u(t){return function(r,n,e){return t(r,n,e)*e}}function f(r){throw Error("Invalid sort config: "+r)}function l(r){var n=r||{},e=n.asc,t=n.desc,o=e?1:-1,i=e||t;if(e&&t)throw f("Ambiguous object with `asc` and `desc` config properties");return i||f("Expected `asc` or `desc` property"),{order:o,sortBy:i,comparer:r.comparer&&u(r.comparer)}}var c=function(e,r,t,o){var n,p;if(!Array.isArray(r))return r;if(Array.isArray(t)&&t.length<2&&(t=t[0]),void 0===t||!0===t)n=function(r,n){return o(r,n,e)};else if("string"==typeof t){if(t.includes("."))throw f("String syntax not allowed for nested properties.");n=function(r,n){return o(r[t],n[t],e)}}else if("function"==typeof t)n=function(r,n){return o(t(r),t(n),e)};else{if(!Array.isArray(t)){var i=l(t);return c(i.order,r,i.sortBy,i.comparer||o)}n=(p=o,function r(n,e,t,o,i,u,f){var c,s;if("string"==typeof n)c=u[n],s=f[n];else{if("function"!=typeof n){var a=l(n);return r(a.sortBy,e,t,a.order,a.comparer||p,u,f)}c=n(u),s=n(f)}var d=i(c,s,o);return e.length>t&&(0===d||null==c&&null==s)?r(e[t],e,t+1,o,i,u,f):d}).bind(void 0,t[0],t,1,e,o)}return r.sort(n)};function r(r){var e=u(r.comparer);return function(n){return{asc:function(r){return c(1,n,r,e)},desc:function(r){return c(-1,n,r,e)},by:function(r){return c(1,n,r,e)}}}}var n=r({comparer:function(r,n,e){return null==r?e:null==n?-e:r<n?-1:r===n?0:1}});return n.createNewInstance=r,n});
{
"name": "fast-sort",
"version": "2.1.0",
"version": "2.1.1",
"description": "Fast and powerful array sorting. Sort by any property in any direction with easy to read syntax.",

@@ -5,0 +5,0 @@ "main": "dist/sort.js",

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