Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/okikio/native. An initiative which aims to make it easy to create complex, light-weight, and perfor okikio.github.io/native
Something went wrong. Try again.
1{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Acts as an enhanced version of the Map class with new features and changed behavior for convenience\n *\n * @typeParam K - the type of keys to store use to store values\n * @typeParam V - the type of values to store\n * */\nexport class Manager<K, V> {\n\t/** For backward compatability and performance reasons Manager use Map to store data */\n\tprotected map: Map<K, V>;\n\tconstructor(value?: Array<[K, V]>) {\n\t\tthis.map = new Map(value);\n\t}\n\n\t/** Returns the Manager classes base Map */\n\tpublic getMap(): Map<K, V> {\n\t\treturn this.map;\n\t}\n\n\t/** Get a value stored in the Manager */\n\tpublic get(key: K): V | undefined {\n\t\treturn this.map.get(key);\n\t}\n\n\t/** Returns the keys of all items stored in the Manager as an Array */\n\tpublic keys(): Array<K> {\n\t\treturn Array.from(this.map.keys());\n\t}\n\n\t/** Returns the values of all items stored in the Manager as an Array */\n\tpublic values(): Array<V> {\n\t\treturn Array.from(this.map.values());\n\t}\n\n\t/** Set a value to the Manager using a key */\n\tpublic set(key: K, value: V): Manager<K, V> {\n\t\tthis.map.set(key, value);\n\t\treturn this;\n\t}\n\n\t/** 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 */\n\tpublic add(value: V): Manager<K, V> {\n\t\tconst size = this.size;\n\t\tconst num = size as K;\n\t\tthis.set(num, value);\n\t\treturn this;\n\t}\n\n\t/** Returns the total number of items stored in the Manager */\n\tpublic get size(): number {\n\t\treturn this.map.size;\n\t}\n\n\t/** An alias for size */\n\tpublic get length(): number {\n\t\treturn this.map.size;\n\t}\n\n\t/** Returns the last item in the Manager who's index is a certain distance from the last item in the Manager */\n\tpublic last(distance: number = 1): V | undefined {\n\t\tconst key = this.keys()[this.size - distance];\n\t\treturn this.get(key);\n\t}\n\n\t/** 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 */\n\tpublic delete(key: K): boolean {\n\t\treturn this.map.delete(key);\n\t}\n\n\t/** Removes a value stored in the Manager via a key, returns the Manager class, allowing for chains */\n\tpublic remove(key: K): Manager<K, V> {\n\t\tthis.map.delete(key);\n\t\treturn this;\n\t}\n\n\t/** Clear the Manager of all its contents */\n\tpublic clear(): Manager<K, V> {\n\t\tthis.map.clear();\n\t\treturn this;\n\t}\n\n\t/** Checks if the Manager contains a certain key */\n\tpublic has(key: K): boolean {\n\t\treturn this.map.has(key);\n\t}\n\n\t/** Returns a new Iterator object that contains an array of [key, value] for each element in the Map object in insertion order. */\n\tpublic entries(): IterableIterator<[K, V]> {\n\t\treturn this.map.entries();\n\t}\n\n\t/** Iterates through the Managers contents, calling a callback function every iteration */\n\tpublic forEach(\n\t\tcallback: (value?: V, key?: K, map?: Map<K, V>) => void,\n\t\tcontext?: object\n\t): Manager<K, V> {\n\t\tthis.map.forEach(callback, context);\n\t\treturn this;\n\t}\n\n\t/** Allows for iteration via for..of, learn more: [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators] */\n\tpublic [Symbol.iterator](): IterableIterator<[K, V]> {\n\t\treturn this.entries();\n\t}\n}\n\n/**\n * Calls the method of a certain name for all items in the Map\n */\nexport function methodCall<K, V>(manager: Manager<K, V>, method: string, ...args: any): void {\n\tmanager.forEach((item) => {\n\t\tif (!item) return;\n\t\tif (typeof item !== \"object\") return;\n\t\tif (!(method in item)) return;\n\n\t\tconst fn = (item as Record<PropertyKey, Function>)[method];\n\t\tif (typeof fn !== \"function\") return;\n\t\tfn?.(...args);\n\t});\n};\n\nexport default Manager;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMO,IAAM,UAAN,MAAoB;AAAA;AAAA,EAEhB;AAAA,EACV,YAAY,OAAuB;AAClC,SAAK,MAAM,IAAI,IAAI,KAAK;AAAA,EACzB;AAAA;AAAA,EAGO,SAAoB;AAC1B,WA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