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:
;;// Or; // Via script tag<script src="https://unpkg.com/managerjs@latest/lib/api.umd.js"></script>// Do note, on the web you need to do this, if you installed it via the script tag:const Manager = windowmanagerjs;
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()
Managerprototype; /** * Returns the Manager class's Map * * @returns Map<K, V> * @memberof Manager */ // Example:const arr = Array;const manager = arr;console; //= Map(5) { 0 => 1, 1 => 2, 2 => 3, 3 => 4, 4 => 5 }
Manager#add(value)
Managerprototype; /** * Adds a value to Manager, and uses the current size of the Manager as it's key, it works best when all the key in the Manager are numbers * * @param * @returns Manager<K, V> */ // Example:const arr = Array;const manager = arr;manager;console; //= 6
Manager#keys()
Managerprototype; /** * Returns the keys of all items stored in the Manager as an Array * * @returns Array<K> * @memberof Manager */ // Example:const arr = Array;const manager = arr;console; //= [0, 1, 2, 3, 4]
Manager#values()
Managerprototype; /** * Returns the values of all items stored in the Manager as an Array * * @returns Array<V> * @memberof Manager */ // Example:const arr = Array;const manager = arr;console; //= [1, 2, 3, 4, 5]
Manager#last(distance)
Managerprototype; /** * Returns the last item in the Manager who's index is a certain distance from the last item in the Manager * * @param * @returns V * @memberof Manager */ // Example:const arr = Array;const manager = arr;console; //= 5console; //= 3
Manager#prev()
Managerprototype; /** * Returns the second last item in the Manager * * @public * @returns V */ // Example:const arr = Array;const manager = arr;console; //= 4
Manager#methodCall(method, ...)
Managerprototype; /** * Calls a method for all items that are currently in it's list * * @param * @param * @returns Manager<K, V> * @memberof Manager */ // Example:const manager = ;manager;manager;manager;
Manager#asyncMethodCall(method, ...)
Managerprototype; /** * Asynchronously calls a method for all items that are currently in it's map, similar to methodCall except the loop waits for the asynchronous method to run, before the loop continues on to the the next method * * @param * @param * @returns Promise<Manager<K, V>> * @memberof Manager */ // Example:const manager = ;let { return async { let data = await ; console; };}; manager;manager;manager; //= (https://www.google.com/), (https://github.com/)
Manager#@@iterator
/** * Allows iteration via the for..of, learn more: [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators] * * @returns IterableIterator<[K, V]> * @memberof Manager */ // Example:const arr = Array;const manager = arr;for let key value of manager console; //= { key: ..., value: ... }