sussy-util
Version:
Util package made by me
77 lines (76 loc) • 3.65 kB
TypeScript
import { MapEntry } from "../Types";
import Optional from "./Optional";
type Predicate<V, K> = (value: V, key: K, collection: Collection<K, V>) => boolean;
export default class Collection<K, V> extends Map<K, V> {
/**
* It removes the key and value from the map.
* @param {K} key - The key of the element to remove from the Map object.
* @returns The object that was removed from the map.
*/
remove(key: K): Optional<MapEntry<K, V>>;
toString(): string;
/**
* It converts the map to an array of objects.
* @returns An array of objects with key and value properties.
*/
toArray(): MapEntry<K, V>[];
/**
* It returns the size of the stack.
* @returns The size of the list.
*/
count(): number;
/**
* returns true if the key is not in the map
* @param {K} key - K
* @returns A boolean value.
*/
missing(key: K): boolean;
/**
* It converts the object to a JSON string.
* @returns The JSON string representation of the array.
*/
toJSONString(): string;
/**
* It checks if the map contains a specific value.
* @param {V} value - The value to search for in the map.
* @returns A boolean value indicating whether the value is found in the map.
*/
contains(value: V): boolean;
/**
* It merges the entries from another map into the current map.
* @param {Collection<K, V>} map - The map to merge with the current map.
*/
merge(map: Collection<K, V>): void;
/**
* It returns a new Collection containing entries that satisfy the provided predicate function.
* @param {Function} predicate - A predicate function that is called for each entry with arguments (value, key, collection).
* @returns A new Collection containing entries that satisfy the predicate function.
*/
filter(predicate: Predicate<V, K>): Collection<K, V>;
/**
* It performs a transformation on each entry in the Collection and returns a new Collection with the transformed entries.
* @param {Function} transformFn - A function that is called for each entry with arguments (value, key, collection).
* @returns A new Collection with the transformed entries.
*/
map<U>(transformFn: (value: V, key: K, collection: Collection<K, V>) => U): Collection<K, U>;
/**
* It performs a reduce operation on the Collection, accumulating a single value based on the entries.
* @param {Function} reducer - A reducer function that is called for each entry with arguments (accumulator, value, key, collection).
* @param {any} initialValue - An initial value for the accumulator.
* @returns The accumulated value after applying the reducer function to each entry.
*/
reduce<U>(reducer: (accumulator: U, value: V, key: K, collection: Collection<K, V>) => U, initialValue: U): U;
/**
* It checks if all entries in the Collection satisfy the provided predicate function.
* @param {Function} predicate - A predicate function that is called for each entry with arguments (value, key, collection).
* @returns A boolean value indicating whether all entries satisfy the predicate function.
*/
every(predicate: Predicate<V, K>): boolean;
/**
* It checks if any entry in the Collection satisfies the provided predicate function.
* @param {Function} predicate - A predicate function that is called for each entry with arguments (value, key, collection).
* @returns A boolean value indicating whether any entry satisfies the predicate function.
*/
some(predicate: Predicate<V, K>): boolean;
}
export {};