@danliyev/wishmap
    Preparing search index...

    Class WishMap<K, V>

    An extended Map with Array-like methods and event emission.

    Type Parameters

    • K

      The type of keys in the map

    • V

      The type of values in the map

    Hierarchy

    • Map<K, V>
      • WishMap
    Index

    Constructors

    • Type Parameters

      • K

        The type of keys in the map

      • V

        The type of values in the map

      Parameters

      • Optionalentries: readonly (readonly [K, V])[] | null

      Returns WishMap<K, V>

    • Type Parameters

      • K

        The type of keys in the map

      • V

        The type of values in the map

      Parameters

      • Optionaliterable: Iterable<readonly [K, V], any, any> | null

      Returns WishMap<K, V>

    Properties

    "[toStringTag]": string
    events: EventEmitter<WishMapEvents<K, V>> = ...

    Event emitter for map mutations

    includes: (key: K) => boolean = ...

    Alias for has(). Checks if a key exists in the map.

    Type Declaration

      • (key: K): boolean
      • Parameters

        • key: K

        Returns boolean

        boolean indicating whether an element with the specified key exists or not.

    off: <E extends string | symbol>(
        eventName: "delete" | "set" | (keyof EventEmitterEventMap) | E,
        listener: (
            ...args: E extends keyof WishMapEvents<K, V>
                ? WishMapEvents<K, V>[E<E>]
                : E extends keyof EventEmitterEventMap
                    ? EventEmitterEventMap[E<E>]
                    : any[],
        ) => void,
    ) => this = ...

    Type Declaration

      • <E extends string | symbol>(
            eventName: "delete" | "set" | (keyof EventEmitterEventMap) | E,
            listener: (
                ...args: E extends keyof WishMapEvents<K, V>
                    ? WishMapEvents<K, V>[E<E>]
                    : E extends keyof EventEmitterEventMap
                        ? EventEmitterEventMap[E<E>]
                        : any[],
            ) => void,
        ): this
      • Alias for emitter.removeListener().

        Type Parameters

        • E extends string | symbol

        Parameters

        • eventName: "delete" | "set" | (keyof EventEmitterEventMap) | E
        • listener: (
              ...args: E extends keyof WishMapEvents<K, V>
                  ? WishMapEvents<K, V>[E<E>]
                  : E extends keyof EventEmitterEventMap
                      ? EventEmitterEventMap[E<E>]
                      : any[],
          ) => void

        Returns this

        v10.0.0

    on: <E extends string | symbol>(
        eventName: "delete" | "set" | (keyof EventEmitterEventMap) | E,
        listener: (
            ...args: E extends keyof WishMapEvents<K, V>
                ? WishMapEvents<K, V>[E<E>]
                : E extends keyof EventEmitterEventMap
                    ? EventEmitterEventMap[E<E>]
                    : any[],
        ) => void,
    ) => this = ...

    Type Declaration

      • <E extends string | symbol>(
            eventName: "delete" | "set" | (keyof EventEmitterEventMap) | E,
            listener: (
                ...args: E extends keyof WishMapEvents<K, V>
                    ? WishMapEvents<K, V>[E<E>]
                    : E extends keyof EventEmitterEventMap
                        ? EventEmitterEventMap[E<E>]
                        : any[],
            ) => void,
        ): this
      • Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

        server.on('connection', (stream) => {
        console.log('someone connected!');
        });

        Returns a reference to the EventEmitter, so that calls can be chained.

        By default, event listeners are invoked in the order they are added. The emitter.prependListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.

        import { EventEmitter } from 'node:events';
        const myEE = new EventEmitter();
        myEE.on('foo', () => console.log('a'));
        myEE.prependListener('foo', () => console.log('b'));
        myEE.emit('foo');
        // Prints:
        // b
        // a

        Type Parameters

        • E extends string | symbol

        Parameters

        • eventName: "delete" | "set" | (keyof EventEmitterEventMap) | E

          The name of the event.

        • listener: (
              ...args: E extends keyof WishMapEvents<K, V>
                  ? WishMapEvents<K, V>[E<E>]
                  : E extends keyof EventEmitterEventMap
                      ? EventEmitterEventMap[E<E>]
                      : any[],
          ) => void

          The callback function

        Returns this

        v0.1.101

    once: <E extends string | symbol>(
        eventName: "delete" | "set" | (keyof EventEmitterEventMap) | E,
        listener: (
            ...args: E extends keyof WishMapEvents<K, V>
                ? WishMapEvents<K, V>[E<E>]
                : E extends keyof EventEmitterEventMap
                    ? EventEmitterEventMap[E<E>]
                    : any[],
        ) => void,
    ) => this = ...

    Type Declaration

      • <E extends string | symbol>(
            eventName: "delete" | "set" | (keyof EventEmitterEventMap) | E,
            listener: (
                ...args: E extends keyof WishMapEvents<K, V>
                    ? WishMapEvents<K, V>[E<E>]
                    : E extends keyof EventEmitterEventMap
                        ? EventEmitterEventMap[E<E>]
                        : any[],
            ) => void,
        ): this
      • Adds a one-time listener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked.

        server.once('connection', (stream) => {
        console.log('Ah, we have our first user!');
        });

        Returns a reference to the EventEmitter, so that calls can be chained.

        By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.

        import { EventEmitter } from 'node:events';
        const myEE = new EventEmitter();
        myEE.once('foo', () => console.log('a'));
        myEE.prependOnceListener('foo', () => console.log('b'));
        myEE.emit('foo');
        // Prints:
        // b
        // a

        Type Parameters

        • E extends string | symbol

        Parameters

        • eventName: "delete" | "set" | (keyof EventEmitterEventMap) | E

          The name of the event.

        • listener: (
              ...args: E extends keyof WishMapEvents<K, V>
                  ? WishMapEvents<K, V>[E<E>]
                  : E extends keyof EventEmitterEventMap
                      ? EventEmitterEventMap[E<E>]
                      : any[],
          ) => void

          The callback function

        Returns this

        v0.3.0

    size: number

    the number of elements in the Map.

    "[species]": MapConstructor

    Accessors

    Methods

    • Returns an iterable of entries in the map.

      Returns MapIterator<[K, V]>

    • Returns the value at the given index. Supports negative indices.

      Parameters

      • index: number

        The index of the value to return

      Returns V | undefined

    • Returns void

    • Copies a sequence of entries within the map.

      Parameters

      • target: number

        Index to copy entries to

      • start: number

        Index to start copying from

      • Optionalend: number

        Index to stop copying from (exclusive)

      Returns this

    • Returns an iterable of key, value pairs for every entry in the map.

      Returns MapIterator<[K, V]>

    • Tests whether all entries pass the provided function.

      Parameters

      • fn: (value: V, key: K) => boolean

        Function to test each entry

      Returns boolean

    • Fills entries with a value from start to end index.

      Parameters

      • value: V

        Value to fill with

      • start: number = 0

        Start index (default: 0)

      • end: number = ...

        End index (default: size)

      Returns this

    • Returns the first value that passes the provided function.

      Parameters

      • fn: (value: V, key: K) => boolean

        Function to test each entry

      Returns V | undefined

    • Returns the index of the first entry that passes the provided function.

      Parameters

      • fn: (value: V, key: K) => boolean

        Function to test each entry

      Returns number

      Index of the first match, or -1 if not found

    • Returns the last value that passes the provided function.

      Parameters

      • fn: (value: V, key: K) => boolean

        Function to test each entry

      Returns V | undefined

    • Returns the index of the last entry that passes the provided function.

      Parameters

      • fn: (value: V, key: K) => boolean

        Function to test each entry

      Returns number

      Index of the last match, or -1 if not found

    • Flattens nested arrays in values to a specified depth.

      Type Parameters

      • D extends number = 1

      Parameters

      • Optionaldepth: D

        Depth level to flatten (default: 1)

      Returns unknown[]

    • Maps each entry then flattens the result.

      Type Parameters

      • T

      Parameters

      • fn: (value: V, key: K) => T | T[]

        Function that returns a value or array of values

      Returns T[]

    • Executes a provided function once per each key/value pair in the Map, in insertion order.

      Parameters

      • callbackfn: (value: V, key: K, map: Map<K, V>) => void
      • OptionalthisArg: any

      Returns void

    • Returns a specified element from the 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.

      Parameters

      • key: K

      Returns V | undefined

      Returns the element associated with the specified key. If no element is associated with the specified key, undefined is returned.

    • Parameters

      • key: K

      Returns boolean

      boolean indicating whether an element with the specified key exists or not.

    • Returns the first index of a value.

      Parameters

      • value: V

        Value to search for

      • fromIndex: number = 0

        Index to start searching from (default: 0)

      Returns number

    • Joins all values into a string.

      Parameters

      • separator: string = ','

        Separator between values (default: ',')

      Returns string

    • Returns an iterable of keys in the map

      Returns MapIterator<K>

    • Returns the last index of a value.

      Parameters

      • value: V

        Value to search for

      • fromIndex: number = ...

        Index to start searching backwards from

      Returns number

    • Creates an array by applying a function to each entry.

      Type Parameters

      • T

      Parameters

      • fn: (value: V, key: K) => T

        Function to apply to each entry

      Returns T[]

    • Adds entries to the end of the map.

      Parameters

      • ...items: [K, V][]

        Entries as [key, value] tuples

      Returns number

      The new size of the map

    • Reduces entries to a single value, from left to right.

      Type Parameters

      • T

      Parameters

      • fn: (acc: T, value: V, key: K) => T

        Reducer function

      • initial: T

        Initial accumulator value

      Returns T

    • Reduces entries to a single value, from right to left.

      Type Parameters

      • T

      Parameters

      • fn: (acc: T, value: V, key: K) => T

        Reducer function

      • initial: T

        Initial accumulator value

      Returns T

    • Adds or updates an element with a specified key and value.

      Parameters

      • key: K
      • value: V

      Returns this

      WishMap#set

    • Tests whether any entry passes the provided function.

      Parameters

      • fn: (value: V, key: K) => boolean

        Function to test each entry

      Returns boolean

    • Sorts entries in place.

      Parameters

      • Optionalfn: (a: [K, V], b: [K, V]) => number

        Compare function for [key, value] tuples

      Returns this

    • Removes and/or adds entries at a given index.

      Parameters

      • start: number

        Index to start changes

      • OptionaldeleteCount: number

        Number of entries to remove

      • ...items: [K, V][]

        Entries to add as [key, value] tuples

      Returns WishMap<K, V>

      A WishMap containing the removed entries

    • Returns a new WishMap with entries removed and/or added.

      Parameters

      • start: number

        Index to start changes

      • OptionaldeleteCount: number

        Number of entries to remove

      • ...items: [K, V][]

        Entries to add as [key, value] tuples

      Returns WishMap<K, V>

    • Adds entries to the beginning of the map.

      Parameters

      • ...items: [K, V][]

        Entries as [key, value] tuples

      Returns number

      The new size of the map

    • Returns an iterable of values in the map

      Returns MapIterator<V>

    • Groups members of an iterable according to the return value of the passed callback.

      Type Parameters

      • K
      • T

      Parameters

      • items: Iterable<T>

        An iterable.

      • keySelector: (item: T, index: number) => K

        A callback which will be invoked for each item in items.

      Returns Map<K, T[]>