This module inspired by abalabahaha
Instalation (with npm)
npm i gs-collection@latest
GS-Collection is remastered version of @discordjs/collection, so if pro at @discordjs/collection may be you can use GS-Collection too.
Apart from being a Collection, you can also use mixin
to mix two different objects, getTypeOf
to get the type of all objects, baseObjectBase` to convert a data.
DJSCollection
imported from @discordjs/collection.instantLazy
imported from aio-get-all-files.
const { Collection } = require("gs-collection");
const coll = new Collection({ entries: [ /* ["a", "value"], ["b", "value"] */ ], baseObject: LogicClass /* Can be a class or function */, keyIndex: id" /* Index to get property to be key of an entry & Must be a string */ });
coll.add({ id: "1" }); // output: { "id": "1" }
coll.add({ id: "2" }); // output: { "id": "2" }
coll.add({ id: "3" }); // output: { "id": "2" }
coll.update({ id: "3", role: "Member" }); // output: { "old": { "id": "3" }, "updated": { "id": "3", "role": "Member" } }
coll.remove({ id: "1" }); // output: { "id": "1" }