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

array-tools

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

array-tools - npm Package Compare versions

Comparing version 1.4.5 to 1.5.0

27

lib/array-tools.js

@@ -34,7 +34,6 @@ "use strict";

> var data = [
... {one: 1, two: 2},
... {two: "two"},
... {one: "one", two: "zwei"},
... ];
undefined
{one: 1, two: 2},
{two: "two"},
{one: "one", two: "zwei"},
];
> a.pluck(data, "one");

@@ -125,3 +124,2 @@ [ 1, 'one' ]

> function f(){ return a.arrayify(arguments); }
undefined
> f(1,2,3)

@@ -243,11 +241,8 @@ [ 1, 2, 3 ]

> var array1 = [ 1, 2 ], array2 = [ 2, 3 ];
undefined
> a.union(array1, array2)
[ 1, 2, 3 ]
> var array1 = [ { id: 1 }, { id: 2 } ], array2 = [ { id: 2 }, { id: 3 } ];
undefined
> a.union(array1, array2)
[ { id: 1 }, { id: 2 }, { id: 3 } ]
> var array2 = [ { id: 2, blah: true }, { id: 3 } ]
undefined
> a.union(array1, array2)

@@ -392,3 +387,4 @@ [ { id: 1 },

@param columns {...string} - column names to sort by
@returns {array}
@param order {object} - specific sort orders, per columns
@returns {Array}
@example

@@ -420,6 +416,9 @@ > var fixture = [

var array = args.shift();
return array.sort(sortByFunc(args));
if (typeof args[args.length-1] === "object"){
var customOrder = args.pop();
}
return array.sort(sortByFunc(args, customOrder));
}
function sortByFunc(properties){
function sortByFunc(properties, customOrder){
var props = properties.slice(0);

@@ -438,4 +437,6 @@ var property = props.shift();

result = 0;
} else if (customOrder && customOrder[property]){
result = customOrder[property].indexOf(x) - customOrder[property].indexOf(y);
} else {
var result = x < y ? -1 : x > y ? 1 : 0;
result = x < y ? -1 : x > y ? 1 : 0;
}

@@ -442,0 +443,0 @@

{
"name": "array-tools",
"author": "Lloyd Brookes <75pound@gmail.com>",
"version": "1.4.5",
"version": "1.5.0",
"description": "Useful functions for working with arrays",

@@ -6,0 +6,0 @@ "repository": "https://github.com/75lb/array-tools.git",

@@ -54,7 +54,6 @@ [![view on npm](http://img.shields.io/npm/v/array-tools.svg)](https://www.npmjs.org/package/array-tools)

> var data = [
... {one: 1, two: 2},
... {two: "two"},
... {one: "one", two: "zwei"},
... ];
undefined
{one: 1, two: 2},
{two: "two"},
{one: "one", two: "zwei"},
];
> a.pluck(data, "one");

@@ -131,3 +130,2 @@ [ 1, 'one' ]

> function f(){ return a.arrayify(arguments); }
undefined
> f(1,2,3)

@@ -280,11 +278,8 @@ [ 1, 2, 3 ]

> var array1 = [ 1, 2 ], array2 = [ 2, 3 ];
undefined
> a.union(array1, array2)
[ 1, 2, 3 ]
> var array1 = [ { id: 1 }, { id: 2 } ], array2 = [ { id: 2 }, { id: 3 } ];
undefined
> a.union(array1, array2)
[ { id: 1 }, { id: 2 }, { id: 3 } ]
> var array2 = [ { id: 2, blah: true }, { id: 3 } ]
undefined
> a.union(array1, array2)

@@ -291,0 +286,0 @@ [ { id: 1 },

@@ -44,1 +44,9 @@ var test = require("tape");

});
test("custom order", function(t){
var fixture = [{ fruit: "apple" }, { fruit: "orange" }, { fruit: "banana" }, { fruit: "pear" }];
var expected = [{ fruit: "banana" }, { fruit: "pear" }, { fruit: "apple" }, { fruit: "orange" }];
var fruitOrder = [ "banana", "pear", "apple", "orange" ];
t.deepEqual(a.sortBy(fixture, "fruit", { fruit: fruitOrder }), expected);
t.end();
});
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