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.5.1 to 1.5.2

71

lib/array-tools.js

@@ -27,7 +27,8 @@ "use strict";

/**
/**
Plucks the value of the specified property from each object in the input array
@param arrayOfObjects {object[]} - the input array of objects
@param property {...string} - the property(s) to pluck
@returns {Array}
@returns {Array}
@category Record sets
@example

@@ -49,3 +50,3 @@ > var data = [

if (!Array.isArray(arrayOfObjects)) throw new Error(".pluck() input must be an array");
return arrayOfObjects

@@ -71,2 +72,3 @@ .filter(function(obj){

@return {object[]}
@category Record sets
@example

@@ -89,5 +91,5 @@ > data = [

var properties = args;
if (!Array.isArray(arrayOfObjects)) throw new Error(".pick() input must be an array");
return arrayOfObjects

@@ -117,3 +119,3 @@ .filter(function(obj){

@param input {*} - the input value to convert to an array
@param {*} - the input value to convert to an array
@returns {Array}

@@ -132,9 +134,9 @@ @example

*/
function arrayify(input){
if (input === null || input === undefined){
function arrayify(any){
if (any === null || any === undefined){
return [];
} else if (t.isPlainObject(input) && input.length >= 0 && input.length === Math.floor(input.length)){
return Array.prototype.slice.call(input);
} else if (t.isPlainObject(any) && any.length >= 0 && any.length === Math.floor(any.length)){
return Array.prototype.slice.call(any);
} else {
return Array.isArray(input) ? input : [ input ];
return Array.isArray(any) ? any : [ any ];
}

@@ -146,3 +148,3 @@ }

@param {Array} - the array to search
@param {*} - the value to search for
@param {*} - the value to search for
@returns {boolean}

@@ -177,7 +179,8 @@ @example

/**
returns an array containing items from `arrayOfObjects` where key/value pairs
returns an array containing items from `arrayOfObjects` where key/value pairs
from `query` are matched identically
@param {Array} - the array to search
@param {object[]} - the array to search
@param {query} - an object containing the key/value pairs you want to match
@returns {Array}
@category Record sets
@example

@@ -200,7 +203,8 @@ > dudes = [{ name: "Jim", age: 8}, { name: "Clive", age: 8}, { name: "Hater", age: 9}]

/**
returns the first item from `arrayOfObjects` where key/value pairs
returns the first item from `arrayOfObjects` where key/value pairs
from `query` are matched identically
@param {Array} - the array to search
@param {query} - an object containing the key/value pairs you want to match
@param {object[]} - the array to search
@param {object} - an object containing the key/value pairs you want to match
@returns {object}
@category Record sets
@example

@@ -233,5 +237,5 @@ > dudes = [{ name: "Jim", age: 8}, { name: "Clive", age: 8}, { name: "Hater", age: 9}]

*/
function without(input, toRemove){
function without(array, toRemove){
toRemove = arrayify(toRemove);
return input.filter(function(item){
return array.filter(function(item){
return !exists(toRemove, item);

@@ -303,3 +307,3 @@ });

/**
reduces an array to unique values
returns an array of unique values
@param {Array} - input array

@@ -324,3 +328,3 @@ @returns {Array}

@param {Array} - the input array
@param {number} - the position to begin splicing from
@param {number} - the position to begin splicing from
@param {RegExp} - the test to continue splicing while true

@@ -396,6 +400,8 @@ @param ...elementN {*} - the elements to add to the array

@static
@param arrayOfObject {array} - input array
@param columns {...string} - column names to sort by
@param order {object} - specific sort orders, per columns
@param {object[]} - input array
@param {string|string[]} - column name(s) to sort by
@param {object} - specific sort orders, per columns
@returns {Array}
@category Record sets
@since 1.5.0
@example

@@ -411,5 +417,5 @@ > var fixture = [

{ a: 3, b: 3, c: 3},
{ a: 4, b: 3, c: 1}
{ a: 4, b: 3, c: 1}
];
> a.sortBy(fixture, "a", "b", "c")
> a.sortBy(fixture, ["a", "b", "c"])
[ { a: 1, b: 1, c: 4 },

@@ -425,9 +431,4 @@ { a: 1, b: 2, c: 4 },

*/
function sortBy(){
var args = arrayify(arguments);
var array = args.shift();
if (typeof args[args.length-1] === "object"){
var customOrder = args.pop();
}
return array.sort(sortByFunc(args, customOrder));
function sortBy(arrayOfObjects, columns, customOrder){
return arrayOfObjects.sort(sortByFunc(arrayify(columns), customOrder));
}

@@ -442,3 +443,3 @@

var y = b[property];
if (typeof x === "undefined" && typeof y !== "undefined"){

@@ -455,3 +456,3 @@ result = -1;

}
if (result === 0){

@@ -458,0 +459,0 @@ if (props.length){

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

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

var test = require("tape");
var a = require("../");
return;
test("groupBy", function(t){

@@ -5,0 +6,0 @@ var fixture = [

@@ -27,3 +27,3 @@ var test = require("tape");

];
t.deepEqual(a.sortBy(fixture, "a", "b", "c"), expected);
t.deepEqual(a.sortBy(fixture, ["a", "b", "c"]), expected);
t.end();

@@ -30,0 +30,0 @@ });

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