@deebeetech/array-helper
v2.0.0
Published
A small collection of extra methods for arrays that we mostly needed from LoDash and Underscore that we didn't want to carry the weight of those installs.
Maintainers
Readme
Array Helper
Lightweight standalone array utility functions — the parts of LoDash and Underscore you actually need, without the weight.
Install
npm install @deebeetech/array-helperFunctions
orderBy
Sort an array by multiple keys and directions, returning a new array without
mutating the original. Compares numbers numerically and everything else via
localeCompare.
import { orderBy } from "@deebeetech/array-helper";
const users = [
{ name: "John", age: 25 },
{ name: "Jane", age: 30 },
{ name: "John", age: 30 },
];
orderBy(users, ["name", "age"], ["asc", "desc"]);
// [{ name: "Jane", age: 30 }, { name: "John", age: 30 }, { name: "John", age: 25 }]uniqBy
Return the unique values in an array, optionally deduplicated by a specific key.
When called without a key, uses Set semantics (identity/value equality).
import { uniqBy } from "@deebeetech/array-helper";
const users = [
{ name: "John", age: 25 },
{ name: "Jane", age: 30 },
{ name: "John", age: 30 },
];
uniqBy(users, "name");
// [{ name: "John", age: 25 }, { name: "Jane", age: 30 }]
uniqBy([1, 2, 3, 2, 1]);
// [1, 2, 3]