import { Observable } from 'rxjs'; /** * Provides utility methods to work with `undefined` values. The value `null` is considered as a defined value. * * Note: TypeScript 3.7 introduces the `nullish coalescing operator` [1] `(??)`, which is similar to the `Defined` function, * but also applies for `null` values. * * ## Links: * [1] https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#nullish-coalescing */ declare namespace Defined { /** * Returns the value if not `undefined`, otherwise "orElseValue". The "orElseValue" value can be created with a factory function. * * Unlike JavaScript's "nullish coalescing operator (??)", the "orElse" function only tests for `undefined`, not `null`. */ function orElse(value: T | undefined, orElseValue: T | (() => T)): T; /** * Returns the value if not `undefined`, otherwise throws the error created by the passed factory function. */ function orElseThrow(value: T | undefined, orElseThrowFn: () => Error): T; } /** * Provides array utility methods. */ declare namespace Arrays { /** * Returns the value, if an array, or adds it to an array. If `null` or `undefined` is given, by default, returns an empty array. */ function coerce(value: T | T[] | readonly T[] | null | undefined, options?: { coerceNullOrUndefined: true; }): NonNullable; function coerce(value: T | T[] | readonly T[] | null | undefined, options: { coerceNullOrUndefined: false; }): T[] | null | undefined; /** * Compares items of given arrays for reference equality. * * Use the parameter `exactOrder` to control if the item order must be equal (which is by default) or not. * * @deprecated since version 2.1.0; use {@link Objects.isEqual} instead; API will be removed in version 3.0.0. */ function isEqual(array1: any[] | null | undefined, array2: any[] | null | undefined, options?: { exactOrder?: boolean; }): boolean; /** * Removes the specified element from an array, or the elements which satisfy the provided predicate function. * The original array will be changed. * * @param array - The array from which elements should be removed. * @param element - The element to be removed, or a predicate function to resolve elements which to be removed. * @param options - Control if to remove all occurrences of the element. If not specified, all occurrences are removed. * @return the elements removed from the array. */ function remove(array: T[], element: T | ((element: T) => boolean), options?: { firstOnly: boolean; }): T[]; /** * Removes duplicate items from the array. The original array will not be modified. * * Use the parameter `keySelector` to provide a function for comparing objects. */ function distinct(items: T[] | readonly T[], keySelector?: (item: T) => any): T[]; /** * Intersects the given arrays, returning a new array containing all the elements contained in every array. * Arrays which are `undefined` or `null` are ignored. */ function intersect(...arrays: Array): T[]; /** * Returns the last element in the given array, optionally matching the predicate if given. * * Returns `undefined` if no element is found. */ function last(array: T[] | readonly T[] | null | undefined, predicate?: (item: T) => boolean): T | undefined; } /** * Provides helper functions for working with objects. */ declare const Objects: { /** * Compares two objects for deep equality. * * Supported types: Record, Array, Map, Set, and primitives. * * The property order is ignored when comparing records. The element order in arrays is relevant unless specified otherwise in options. * * @param a - The first object to compare. * @param b - The second object to compare. * @param options - Controls how to compare two objects. * @param options.ignoreArrayOrder - Controls whether to ignore the element order when comparing arrays. By default, the order is not ignored. * @return `true` if objects are equal, false otherwise. */ readonly isEqual: (a: unknown, b: unknown, options?: { ignoreArrayOrder?: true; }) => boolean; /** * Stringifies given object to matrix notation: a=b;c=d;e=f */ readonly toMatrixNotation: (object: Record | null | undefined) => string; /** * Like {@link Object.keys}, but preserving the data type of keys. */ readonly keys: (object: T) => P[]; /** * Like {@link Object.values}, but preserving the data type of values and supporting optional properties. */ readonly values: (object: T) => Array; /** * Like {@link Object.entries}, but preserving the data type of keys and supporting optional properties. */ readonly entries: (object: T) => Array<[P, T[P]]>; }; /** * Provides utilities for a dictionary. */ declare namespace Dictionaries { /** * Creates a {@link Dictionary} from the given dictionary-like object. If given a `Dictionary`, it is returned. If given `null` or `undefined`, by default, returns an empty {@link Dictionary}. */ function coerce(dictionaryLike: Dictionary | Map | Iterable<[string, T]> | undefined | null, options?: { coerceNullOrUndefined: true; }): NonNullable>; function coerce(dictionaryLike: Dictionary | Map | Iterable<[string, T]> | undefined | null, options: { coerceNullOrUndefined: false; }): Dictionary | null | undefined; /** * Returns a new {@link Dictionary} with `undefined` values removed. */ function withoutUndefinedEntries(object: Dictionary): Dictionary; } /** * Represents an object with a variable number of properties, whose keys are not known at development time. */ interface Dictionary { [key: string]: T; } /** * Provides utilities for {@link Map}. */ declare namespace Maps { /** * Creates a {@link Map} from the given map-like object. If given a `Map`, it is returned. If given `null` or `undefined`, by default, returns an empty {@link Map}. */ function coerce(mapLike: Map | Dictionary | Iterable<[string, T]> | undefined | null, options?: { coerceNullOrUndefined: true; }): NonNullable>; function coerce(mapLike: Map | Dictionary | Iterable<[string, T]> | undefined | null, options: { coerceNullOrUndefined: false; }): Map | null | undefined; /** * Adds the given value into a {@link Set} in the multi value {@link Map}. */ function addSetValue(multiValueMap: Map>, key: K, value: V): Map>; /** * Removes the given value or values matching the given predicate from the multi {@link Map}. * * @return `true` if the element was removed, or `false` otherwise. */ function removeSetValue(multiValueMap: Map>, key: K, value: V | PredicateFn): boolean; /** * Adds the given value into an {@link Array} in the multi value {@link Map}. */ function addListValue(map: Map, key: K, value: V): Map; /** * Removes the given value or values matching the given predicate from the multi {@link Map}. * * @return `true` if the element was removed, or `false` otherwise. */ function removeListValue(multiValueMap: Map, key: K, value: V | PredicateFn): boolean; } /** * Represents a predicate function which returns `true` or `false`. */ type PredicateFn = (value: T) => boolean; declare namespace Observables { /** * Creates an `Observable` from the passed value, which will emit the value and then complete, * or, if passing an `Observable`, returns it unchanged. If passing a `Promise`, it is converted * to an `Observable`. */ function coerce(value: T | Observable | Promise): Observable; } export { Arrays, Defined, Dictionaries, Maps, Objects, Observables }; export type { Dictionary, PredicateFn };