1.0.3 • Published 2 years ago

@lbagic/collections v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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.

FunctionParametersReturnsMutates
addsource, item, identifier?item[]
addsource, items, identifier?item[]
removesource, id, identifier?item[]
removesource, ids, identifier?item[]
removesource, itemitem[]
removesource, itemsitem[]
findOnesource, id, identifier?item | undefined
findOnesource, itemitem | undefined
findManysource, id, identifier?item[]
findManysource, ids, identifier?item[]
findManysource, itemitem[]
findManysource, itemsitem[]
1.0.4

1 year ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago