@okikio/manager
Advanced tools
Comparing version 0.0.7 to 1.0.0
@@ -1,2 +0,2 @@ | ||
var Manager=function(d){"use strict";class e{constructor(a){this.map=new Map(a)}getMap(){return this.map}get(a){return this.map.get(a)}keys(){return Array.from(this.map.keys())}values(){return Array.from(this.map.values())}set(a,b){return this.map.set(a,b),this}add(a){let b=this.size,c=b;return this.set(c,a),this}get size(){return this.map.size}last(a=1){let b=this.keys()[this.size-a];return this.get(b)}prev(){return this.last(2)}delete(a){return this.map.delete(a),this}clear(){return this.map.clear(),this}has(a){return this.map.has(a)}entries(){return this.map.entries()}forEach(a=(...c)=>{},b){return this.map.forEach(a,b),this}[Symbol.iterator](){return this.entries()}methodCall(a,...b){return this.forEach(c=>{c[a](...b)}),this}async asyncMethodCall(a,...b){for(let[,c]of this.map)await c[a](...b);return this}}return d.Manager=e,d.default=e,d}({}); | ||
var manager=(()=>{var s=Object.defineProperty,p=r=>s(r,"__esModule",{value:!0}),h=(r,e)=>{p(r);for(var t in e)s(r,t,{get:e[t],enumerable:!0})},o={};h(o,{Manager:()=>i,asyncMethodCall:()=>u,default:()=>l,methodCall:()=>n});var i=class{constructor(e){this.map=new Map(e)}getMap(){return this.map}get(e){return this.map.get(e)}keys(){return Array.from(this.map.keys())}values(){return Array.from(this.map.values())}set(e,t){return this.map.set(e,t),this}add(e){let t=this.size,a=t;return this.set(a,e),this}get size(){return this.map.size}get length(){return this.map.size}last(e=1){let t=this.keys()[this.size-e];return this.get(t)}delete(e){return this.map.delete(e)}remove(e){return this.map.delete(e),this}clear(){return this.map.clear(),this}has(e){return this.map.has(e)}entries(){return this.map.entries()}forEach(e=(...a)=>{},t){return this.map.forEach(e,t),this}[Symbol.iterator](){return this.entries()}},n=(r,e,...t)=>{r.forEach(a=>{a[e](...t)})},u=async(r,e,...t)=>{for(let[,a]of r)await a[e](...t)},l=i;return o;})(); | ||
//# sourceMappingURL=api.js.map |
{ | ||
"name": "@okikio/manager", | ||
"version": "0.0.7", | ||
"description": "A superset of the Map class called Manager that allows for complex management of data.", | ||
"version": "1.0.0", | ||
"description": "A superset of the Map class, it gives the Map class superpowers.", | ||
"publishConfig": { | ||
"access": "public", | ||
"main": "lib/api.js", | ||
"types": "lib/api.d.ts", | ||
"umd:main": "lib/api.umd.js", | ||
"browser": "lib/api.umd.js", | ||
"unpkg": "lib/api.umd.js", | ||
"module": "lib/api.mjs" | ||
"types": "lib/types/api.d.ts", | ||
"browser": "lib/api.js", | ||
"node": "lib/api.node.js", | ||
"unpkg": "lib/api.js", | ||
"module": "lib/api.modern.js", | ||
"exports": "lib/api.modern.js" | ||
}, | ||
"umd:name": "Manager", | ||
"main": "lib/api.js", | ||
"source": "src/api.ts", | ||
"output": [ | ||
{ | ||
"file": "lib/api.mjs", | ||
"format": "es" | ||
}, | ||
{ | ||
"file": "lib/api.umd.js", | ||
"format": "umd" | ||
}, | ||
{ | ||
"file": "lib/api.js", | ||
"format": "iife" | ||
} | ||
], | ||
"directories": { | ||
"lib": "lib" | ||
}, | ||
"files": [ | ||
"lib", | ||
"src" | ||
"src", | ||
"demo", | ||
"assets" | ||
], | ||
"scripts": { | ||
"build": "rollup --config", | ||
"watch": "rollup --config --watch", | ||
"test": "jest --maxWorkers=3 --coverage", | ||
"build": "node ./build", | ||
"watch": "node ./build --watch", | ||
"test": "jest --maxWorkers=1", | ||
"test:watch": "jest --maxWorkers=1 --watch --verbose false", | ||
"pre-release": "ultra build && ultra test" | ||
"dts": "tsc --project dts.tsconfig.json", | ||
"pre-release": "npm run build && npm test && npm run dts" | ||
}, | ||
@@ -48,8 +40,7 @@ "repository": { | ||
"manager", | ||
"js", | ||
"ts", | ||
"map", | ||
"library", | ||
"web", | ||
"api", | ||
"data" | ||
"api" | ||
], | ||
@@ -65,26 +56,26 @@ "author": { | ||
}, | ||
"homepage": "https://github.com/okikio/native#readme", | ||
"homepage": "https://github.com/okikio/native/packages/manager#readme", | ||
"dependencies": { | ||
"esbuild": "^0.8.26", | ||
"gzip-size": "^6.0.0", | ||
"pretty-bytes": "^5.5.0", | ||
"typescript": "^4.1.3" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-node-resolve": "^8.1.0", | ||
"@types/jest": "^26.0.3", | ||
"eslint": "^7.3.1", | ||
"jest": "^26.1.0", | ||
"@types/jest": "^26.0.19", | ||
"chokidar": "^3.4.3", | ||
"esbuild-jest": "^0.3.0", | ||
"eslint": "^7.16.0", | ||
"jest": "^26.6.3", | ||
"jest-chain": "^1.1.5", | ||
"jest-environment-jsdom-global": "^2.0.4", | ||
"jest-watch-lerna-packages": "^1.1.0", | ||
"node-fetch": "^2.6.0", | ||
"rollup": "^2.18.1", | ||
"rollup-plugin-esbuild": "^2.1.0", | ||
"rollup-plugin-typescript2": "^0.27.1", | ||
"ts-jest": "^26.1.1", | ||
"tslib": "^2.0.0", | ||
"typescript": "^3.9.5", | ||
"ultra": "^0.7.2" | ||
"node-fetch": "^2.6.1", | ||
"standard-changelog": "^2.0.27", | ||
"ultra-runner": "^3.8.0" | ||
}, | ||
"gitHead": "ad422076cdb57d570426f786886129d5bca2f90f", | ||
"types": "lib/api.d.ts", | ||
"umd:main": "lib/api.umd.js", | ||
"browser": "lib/api.umd.js", | ||
"unpkg": "lib/api.umd.js", | ||
"module": "lib/api.mjs" | ||
"types": "lib/types/api.d.ts", | ||
"browser": "lib/api.js", | ||
"unpkg": "lib/api.js", | ||
"module": "lib/api.modern.js", | ||
"exports": "lib/api.modern.js" | ||
} |
219
README.md
@@ -1,7 +0,26 @@ | ||
# Manager | ||
# @okikio/manager | ||
A superset of the Map class called Manager that manages complex amounts of data. | ||
A superset of the Map class, it gives Map superpowers, it weighs less than 450 B (minified and compressed). | ||
*You will need a Map polyfill for older browsers. If you install `@okikio/manager` via `npm` you are most likely going to need [rollup](https://rollupjs.org/) or [esbuild](https://esbuild.github.io/). You can use [polyfill.io](https://polyfill.io/), or another source to create a polyfill. The minimum feature requirement for a polyfill are Maps e.g. [https://polyfill.io/v3/polyfill.min.js?features=Maps](https://polyfill.io/v3/polyfill.min.js?features=Maps).* | ||
You can play with `@okikio/manager` using Gitpod: | ||
[![Edit with Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/okikio/native) | ||
_Start the dev script by typing into the terminal_ | ||
```bash | ||
ultra pnpm test:watch --filter *manager | ||
``` | ||
Once Gitpod has booted up, go to the `./packages/manager/test folder` and start tweaking and testing to your hearts content. | ||
## Table of Contents | ||
- [Manager](#manager) | ||
- [@okikio/manager](#okikiomanager) | ||
- [Table of Contents](#table-of-contents) | ||
@@ -11,44 +30,91 @@ - [Installation](#installation) | ||
- [API](#api) | ||
- [Manager#getMap()](#managergetmap) | ||
- [Manager#add(value)](#manageraddvalue) | ||
- [Manager#keys()](#managerkeys) | ||
- [Manager#values()](#managervalues) | ||
- [Manager#last(distance)](#managerlastdistance) | ||
- [Manager#prev()](#managerprev) | ||
- [Manager#methodCall(method, ...)](#managermethodcallmethod-) | ||
- [Manager#asyncMethodCall(method, ...)](#managerasyncmethodcallmethod-) | ||
- [Manager#@@iterator](#manageriterator) | ||
- [Existing Map Methods](#existing-map-methods) | ||
- [Manager#length](#managerlength) | ||
- [Manager#getMap()](#managergetmap) | ||
- [Manager#add(value)](#manageraddvalue) | ||
- [Manager#remove(key)](#managerremovekey) | ||
- [Manager#keys()](#managerkeys) | ||
- [Manager#values()](#managervalues) | ||
- [Manager#last(distance)](#managerlastdistance) | ||
- [Manager#@@iterator](#manageriterator) | ||
- [#methodCall(method, ...)](#methodcallmethod-) | ||
- [#asyncMethodCall(method, ...)](#asyncmethodcallmethod-) | ||
- [Contributing](#contributing) | ||
- [Licence](#licence) | ||
## 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) `https://unpkg.com/managerjs@latest/lib/api.umd.js` or [jsdelivr](https://cdn.jsdelivr.net/npm/managerjs@latest/lib/api.umd.js) `https://cdn.jsdelivr.net/npm/managerjs@latest/lib/api.umd.js`. | ||
You can install `@okikio/manager` from `npm` via `npm i @okikio/manager` or `yarn add @okikio/manager`. You can use `@okikio/manager` on the web via: | ||
* [https://unpkg.com/@okikio/manager@latest/lib/api.modern.js](https://unpkg.com/@okikio/manager@latest/lib/api.modern.js), | ||
* [https://cdn.skypack.dev/@okikio/manager](https://cdn.skypack.dev/@okikio/manager) or | ||
* [https://cdn.jsdelivr.net/npm/@okikio/manager@latest/lib/api.modern.js](https://cdn.jsdelivr.net/npm/@okikio/manager@latest/lib/api.modern.js). | ||
Once installed it can be used like this: | ||
```javascript | ||
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 "@okikio/manager"; | ||
import { Manager } from "https://unpkg.com/@okikio/manager@latest/lib/api.modern.js"; | ||
import { Manager } from "https://cdn.jsdelivr.net/npm/@okikio/manager@latest/lib/api.modern.js"; | ||
// Or | ||
import { Manager } from "https://unpkg.com/managerjs@latest/lib/api.umd.js) `https://unpkg.com/managerjs@latest/lib/api.modern.js"; | ||
import { Manager } from "https://cdn.skypack.dev/@okikio/manager"; | ||
// Via script tag | ||
<script src="https://unpkg.com/managerjs@latest/lib/api.umd.js"></script> | ||
<script src="https://unpkg.com/@okikio/manager@latest/lib/api.js"></script> | ||
// Do note, on the web you need to do this, if you installed it via the script tag: | ||
const { Manager } = window.managerjs; | ||
const { Manager, methodCall } = window.manager; | ||
// or | ||
const { default: Manager, methodCall } = window.manager; | ||
``` | ||
## 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). | ||
The `Manager` class makes Maps easier to use, as well as adding 7 methods, **getMap**, **last**, **methodCall**, **asyncMethodCall**, **add**, **remove**, **keys** and **values**, (**methodCall**, and **asyncMethodCall** are seperate methods from the `Manager` class, so treeshaking can get rid of them if they aren't need). | ||
*Note: the behavior of the keys and values methods are slightly modified, to return an Array of keys/values instead of an iterator. You can get the keys and values original effects by using ...getMap().keys() or ...getMap().values().* | ||
## API | ||
All the existing Map methods, and ... | ||
### Existing Map Methods | ||
* Manager.prototype.get(key: K): V | ||
* Returns a specified element from a Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map object. | ||
* Manager.prototype.set(value: V): Manager | ||
* Adds or updates an element with a specified key and a value to a Map object. | ||
* Returns the Manager class (it is chainable). | ||
* *Note: techincally the values being returned are different from a normal Map. The Map set() method returns the Map class while the Manager set() method return the Manager class, this shouldn't leave much of an effect on use, but should be kept in mind.* | ||
* Manager.prototype.size: number | ||
* Returns the number of elements in a Map object. | ||
* Manager.prototype.delete(key: K): boolean | ||
* Removes the specified element from a Map object by key. Returns true if an element in the Map object existed and has been removed, or false if the element does not exist. | ||
* Manager.prototype.entries(): [[K, V], ...] | ||
* Returns a new Iterator object that contains the [key, value] pairs for each element in the Map object in insertion order. | ||
* Manager.prototype.has(): boolean | ||
* Returns a boolean indicating whether an element with the specified key exists or not, true if an element with the specified key exists in the Map object; otherwise false. | ||
* Manager.prototype.forEach(callback: Function,context?: object): Manager | ||
* Executes a provided function once per each key/value pair in the Map object, in insertion order. | ||
* Returns the Manager class (it is chainable). | ||
#### Manager#getMap() | ||
### Manager#length | ||
```js | ||
Manager.prototype.length | ||
/** | ||
* Returns the total number of items stored in the Manager, an alias to Manger.prototype.size | ||
* | ||
* @public | ||
* @returns Number | ||
*/ | ||
// Example: | ||
import Manager from "@okikio/manager"; | ||
const arr = Array.from([1, 2, 3, 4, 5].entries()); | ||
const manager = new Manager(arr); | ||
console.log(manager.length); //= 5 | ||
``` | ||
### Manager#getMap() | ||
```js | ||
Manager.prototype.getMap(); | ||
/** | ||
* Returns the Manager class's Map | ||
* Returns the Manager class as a Map | ||
* | ||
@@ -60,2 +126,4 @@ * @returns Map<K, V> | ||
// Example: | ||
import Manager from "@okikio/manager"; | ||
const arr = Array.from([1, 2, 3, 4, 5].entries()); | ||
@@ -66,3 +134,3 @@ const manager = new Manager(arr); | ||
#### Manager#add(value) | ||
### Manager#add(value) | ||
```js | ||
@@ -72,3 +140,3 @@ Manager.prototype.add(value: V); | ||
/** | ||
* 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 | ||
* Adds a value to Manager, and uses the current size of the Manager as it's key, it works best when all the keys in the Manager are numbers | ||
* | ||
@@ -80,2 +148,4 @@ * @param {V} value | ||
// Example: | ||
import Manager from "@okikio/manager"; | ||
const arr = Array.from([1, 2, 3, 4, 5].entries()); | ||
@@ -87,4 +157,25 @@ const manager = new Manager(arr); | ||
### Manager#remove(key) | ||
```js | ||
Manager.prototype.remove(key: K); | ||
#### Manager#keys() | ||
/** | ||
* Removes a value stored in the Manager, via the key, returns the Manager class, allowing for chains | ||
* Similar to `Manager.prototype.delete`, except it is chainable, and returns the Manager class. | ||
* | ||
* @public | ||
* @param {K} key - The key for the key value pair to be removed | ||
* @returns Manager<K, V> | ||
*/ | ||
// Example: | ||
import Manager from "@okikio/manager"; | ||
const arr = Array.from([1, 2, 3, 4, 5].entries()); | ||
const manager = new Manager(arr); | ||
manager.remove(2).remove(1); | ||
console.log(manager.get(1)); //= undefined | ||
``` | ||
### Manager#keys() | ||
```js | ||
@@ -101,2 +192,4 @@ Manager.prototype.keys(); | ||
// Example: | ||
import Manager from "@okikio/manager"; | ||
const arr = Array.from([1, 2, 3, 4, 5].entries()); | ||
@@ -107,4 +200,3 @@ const manager = new Manager(arr); | ||
#### Manager#values() | ||
### Manager#values() | ||
```js | ||
@@ -121,2 +213,4 @@ Manager.prototype.values(); | ||
// Example: | ||
import Manager from "@okikio/manager"; | ||
const arr = Array.from([1, 2, 3, 4, 5].entries()); | ||
@@ -127,4 +221,3 @@ const manager = new Manager(arr); | ||
#### Manager#last(distance) | ||
### Manager#last(distance) | ||
```js | ||
@@ -142,2 +235,4 @@ Manager.prototype.last(distance: number = 1); | ||
// Example: | ||
import Manager from "@okikio/manager"; | ||
const arr = Array.from([1, 2, 3, 4, 5].entries()); | ||
@@ -149,55 +244,57 @@ const manager = new Manager(arr); | ||
#### Manager#prev() | ||
### Manager#@@iterator | ||
```js | ||
Manager.prototype.prev(); | ||
/** | ||
* Returns the second last item in the Manager | ||
* Allows iteration via the for..of, learn more: [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators] | ||
* | ||
* @public | ||
* @returns V | ||
* @returns IterableIterator<[K, V]> | ||
* @memberof Manager | ||
*/ | ||
// Example: | ||
import Manager from "@okikio/manager"; | ||
const arr = Array.from([1, 2, 3, 4, 5].entries()); | ||
const manager = new Manager(arr); | ||
console.log(manager.prev()); //= 4 | ||
for (let [key, value] of manager) { | ||
console.log({ key, value }); //= { key: ..., value: ... } | ||
} | ||
``` | ||
#### Manager#methodCall(method, ...) | ||
### #methodCall(method, ...) | ||
```js | ||
Manager.prototype.methodCall(method: string, ...args: any); | ||
methodCall(method: string, ...args: any); | ||
/** | ||
* Calls a method for all items that are currently in it's list | ||
* Calls the method of a certain name for all items that are currently installed | ||
* | ||
* @param {Manager<any, any>} manager | ||
* @param {string} method | ||
* @param {Array<any>} [args=[]] | ||
* @returns Manager<K, V> | ||
* @memberof Manager | ||
*/ | ||
// Example: | ||
import { Manager, methodCall } from "@okikio/manager"; | ||
const manager = new Manager(); | ||
manager.set("x", { print: console.log }); | ||
manager.set("y", { print: console.log }); | ||
manager.methodCall("print", Date.now()); | ||
methodCall(manager, "print", Date.now()); // Eg. 1598772789150, 1598772801639 | ||
``` | ||
#### Manager#asyncMethodCall(method, ...) | ||
### #asyncMethodCall(method, ...) | ||
```js | ||
Manager.prototype.asyncMethodCall(method: string, ...args: any[]); | ||
asyncMethodCall(method: string, ...args: any[]); | ||
/** | ||
* 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 | ||
* Asynchronously calls the method of a certain name for all items that are currently installed, similar to methodCall | ||
* | ||
* @param {Manager<any, any>} manager | ||
* @param {string} method | ||
* @param {Array<any>} [args=[]] | ||
* @returns Promise<Manager<K, V>> | ||
* @memberof Manager | ||
*/ | ||
// Example: | ||
import { Manager, asyncMethodCall } from "@okikio/manager"; | ||
const manager = new Manager(); | ||
@@ -213,21 +310,11 @@ let fn = (url = "https://google.com") => { | ||
manager.set("y", { print: fn("https://github.com") }); | ||
manager.asyncMethodCall("print"); //= (https://www.google.com/), (https://github.com/) | ||
asyncMethodCall(manager, "print"); //= (https://www.google.com/), (https://github.com/) | ||
``` | ||
#### Manager#@@iterator | ||
```js | ||
/** | ||
* 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 | ||
*/ | ||
## Contributing | ||
If there is something I missed, a mistake, or a feature you would like added please create an issue or a pull request and I'll try to get to it. | ||
// Example: | ||
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 }); //= { key: ..., value: ... } | ||
} | ||
``` | ||
*The `native` project uses [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) as the style of commit, we even use the [Commitizen CLI](http://commitizen.github.io/cz-cli/) to make commits easier.* | ||
## Licence | ||
See the [LICENSE](./LICENSE) file for license rights and limitations (MIT). |
201
src/api.ts
@@ -1,25 +0,5 @@ | ||
/** | ||
* Manages complex lists of named data, eg. A page can be stored in a list by of other pages with the url being how the page is stored in the list. Managers use Maps to store data. | ||
* | ||
* @export | ||
* @class Manager | ||
* @template K | ||
* @template V | ||
*/ | ||
/** Manages complex lists of named data, eg. A page can be stored in a list by of other pages with the url being how the page is stored in the list. Managers use Maps to store data */ | ||
export class Manager<K, V> { | ||
/** | ||
* The complex list of named data, to which the Manager controls | ||
* | ||
* @protected | ||
* @type Map<K, V> | ||
* @memberof Manager | ||
*/ | ||
protected map: Map<K, V>; | ||
/** | ||
* Creates an instance of Manager. | ||
* | ||
* @param {Array<[K, V]>} [value] | ||
* @memberof Manager | ||
*/ | ||
/** The complex list of named data, to which the Manager controls */ | ||
public map: Map<K, V>; | ||
constructor(value?: Array<[K, V]>) { | ||
@@ -29,8 +9,3 @@ this.map = new Map(value); | ||
/** | ||
* Returns the Manager class's list | ||
* | ||
* @returns Map<K, V> | ||
* @memberof Manager | ||
*/ | ||
/** Returns the Manager classes base Map */ | ||
public getMap(): Map<K, V> { | ||
@@ -40,9 +15,3 @@ return this.map; | ||
/** | ||
* Get a value stored in the Manager | ||
* | ||
* @public | ||
* @param {K} key - The key to find in the Manager's list | ||
* @returns V | ||
*/ | ||
/** Get a value stored in the Manager */ | ||
public get(key: K): V { | ||
@@ -52,8 +21,3 @@ return this.map.get(key); | ||
/** | ||
* Returns the keys of all items stored in the Manager as an Array | ||
* | ||
* @returns Array<K> | ||
* @memberof Manager | ||
*/ | ||
/** Returns the keys of all items stored in the Manager as an Array */ | ||
public keys(): Array<K> { | ||
@@ -63,8 +27,3 @@ return Array.from(this.map.keys()); | ||
/** | ||
* Returns the values of all items stored in the Manager as an Array | ||
* | ||
* @returns Array<V> | ||
* @memberof Manager | ||
*/ | ||
/** Returns the values of all items stored in the Manager as an Array */ | ||
public values(): Array<V> { | ||
@@ -74,10 +33,3 @@ return Array.from(this.map.values()); | ||
/** | ||
* Set a value stored in the Manager | ||
* | ||
* @public | ||
* @param {K} key - The key where the value will be stored | ||
* @param {V} value - The value to store | ||
* @returns Manager<K, V> | ||
*/ | ||
/** Set a value to the Manager using a key */ | ||
public set(key: K, value: V): Manager<K, V> { | ||
@@ -88,9 +40,3 @@ this.map.set(key, value); | ||
/** | ||
* 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 | ||
* | ||
* @public | ||
* @param {V} value | ||
* @returns Manager<K, V> | ||
*/ | ||
/** 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 */ | ||
public add(value: V): Manager<K, V> { | ||
@@ -104,8 +50,3 @@ let size = this.size; | ||
/** | ||
* Returns the total number of items stored in the Manager | ||
* | ||
* @public | ||
* @returns Number | ||
*/ | ||
/** Returns the total number of items stored in the Manager */ | ||
public get size(): number { | ||
@@ -115,9 +56,8 @@ return this.map.size; | ||
/** | ||
* Returns the last item in the Manager who's index is a certain distance from the last item in the Manager | ||
* | ||
* @param {number} [distance=1] | ||
* @returns V | undefined | ||
* @memberof Manager | ||
*/ | ||
/** An alias for size */ | ||
public get length(): number { | ||
return this.map.size; | ||
} | ||
/** Returns the last item in the Manager who's index is a certain distance from the last item in the Manager */ | ||
public last(distance: number = 1): V | undefined { | ||
@@ -128,20 +68,9 @@ let key = this.keys()[this.size - distance]; | ||
/** | ||
* Returns the second last item in the Manager | ||
* | ||
* @public | ||
* @returns V | ||
*/ | ||
public prev(): V { | ||
return this.last(2); | ||
/** Removes a value stored in the Manager via a key, returns true if an element in the Map object existed and has been removed, or false if the element does not exist */ | ||
public delete(key: K): boolean { | ||
return this.map.delete(key); | ||
} | ||
/** | ||
* Removes a value stored in the Manager, via the key | ||
* | ||
* @public | ||
* @param {K} key - The key for the key value pair to be removed | ||
* @returns Manager<K, V> | ||
*/ | ||
public delete(key: K): Manager<K, V> { | ||
/** Removes a value stored in the Manager via a key, returns the Manager class, allowing for chains */ | ||
public remove(key: K): Manager<K, V> { | ||
this.map.delete(key); | ||
@@ -151,8 +80,3 @@ return this; | ||
/** | ||
* Clear the Manager of all its contents | ||
* | ||
* @public | ||
* @returns Manager<K, V> | ||
*/ | ||
/** Clear the Manager of all its contents */ | ||
public clear(): Manager<K, V> { | ||
@@ -163,9 +87,3 @@ this.map.clear(); | ||
/** | ||
* Checks if the Manager contains a certain key | ||
* | ||
* @public | ||
* @param {K} key | ||
* @returns boolean | ||
*/ | ||
/** Checks if the Manager contains a certain key */ | ||
public has(key: K): boolean { | ||
@@ -175,8 +93,3 @@ return this.map.has(key); | ||
/** | ||
* Returns a new Iterator object that contains an array of [key, value] for each element in the Map object in insertion order. | ||
* | ||
* @public | ||
* @returns IterableIterator<[K, V]> | ||
*/ | ||
/** Returns a new Iterator object that contains an array of [key, value] for each element in the Map object in insertion order. */ | ||
public entries(): IterableIterator<[K, V]> { | ||
@@ -186,10 +99,3 @@ return this.map.entries(); | ||
/** | ||
* Iterates through the Managers contents, calling a callback function every iteration | ||
* | ||
* @param {*} [callback=(...args: any): void => { }] | ||
* @param {object} context | ||
* @returns Manager<K, V> | ||
* @memberof Manager | ||
*/ | ||
/** Iterates through the Managers contents, calling a callback function every iteration */ | ||
public forEach( | ||
@@ -203,45 +109,28 @@ callback: any = (...args: any): void => { }, | ||
/** | ||
* 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 | ||
*/ | ||
/** Allows for iteration via for..of, learn more: [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators] */ | ||
public [Symbol.iterator](): IterableIterator<[K, V]> { | ||
return this.entries(); | ||
} | ||
} | ||
/** | ||
* Calls the method of a certain name for all items that are currently installed | ||
* | ||
* @param {string} method | ||
* @param {Array<any>} [args=[]] | ||
* @returns Manager<K, V> | ||
* @memberof Manager | ||
*/ | ||
public methodCall(method: string, ...args: any): Manager<K, V> { | ||
this.forEach((item: V) => { | ||
// @ts-ignore | ||
item[method](...args); | ||
}); | ||
return this; | ||
} | ||
/** | ||
* Calls the method of a certain name for all items that are currently installed | ||
*/ | ||
export const methodCall = (manager: Manager<any, any>, method: string, ...args: any): void => { | ||
manager.forEach((item) => { | ||
// @ts-ignore | ||
item[method](...args); | ||
}); | ||
}; | ||
/** | ||
* Asynchronously calls the method of a certain name for all items that are currently installed, similar to methodCall | ||
* | ||
* @param {string} method | ||
* @param {Array<any>} [args=[]] | ||
* @returns Promise<Manager<K, V>> | ||
* @memberof Manager | ||
*/ | ||
public async asyncMethodCall(method: string, ...args: any): Promise<Manager<K, V>> { | ||
for (let [, item] of this.map) { | ||
// @ts-ignore | ||
await item[method](...args); | ||
} | ||
return this; | ||
/** | ||
* Asynchronously calls the method of a certain name for all items that are currently installed, similar to methodCall | ||
*/ | ||
export const asyncMethodCall = async (manager: Manager<any, any>, method: string, ...args: any): Promise<void> => { | ||
for (let [, item] of manager) { | ||
// @ts-ignore | ||
await item[method](...args); | ||
} | ||
} | ||
}; | ||
export default Manager; | ||
export default Manager; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
9
308
39245
4
118
1
+ Addedesbuild@^0.8.26
+ Addedgzip-size@^6.0.0
+ Addedpretty-bytes@^5.5.0
+ Addedtypescript@^4.1.3
+ Addedduplexer@0.1.2(transitive)
+ Addedesbuild@0.8.57(transitive)
+ Addedgzip-size@6.0.0(transitive)
+ Addedpretty-bytes@5.6.0(transitive)
+ Addedtypescript@4.9.5(transitive)