@lbagic/collections
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

Collections

Javascript collection helper methods.

Installation

npm i @lbagic/collections

Example usage

import { collection } from "@lbagic/collections";

const data = [
  { id: 1, type: "Odd" },
  { id: 2, type: "Odd" },
  { id: 3, type: "Odd" },
];

collection.add(data, [
  { id: 2, type: "Even" },
  { id: 4, type: "Even" },
]);
// @returns [
//   { id: 1, type: "Odd" },
//   { id: 2, type: "Even" },
//   { id: 3, type: "Odd" }
//   { id: 4, type: "Even" }
// ]

collection.remove(data, 4);
collection.remove(data, { id: 4 });
// @returns [
//   { id: 1, type: "Odd" },
//   { id: 2, type: "Even" },
//   { id: 3, type: "Odd" }
// ]

collection.findOne(data, 2);
collection.findOne(data, { id: 2 });
// @returns { id: 2, type: "Even" }

collection.findMany(data, "Odd", "type");
collection.findMany(data, { type: "Odd" });
// @returns [
//   { id: 1, type: "Odd" },
//   { id: 3, type: "Odd" }
// ]

Documentation

Source parameter expects array of objects.
Functions support curried first parameter.
Identifier defaults to id.

Function Parameters Returns Mutates
add source, item, identifier? item[]
add source, items, identifier? item[]
remove source, id, identifier? item[]
remove source, ids, identifier? item[]
remove source, item item[]
remove source, items item[]
findOne source, id, identifier? item | undefined
findOne source, item item | undefined
findMany source, id, identifier? item[]
findMany source, ids, identifier? item[]
findMany source, item item[]
findMany source, items item[]

Readme

Keywords

Package Sidebar

Install

npm i @lbagic/collections

Weekly Downloads

1

Version

1.0.3

License

ISC

Unpacked Size

11.5 kB

Total Files

5

Last publish

Collaborators

  • lbagic