import { a as EitherKey, n as immutable, r as IMapBase, t as IMapImmutable } from "./map-Dgj9_4Jy.js"; import { IWithEntries, Interval, IsEqual, ToString } from "@ixfx/core"; import { SimpleEventEmitter } from "@ixfx/events"; //#region src/circular-array.d.ts interface ICircularArray extends Array { /** * Returns true if the array has filled to capacity and is now * recycling array indexes. */ get isFull(): boolean; /** * Returns a new Circular with item added * * Items are added at `pointer` position, which automatically cycles through available array indexes. * * @param value Thing to add * @returns Circular with item added */ add(value: V): ICircularArray; get length(): number; /** * Returns the current add position of array. */ get pointer(): number; } /** * A circular array keeps a maximum number of values, overwriting older values as needed. Immutable. * * `CircularArray` extends the regular JS array. Only use `add` to change the array if you want * to keep the `CircularArray` behaviour. * * @example Basic functions * ```js * let a = new CircularArray(10); * a = a.add(`hello`); // Because it's immutable, capture the return result of `add` * a.isFull; // True if circular array is full * a.pointer; // The current position in array it will write to * ``` * * Since it extends the regular JS array, you can access items as usual: * @example Accessing * ```js * let a = new CircularArray(10); * ... add some stuff .. * a.forEach(item => // do something with item); * ``` * @param capacity Maximum capacity before recycling array entries * @return Circular array */ declare class CircularArray extends Array { #private; constructor(capacity?: number); /** * Add to array * @param value Thing to add * @returns */ add(value: V): CircularArray; get pointer(): number; get isFull(): boolean; } //#endregion //#region src/map/expiring-map.d.ts /** * Expiring map options */ type Opts = { /** * Capacity limit */ readonly capacity?: number; /** * Policy for evicting items if capacity is reached */ readonly evictPolicy?: `none` | `oldestGet` | `oldestSet`; /** * Automatic deletion policy. * none: no automatic deletion (default) * get/set: interval based on last get/set * either: if either interval has elapsed */ readonly autoDeletePolicy?: `none` | `get` | `set` | `either`; /** * Automatic deletion interval */ readonly autoDeleteElapsedMs?: number; }; /** * Event from the ExpiringMap */ type ExpiringMapEvent = { readonly key: K; readonly value: V; }; type ExpiringMapEvents = { /** * Fires when an item is removed due to eviction * or automatic expiry */ readonly expired: ExpiringMapEvent; /** * Fires when a item with a new key is added */ readonly newKey: ExpiringMapEvent; /** * Fires when an item is manually removed, * removed due to eviction or automatic expiry */ readonly removed: ExpiringMapEvent; }; /** * Create a ExpiringMap instance * @param options Options when creating map * @returns */ declare const create: (options?: Opts) => ExpiringMap; /*** * A map that can have a capacity limit. The elapsed time for each get/set * operation is maintained allowing for items to be automatically removed. * `has()` does not affect the last access time. * * By default, it uses the `none` eviction policy, meaning that when full * an error will be thrown if attempting to add new keys. * * Eviction policies: * `oldestGet` removes the item that hasn't been accessed the longest, * `oldestSet` removes the item that hasn't been updated the longest. * * ```js * const map = new ExpiringMap(); * map.set(`fruit`, `apple`); * * // Remove all entries that were set more than 100ms ago * map.deleteWithElapsed(100, `set`); * // Remove all entries that were last accessed more than 100ms ago * map.deleteWithElapsed(100, `get`); * // Returns the elapsed time since `fruit` was last accessed * map.elapsedGet(`fruit`); * // Returns the elapsed time since `fruit` was last set * map.elapsedSet(`fruit`); * ``` * * Last set/get time for a key can be manually reset using {@link touch}. * * * Events: * * 'expired': when an item is automatically removed. * * 'removed': when an item is manually or automatically removed due to expiry. Note: does not fire when .clear() is called * * 'newKey': when a new key is added * * ```js * map.addEventListener(`expired`, evt => { * const { key, value } = evt; * }); * ``` * The map can automatically remove items based on elapsed intervals. * * @example * Automatically delete items that haven't been accessed for one second * ```js * const map = new ExpiringMap({ * autoDeleteElapsed: 1000, * autoDeletePolicy: `get` * }); * ``` * * @example * Automatically delete the oldest item if we reach a capacity limit * ```js * const map = new ExpiringMap({ * capacity: 5, * evictPolicy: `oldestSet` * }); * ``` * @typeParam K - Type of keys * @typeParam V - Type of values */ declare class ExpiringMap extends SimpleEventEmitter> { #private; private capacity; private store; private evictPolicy; private autoDeleteElapsedMs; private autoDeletePolicy; private autoDeleteTimer; private disposed; constructor(opts?: Opts); dispose(): void; /** * Returns the number of keys being stored. */ get keyLength(): number; entries(): IterableIterator<[k: K, v: V]>; values(): IterableIterator; keys(): IterableIterator; /** * Returns the elapsed time since `key` * was set. Returns _undefined_ if `key` * does not exist */ elapsedSet(key: K): number | undefined; /** * Returns the elapsed time since `key` * was accessed. Returns _undefined_ if `key` * does not exist */ elapsedGet(key: K): number | undefined; /** * Returns true if `key` is stored. * Does not affect the key's last access time. * @param key * @returns */ has(key: K): boolean; /** * Gets an item from the map by key, returning * undefined if not present * @param key Key * @returns Value, or undefined */ get(key: K): V | undefined; /** * Deletes the value under `key`, if present. * * Returns _true_ if something was removed. * @param key * @returns */ delete(key: K): boolean; /** * Clears the contents of the map. * Note: does not fire `removed` event */ clear(): void; /** * Updates the lastSet/lastGet time for a value * under `key`. If key was not found, nothing happens. * * Returns _false_ if key was not found * @param key * @returns */ touch(key: K): boolean; private findEvicteeKey; /** * Deletes all values where elapsed time has past * for get/set or either. * ```js * // Delete all keys (and associated values) not accessed for a minute * em.deleteWithElapsed({mins:1}, `get`); * // Delete things that were set 1s ago * em.deleteWithElapsed(1000, `set`); * ``` * * @param interval Interval * @param property Basis for deletion 'get','set' or 'either' * @returns Items removed */ deleteWithElapsed(interval: Interval, property: `get` | `set` | `either`): [k: K, v: V][]; /** * Sets the `key` to be `value`. * * If the key already exists, it is updated. * * If the map is full, according to its capacity, * another value is selected for removal. * @param key * @param value * @returns */ set(key: K, value: V): void; } //#endregion //#region src/map/imap-of.d.ts interface IMapOf { /** * Iterates over all keys */ keys(): IterableIterator; /** * Iterates over all values stored under `key` * @param key */ valuesFor(key: string): IterableIterator; /** * Returns a copy of all values under key as an arry * @param key */ /** * Iterates over all values, regardless of key. * Same value may re-appear if it's stored under different keys. */ valuesFlat(): IterableIterator; /** * Iterates over key-value pairs. * Unlike a normal map, the same key may appear several times. */ entriesFlat(): IterableIterator; entries(): IterableIterator<[key: string, value: V[]]>; /** * Iteates over all keys and the count of values therein */ keysAndCounts(): IterableIterator; /** * Returns _true_ if `value` is stored under `key`. * * @param key Key * @param value Value */ hasKeyValue(key: string, value: V, eq?: IsEqual): boolean; /** * Returns _true_ if `key` has any values * @param key */ has(key: string): boolean; /** * Returns _true_ if the map is empty */ get isEmpty(): boolean; /** * Returns the number of values stored under `key`, or _0_ if `key` is not present. * @param key Key */ count(key: string): number; /** * Finds the first key where value is stored. * Note: value could be stored in multiple keys * @param value Value to seek * @returns Key, or undefined if value not found */ firstKeyByValue(value: V, eq?: IsEqual): string | undefined; } //#endregion //#region src/map/imap-of-mutable.d.ts interface IMapOfMutable extends IMapOf { /** * Adds several `values` under the same `key`. Duplicate values are permitted, depending on implementation. * ```js * addKeyedValues('colours', 'red', 'green', 'blue') * ``` * @param key * @param values */ addKeyedValues(key: string, ...values: readonly V[]): void; /** * Adds a value, automatically extracting a key via the * `groupBy` function assigned in the constructor options. * @param values Adds several values */ addValue(...values: readonly V[]): void; /** * Clears the map */ clear(): void; /** * Returns the number of keys */ get lengthKeys(): number; /** * Deletes all values under `key` that match `value`. * @param key Key * @param value Value */ deleteKeyValue(key: string, value: V): boolean; /** * Delete all occurrences of `value`, regardless of * key it is stored under. * Returns _true_ if something was deleted. * @param value */ deleteByValue(value: V): boolean; /** * Deletes all values stored under `key`. Returns _true_ if key was found * @param key */ delete(key: string): boolean; } //#endregion //#region src/map/map-of-simple-base.d.ts declare class MapOfSimpleBase { protected map: Map; protected readonly groupBy: (value: V) => string; protected valueEq: IsEqual; /** * Constructor * * ```js * const m = new MapOfSimpleBase(); * m.valuesFor(`apple`); // Iterator over all values stored under key `apple` * ``` * @param groupBy Creates keys for values when using `addValue`. By default uses JSON.stringify * @param valueEq Compare values. By default uses JS logic for equality */ constructor(groupBy?: (value: V) => string, valueEq?: IsEqual, initial?: Map | Array<[string, readonly V[]]>); /** * Returns the underlying map storage. Do not manipulate. */ get getRawMapUnsafe(): Map; /** * Returns _true_ if `key` exists * @param key * @returns */ has(key: string): boolean; /** * Returns _true_ if `value` exists under `key`. * @param key Key * @param value Value to seek under `key` * @returns _True_ if `value` exists under `key`. */ hasKeyValue(key: string, value: V): boolean; /** * Debug dump of contents */ debugString(): string; /** * Return number of values stored under `key`. * Returns 0 if `key` is not found. * @param key * @returns */ count(key: string): number; /** * Returns first key that contains `value` * @param value * @param eq * @returns */ firstKeyByValue(value: V, eq?: IsEqual): string | undefined; /** * Iterate over all entries */ entriesFlat(): IterableIterator<[key: string, value: V]>; /** * Iterate over keys and array of values for that key */ entries(): IterableIterator<[key: string, value: V[]]>; /** * Get all values under `key` * @param key * @returns */ valuesFor(key: string): IterableIterator; /** * Iterate over all keys */ keys(): IterableIterator; /** * Iterate over all values (regardless of key). * Use {@link values} to iterate over a set of values per key */ valuesFlat(): IterableIterator; /** * Returns all values under 'key', or * an empty array if key is not found. * * Array is a copy of stored array. * @param key * @returns */ /** * Returns the underlying array that stores values for `key`. * * Returns _undefined_ if key does not exist. * * Be careful about modifying array. * @param key * @returns */ getRawArray(key: string): readonly V[] | undefined; /** * Yields the values for each key in sequence, returning an array. * Use {@link valuesFlat} to iterate over all keys regardless of key. */ values(): IterableIterator; /** * Iterate over keys and length of values stored under keys */ keysAndCounts(): IterableIterator<[string, number]>; /** * Returns the count of keys. */ get lengthKeys(): number; /** * _True_ if empty */ get isEmpty(): boolean; } //#endregion //#region src/map/map-of-simple-mutable.d.ts /** * A simple mutable map of arrays, without events. It can store multiple values * under the same key. * * For a fancier approaches, consider ofArrayMutable, ofCircularMutable or ofSetMutable. * * @example * ```js * const m = mapOfSimpleMutable(); * m.add(`hello`, 1, 2, 3); // Adds numbers under key `hello` * m.delete(`hello`); // Deletes everything under `hello` * const hellos = m.valuesFor(`hello`); // Enumerate items stored under key `hello` * ``` * * Constructor takes a `groupBy` parameter, which yields a string key for a value. This is the * basis by which values are keyed when using `addValues`. * * Constructor takes a `valueEq` parameter, which compares values. This is used when checking * if a value exists under a key, for example. * @typeParam V - Type of items */ declare class MapOfSimpleMutable extends MapOfSimpleBase implements IMapOfMutable { addKeyedValues(key: string, ...values: readonly V[]): void; /** * Set `values` to `key`. * Previous data stored under `key` is thrown away. * @param key * @param values */ setValues(key: string, values: readonly V[]): void; /** * Adds a value, automatically extracting a key via the * `groupBy` function assigned in the constructor options. * @param values Adds several values */ addValue(...values: readonly V[]): void; /** * Delete `value` under a particular `key` * @param key * @param value * @returns _True_ if `value` was found under `key` */ deleteKeyValue(key: string, value: V): boolean; /** * Deletes `value` regardless of key. * * Uses the constructor-defined equality function. * @param value Value to delete * @returns */ deleteByValue(value: V): boolean; /** * Deletes all values under `key`, * @param key * @returns _True_ if `key` was found and values stored */ delete(key: string): boolean; /** * Clear contents */ clear(): void; } /** * A simple mutable map of arrays, without events. It can store multiple values * under the same key. * * For a fancier approaches, consider {@link ofArrayMutable}, {@link ofCircularMutable} or {@link ofSetMutable}. * * @example * ```js * const m = mapOfSimpleMutable(); * m.add(`hello`, 1, 2, 3); // Adds numbers under key `hello` * m.delete(`hello`); // Deletes everything under `hello` * * const hellos = m.get(`hello`); // Get list of items under `hello` * ``` * * @typeParam V - Type of items * @returns New instance */ declare function ofSimpleMutable(groupBy?: (value: V) => string, valueEq?: IsEqual): IMapOfMutable; //#endregion //#region src/map/map-mutable.d.ts /** * A mutable map. * * It is a wrapper around the in-built Map type, but adds roughly the same API as {@link IMapImmutable}. * * @typeParam K - Type of map keys. Typically `string` * @typeParam V - Type of stored values */ interface IMapMutable extends IMapBase { /** * Adds one or more items to map * * Can add items in the form of [key,value] or `{key, value}`. * @example These all produce the same result * ```js * map.set(`hello`, `samantha`); * map.add([`hello`, `samantha`]); * map.add({key: `hello`, value: `samantha`}) * ``` * @param itemsToAdd * @param itemsToAdd */ add(...itemsToAdd: EitherKey): void; /** * Sets a value to a specified key * @param key * @param value */ set(key: K, value: V): void; /** * Deletes an item by key * @param key */ delete(key: K): void; /** * Clears map */ clear(): void; } /** * Returns a {@link IMapMutable} (which just wraps the in-built Map) * Use {@link Maps.immutable} for the immutable alternative. * * @example Basic usage * ```js * const m = mapMutable(); * // Add one or more entries * m.add(["name", "sally"]); * // Alternatively: * m.set("name", "sally"); * // Recall * m.get("name"); // "sally" * m.delete("name"); * m.isEmpty; // True * m.clear(); * ``` * @param data Optional initial data in the form of an array of `{ key: value }` or `[ key, value ]` */ declare const mutable: (...data: EitherKey) => IMapMutable; //#endregion //#region src/map/imap-of-mutable-extended.d.ts /** * Events from mapArray */ type MapArrayEvents = { readonly addedValues: { readonly values: readonly V[]; }; readonly addedKey: { readonly key: string; }; readonly clear: boolean; readonly deleteKey: { readonly key: string; }; }; /** * Like a `Map` but multiple values can be stored for each key. * Duplicate values can be added to the same or even a several keys. * * Three pre-defined MapOf's are available: * * {@link ofArrayMutable} - Map of arrays * * {@link ofSetMutable} - Map of unique items * * {@link ofCircularMutable} - Hold a limited set of values per key * * Adding * ```js * // Add one or more values using the predefined key function to generate a key * map.addValue(value1, value2, ...); * // Add one or more values under a specified key * map.addKeyedValues(key, value1, value2, ...); * ``` * * Finding/accessing * ```js * // Returns all values stored under key * map.get(key); * // Returns the first key where value is found, or _undefined_ if not found * map.findKeyForValue(value); * // Returns _true_ if value is stored under key * map.hasKeyValue(key, value); * // Returns _true_ if map contains key * map.has(key); * ``` * * Removing * ```js * // Removes everything * map.clear(); * // Delete values under key. Returns _true_ if key was found. * map.delete(key); * // Deletes specified value under key. Returns _true_ if found. * map.deleteKeyValue(key, value); * ``` * * Metadata about the map: * ```js * map.isEmpty; // True/false * map.lengthMax; // Largest count of items under any key * map.count(key); // Count of items stored under key, or 0 if key is not present. * map.keys(); // Returns a string array of keys * map.keysAndCounts(); // Returns an array of [string,number] for all keys and number of values for each key * map.debugString(); // Returns a human-readable string dump of the contents * ``` * * Events can be listened to via `addEventListener` * * `addedKey`, `addedValue` - when a new key is added, or when a new value is added * * `clear` - when contents are cleared * * `deleteKey` - when a key is deleted * * @example Event example * ```js * map.addEventLister(`addedKey`, ev => { * // New key evt.key seen. * }); * ``` * * @typeParam V - Values stored under keys * @typeParam M - Type of data structure managing values */ interface IMapOfMutableExtended extends SimpleEventEmitter>, IMapOfMutable { /** * Returns the object managing values under the specified `key` * @private * @param key */ getSource(key: string): M | undefined; /** * Returns the type name. For in-built implementations, it will be one of: array, set or circular */ get typeName(): string; /** * Returns a human-readable rendering of contents */ debugString(): string; } //#endregion //#region src/map/map-of-array-mutable.d.ts /** * Map of array options */ type MapArrayOpts = MapMultiOpts & { /** * Comparer to use */ readonly comparer?: IsEqual; /** * Key function */ readonly convertToString?: ToString; }; /** * Returns a {@link IMapOfMutableExtended} to allow storing multiple values under a key, unlike a regular Map. * @example * ```js * const map = ofArrayMutable(); * map.addKeyedValues(`hello`, [1,2,3,4]); // Adds series of numbers under key `hello` * * const hello = map.get(`hello`); // Get back values * ``` * * Takes options: * * `comparer`: {@link IsEqual} * * `toString`: Util.ToString * * A custom Util.ToString function can be provided as the `convertToString` opion. This is then used when checking value equality (`has`, `without`) * ```js * const map = ofArrayMutable({ convertToString:(v) => v.name}); // Compare values based on their `name` field; * ``` * * Alternatively, a {@link IsEqual} function can be used: * ```js * const map = ofArrayMutable({comparer: (a, b) => a.name === b.name }); * ``` * @param options Optiosn for mutable array * @typeParam V - Data type of items * @returns {@link IMapOfMutableExtended} */ declare const ofArrayMutable: (options?: MapArrayOpts) => IMapOfMutableExtended; //#endregion //#region src/map/imap-of-immutable.d.ts /** * Like a `Map` but multiple values can be stored for each key. Immutable. * Duplicate values can be added to the same or even a several keys. * * Adding * ```js * // Add one or more values using the predefined key function to generate a key * map = map.addValue(value1, value2, ...); * // Add one or more values under a specified key * map = map.addKeyedValues(key, value1, value2, ...); * ``` * * Finding/accessing * ```js * // Returns all values stored under key * map.get(key); * // Returns the first key where value is found, or _undefined_ if not found * map.findKeyForValue(value); * // Returns _true_ if value is stored under key * map.hasKeyValue(key, value); * // Returns _true_ if map contains key * map.has(key); * ``` * * Removing * ```js * // Removes everything * map = map.clear(); * // Delete values under key. Returns _true_ if key was found. * map = map.delete(key); * // Deletes specified value under key. Returns _true_ if found. * map = map.deleteKeyValue(key, value); * ``` * * Metadata about the map: * ```js * map.isEmpty; // True/false * map.lengthMax; // Largest count of items under any key * map.count(key); // Count of items stored under key, or 0 if key is not present. * map.keys(); // Returns a string array of keys * map.keysAndCounts(); // Returns an array of [string,number] for all keys and number of values for each key * map.debugString(); // Returns a human-readable string dump of the contents * ``` * * @typeParam V - Values stored under keys * @typeParam M - Type of data structure managing values */ interface IMapOfImmutable extends IMapOf { /** * Adds several `values` under the same `key`. Duplicate values are permitted, depending on implementation. * @param key * @param values */ addKeyedValues(key: string, ...values: ReadonlyArray): IMapOfImmutable; /** * Adds a value, automatically extracting a key via the * `groupBy` function assigned in the constructor options. * @param values Adds several values */ addValue(...values: ReadonlyArray): IMapOfImmutable; /** * Clears the map */ clear(): IMapOfImmutable; /** * Deletes all values under `key` that match `value`. * @param key Key * @param value Value */ deleteKeyValue(key: string, value: V): IMapOfImmutable; /** * Delete all occurrences of `value`, regardless of * key it is stored under. * @param value */ deleteByValue(value: V): IMapOfImmutable; /** * Deletes all values stored under `key`. * @param key */ delete(key: string): IMapOfImmutable; } //#endregion //#region src/map/map-of-simple.d.ts /** * Simple immutable MapOf */ declare class MapOfSimple extends MapOfSimpleBase implements IMapOf, IMapOfImmutable { addKeyedValues(key: string, ...values: V[]): MapOfSimple; addValue(...values: readonly V[]): MapOfSimple; addBatch(batch: [key: string, value: V[]][]): MapOfSimple; clear(): MapOfSimple; deleteKeyValue(_key: string, _value: V, eq?: IsEqual): MapOfSimple; deleteByValue(value: V, eq?: IsEqual): MapOfSimple; delete(key: string): MapOfSimple; } /** * A simple immutable map of arrays, without events. It can store multiple values * under the same key. * * For a fancier approaches, consider {@link ofArrayMutable}, {@link ofCircularMutable} or {@link ofSetMutable}. * * @example * ```js * let m = mapSimple(); * m = m.add(`hello`, 1, 2, 3); // Adds numbers under key `hello` * m = m.delete(`hello`); // Deletes everything under `hello` * * const hellos = m.get(`hello`); // Get list of items under `hello` * ``` * * @typeParam V - Type of items * @returns New instance */ declare const ofSimple: (groupBy?: ToString, valueEq?: IsEqual) => IMapOfImmutable; //#endregion //#region src/map/map-of-multi-impl.d.ts /** * @internal */ declare class MapOfMutableImpl extends SimpleEventEmitter> implements IMapOfMutableExtended { #private; readonly groupBy: ToString; readonly type: MultiValue; constructor(type: MultiValue, opts?: MapMultiOpts); /** * Returns the type name. For in-built implementations, it will be one of: array, set or circular */ get typeName(): string; /** * Returns the number of keys */ get lengthKeys(): number; /** * Returns the length of the longest child list */ get lengthMax(): number; debugString(): string; get isEmpty(): boolean; clear(): void; addKeyedValues(key: string, ...values: V[]): void; set(key: string, values: V[]): this; addValue(...values: readonly V[]): void; hasKeyValue(key: string, value: V, eq: IsEqual): boolean; has(key: string): boolean; deleteKeyValue(key: string, value: V): boolean; private deleteKeyValueFromMap; deleteByValue(value: V): boolean; delete(key: string): boolean; firstKeyByValue(value: V, eq?: IsEqual): string | undefined; count(key: string): number; /** * Iterates over values stored under `key` * If `key` is not found, no error is thrown - the iterator returns no values * * Alternatively use {@link valuesFor} */ /** * Iterate over the values stored under `key`. * If key does not exist, iteration is essentially a no-op. * * Alternatively, use {@link valuesForAsArray} to get values as an array. * @param key * @returns */ valuesFor(key: string): Generator; getSource(key: string): M | undefined; keys(): IterableIterator; entriesFlat(): IterableIterator<[key: string, value: V]>; valuesFlat(): IterableIterator; entries(): IterableIterator<[key: string, value: V[]]>; keysAndCounts(): IterableIterator<[string, number]>; merge(other: IMapOf): void; get size(): number; get [Symbol.toStringTag](): string; } //#endregion //#region src/map/map-multi-fns.d.ts /** * Finds first entry by iterable value. Expects a map with an iterable as values. * * ```js * const map = new Map(); * map.set('hello', ['a', 'b', 'c']); * map.set('there', ['d', 'e', 'f']); * * const entry = firstEntry(map, (value, key) => { * return (value === 'e'); * }); * // Entry is: ['there', ['d', 'e', 'f']] * ``` * * An alternative is {@link firstEntryByValue} to search by value. * @param map Map to search * @param predicate Filter function returns true when there is a match of value * @returns Entry, or _undefined_ if `filter` function never returns _true_ */ declare const firstEntry: (map: IWithEntries>, predicate: (value: V, key: K) => boolean) => readonly [key: K, value: Iterable] | undefined; /** * Returns the entry with the largest count of elements, * or _undefined_ if `map` is empty. */ declare const longestEntry: (map: IWithEntries) => readonly [K, V] | undefined; /** * Finds first entry by iterable value. Expects a map with an iterable as values. * * ```js * const map = new Map(); * map.set('hello', ['a', 'b', 'c']); * map.set('there', ['d', 'e', 'f']); * * const entry = firstEntryByValue(map, 'e'); * // Entry is: ['there', ['d', 'e', 'f']] * ``` * * An alternative is {@link firstEntry} to search by predicate function. * @param map Map to search * @param soughtValue Value to seek * @param isEqual Filter function which checks equality. Uses JS comparer by default. * @returns Entry, or _undefined_ if `value` not found. * @throws If 'map' doesn't seem like a map */ declare const firstEntryByValue: (map: IWithEntries>, soughtValue: V, isEqual?: IsEqual) => readonly [key: K, value: Iterable] | undefined; /** * Returns a copy of `map`, with the internal arrays being a different object. * Values contained inside are not copied. * @param map * @returns */ declare const cloneShallow: (map: IWithEntries>) => Map; /** * Returns true if both sets of data have the same keys, and iterables at each key contain the same values, regardless of order. * By default uses === comparison semantics. * @param a * @param b * @param comparerOrKey * @returns */ declare const equals: (a: IWithEntries>, b: IWithEntries>, comparerOrKey?: IsEqual | ((v: V) => string)) => boolean; //#endregion //#region src/map/map-multi.d.ts /** * @private */ type MultiValue = { get name(): string; has(source: M, value: V, eq: IsEqual): boolean; addKeyedValues(destination: M | undefined, values: Iterable): M; toArrayCopy(source: M): V[]; iterable(source: M): IterableIterator; find(source: M, predicate: (v: V) => boolean): V | undefined; filter(source: M, predicate: (v: V) => boolean): Iterable; without(source: M, value: V): readonly V[]; count(source: M): number; }; type MapMultiOpts = { /** * Returns a group for values added via `addValue`. Eg. maybe you want to * group values in the shape `{name: 'Samantha' city: 'Copenhagen'}` by city: * * ``` * const opts = { * groupBy: (v) => v.city * } * ``` * * @type {(ToString|undefined)} */ readonly groupBy?: ((value: V) => string) | undefined; }; type MapSetOpts = MapMultiOpts & { readonly hash: (value: V) => string; }; //#endregion //#region src/map/map-of-set-mutable.d.ts /** * Returns a {@link IMapOfMutableExtended} that uses a set to hold values. * This means that only unique values are stored under each key. By default it * uses the JSON representation to compare items. * * Options: `{ hash: toStringFn } }` * * `hash` is Util.ToString function: `(object) => string`. By default it uses * `JSON.stringify`. * * @example Only storing the newest three items per key * ```js * const map = ofSetMutable(); * map.addKeyedValues(`hello`, [1, 2, 3, 1, 2, 3]); * const hello = map.get(`hello`); // [1, 2, 3] * ``` * * @example * ```js * const hash = (v) => v.name; // Use name as the key * const map = ofSetMutable({hash}); * map.addValue({age:40, name: `Mary`}); * map.addValue({age:29, name: `Mary`}); // Value ignored as same name exists * ``` * @param options * @returns */ declare const ofSetMutable: (options?: MapSetOpts) => IMapOfMutableExtended>; //#endregion //#region src/map/map-of-circular-mutable.d.ts type MapCircularOpts = MapMultiOpts & { readonly capacity: number; }; /** * Returns a {@link IMapOfMutableExtended} that uses a {@link ICircularArray} to hold values. Mutable. * This means that the number of values stored under each key will be limited to the defined * capacity. * * Required option: * * `capacity`: how many items to hold * * @example Only store the most recent three items per key * ```js * const map = ofCircularMutable({capacity: 3}); * map.add(`hello`, 1, 2, 3, 4, 5); * const hello = [...map.get(`hello`)]; // [3, 4, 5] * ``` * @param options * @returns */ declare const ofCircularMutable: (options: MapCircularOpts) => IMapOfMutableExtended>; //#endregion //#region src/map/number-map.d.ts /** * Simple map for numbers. * * Keys not present in map return the `defaultValue` given in the constructor * ```js * // All keys default to zero. * const map = new Maps.NumberMap(); * map.get(`hello`); // 0 * ``` * * To check if a key is present, use `has`: * ```js * map.has(`hello`); // false * ``` * * Math: * ```js * // Adds 1 by default to value of `hello` * map.add(`hello`); // 1 * map.multiply(`hello`, 2); // 2 * * // Reset key to default value * map.reset(`hello`); // 0 * ``` * * Different default value: * ```js * const map = new Maps.NumberMap(10); * map.get(`hello`); // 10 * ``` * * Regular `set` works, overriding the value to whatever is given: * ```js * map.set(`hello`, 5); * map.add(`hello`, 2); // 7 * ``` */ declare class NumberMap extends Map { readonly defaultValue: number; /** * Creates a NumberMap with default value of 0 */ constructor(defaultValue?: number); /** * Gets the value at a key. If not found, returns the default value * @param key * @returns */ get(key: K): number; /** * Resets the key's value to the default value * @param key * @returns */ reset(key: K): number; /** * Multiplies the value of `key` by `amount`. If key is not found, it is treated as the default value. * The new value is set and returned. * @param key * @param amount * @returns */ multiply(key: K, amount: number): number; /** * Divides the value of `key` by `amount`. If key is not found, it is treated as the default value. * The new value is set and returned. * @param key * @param amount * @returns */ divide(key: K, amount: number): number; /** * Applies a function to all values * ```js * // Round all the values * map.mapValue((value,key)=> Math.round(value)); * ``` */ mapValue(fn: (value: number, key?: K) => number): void; /** * Returns the largest value in the map. If the map is empty, returns `NaN`. * ```js * // Eg find all the keys corresponding to the maximum value * const largestKeys = [...map.keysByValue(map.findValueMax())]; * ``` * @returns */ findValueMax(): number; /** * Returns the smallest value in the map. If the map is empty, returns `NaN`. * * ```js * // Eg find all the keys corresponding to the minimum value * const smallestKeys = [...map.keysByValue(map.findValueMin())]; * ``` * @returns */ findValueMin(): number; /** * Iterates over all keys that have a corresponding value * @param v */ keysByValue(v: number): Generator; /** * Iterates over entries, sorted by value. By default ascending order. */ entriesSorted(sorter?: (a: [K, number], b: [K, number]) => number): Generator<[key: K, value: number]>; /** * Iterates over all keys that have a value matching `fn`. * ```js * // Iterate over all keys that store a value greater than 1 * const greaterThanOne = (v) => v > 1; * for (const key of map.filterKeysByValue(greaterThanOne)) { * } * ``` * @param fn Predicate to test values */ filterKeysByValue(fn: (value: number) => boolean): Generator; /** * Deletes a set of keys */ deleteKeys(keys: Iterable): number; /** * Adds an amount to `key`'s value. If `key` is not found, it is treated as the default value. The new value is set and returned. * @param key * @param amount * @returns */ add(key: K, amount?: number): number; /** * Subtracts an amount from `key`'s value. If `key` is not found, it is treated as the default value. The new value is set and returned. * @param key * @param amount * @returns */ subtract(key: K, amount?: number): number; } //#endregion //#region src/map/map-mutable-events.d.ts type MapWithEventsEvents = { "removed": { key: TKey; value: TValue; }; "added": { key: TKey; value: TValue; }; "key-added": { key: TKey; value: TValue; }; "key-updated": { key: TKey; value: TValue; }; "cleared": undefined; }; /** * A wrapper around a regular Map, but one that fires events when data changes. * * Events: * * removed: Key/value removed * * added: Key/value added/updated * * key-added: Key/value pair added that resulted in a new key * * key-updated: Value updated for an existing key * * cleared: Map has been cleared */ declare class MapWithEvents extends SimpleEventEmitter> implements IMapMutable { #private; add(...itemsToAdd: EitherKey): void; set(key: TKey, value: TValue): void; delete(key: TKey): void; clear(): void; get(key: TKey): TValue | undefined; has(key: TKey): boolean; isEmpty(): boolean; entries(): IterableIterator; values(): IterableIterator; } declare namespace index_d_exports { export { ExpiringMap, ExpiringMapEvent, ExpiringMapEvents, Opts as ExpiringMapOpts, IMapImmutable, IMapMutable, IMapOf, IMapOfImmutable, IMapOfMutable, IMapOfMutableExtended, MapArrayEvents, MapArrayOpts, MapCircularOpts, MapMultiOpts, MapOfMutableImpl, MapOfSimple, MapOfSimpleMutable, MapSetOpts, MapWithEvents, MapWithEventsEvents, MultiValue, NumberMap, cloneShallow, equals, create as expiringMap, firstEntry, firstEntryByValue, immutable, longestEntry, ofSimpleMutable as mapOfSimpleMutable, mutable, ofArrayMutable, ofCircularMutable, ofSetMutable, ofSimple, ofSimpleMutable }; } import * as import__ixfx_core_maps from "@ixfx/core/maps"; //#endregion export { ExpiringMap as A, MapArrayEvents as C, ofSimpleMutable as D, MapOfSimpleMutable as E, CircularArray as F, ICircularArray as I, ExpiringMapEvents as M, Opts as N, IMapOfMutable as O, create as P, IMapOfMutableExtended as S, mutable as T, MapOfSimple as _, MapCircularOpts as a, MapArrayOpts as b, MapMultiOpts as c, cloneShallow as d, equals as f, MapOfMutableImpl as g, longestEntry as h, NumberMap as i, ExpiringMapEvent as j, IMapOf as k, MapSetOpts as l, firstEntryByValue as m, MapWithEvents as n, ofCircularMutable as o, firstEntry as p, MapWithEventsEvents as r, ofSetMutable as s, index_d_exports as t, MultiValue as u, ofSimple as v, IMapMutable as w, ofArrayMutable as x, IMapOfImmutable as y };