1.2.0 • Published 7 months ago
@withonevision/array-helper v1.2.0
Array Helper
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.
Methods
orderBy
Take in an array of keys and orders and re-order the entire array based on that input.
import { orderBy } from "@withonevision/array-helpers";
const array = [{ key1: "Hello" }, { key1: "Goodbye" }];
orderBy(array, ["key1"], ["asc"]);
// [{key1: "Goodbye"}, {key1: "Hello"}]
uniqBy
Return the unique values in an array based off of a key.
const array = [{ key1: "Hello" }, { key1: "Goodbye" }, { key1: "Hello" }];
uniqBy(array, "key1");
// [{key1: "Hello"}, {key1: "Goodbye"}]
For a full list of functions, see the jsr.io documentation