Manager
A superset of the Map class called Manager that manages complex amounts of data.
Table of Contents
Installation
You can install Manager from npm
via npm i managerjs
or yarn add managerjs
. You can use Manager on the web via unpkg https://unpkg.com/managerjs@latest/lib/api.umd.js
or jsdelivr https://cdn.jsdelivr.net/npm/managerjs@latest/lib/api.umd.js
.
Once installed it can be used like this:
import { Manager } from "managerjs";
import { Manager } from "https://unpkg.com/managerjs@latest/lib/api.umd.js) `https://unpkg.com/managerjs@latest/lib/api.es.js";
import { Manager } from "https://unpkg.com/managerjs@latest/lib/api.umd.js) `https://unpkg.com/managerjs@latest/lib/api.modern.js";
<script src="https://unpkg.com/managerjs@latest/lib/api.umd.js"></script>
const { Manager } = window.managerjs;
Getting started
The Manager class makes Maps easier to use, as well as adding 6 methods, getMap, last, prev, methodCall, asyncMethodCall, add, keys and values (the behavior of the keys and values methods are slightly modified, to return an Array of keys/values instead of an iterator).
API
All the existing Map methods, and ...
Manager#getMap()
Manager.prototype.getMap();
const arr = Array.from([1, 2, 3, 4, 5].entries());
const manager = new Manager(arr);
console.log(manager.getMap());
Manager#add(value)
Manager.prototype.add(value: V);
const arr = Array.from([1, 2, 3, 4, 5].entries());
const manager = new Manager(arr);
manager.add(6).add(7);
console.log(manager.get(5));
Manager#keys()
Manager.prototype.keys();
const arr = Array.from([1, 2, 3, 4, 5].entries());
const manager = new Manager(arr);
console.log(manager.keys());
Manager#values()
Manager.prototype.values();
const arr = Array.from([1, 2, 3, 4, 5].entries());
const manager = new Manager(arr);
console.log(manager.values());
Manager#last(distance)
Manager.prototype.last(distance: number = 1);
const arr = Array.from([1, 2, 3, 4, 5].entries());
const manager = new Manager(arr);
console.log(manager.last());
console.log(manager.last(3));
Manager#prev()
Manager.prototype.prev();
const arr = Array.from([1, 2, 3, 4, 5].entries());
const manager = new Manager(arr);
console.log(manager.prev());
Manager#methodCall(method, ...)
Manager.prototype.methodCall(method: string, ...args: any);
const manager = new Manager();
manager.set("x", { print: console.log });
manager.set("y", { print: console.log });
manager.methodCall("print", Date.now());
Manager#asyncMethodCall(method, ...)
Manager.prototype.asyncMethodCall(method: string, ...args: any[]);
const manager = new Manager();
let fn = (url = "https://google.com") => {
return async () => {
let data = await fetch(url);
console.log(`(${data.url})`);
};
};
manager.set("x", { print: fn() });
manager.set("y", { print: fn("https://github.com") });
manager.asyncMethodCall("print");
Manager#@@iterator
const arr = Array.from([1, 2, 3, 4, 5].entries());
const manager = new Manager(arr);
for (let [key, value] of manager) {
console.log({ key, value });
}