/// declare module "@proc7ts/primitives" { /** * Checks whether two values are the same. I.e. strictly equal to each other. * * @typeParam T - A type of values. * @param first - First value to compare. * @param second - Second value to compare. * * @returns `true` if `first === second`, or `false` otherwise. */ export function areTheSame(first: T, second: T): boolean; } declare module "@proc7ts/primitives" { /** * Asynchronous recipe of value evaluation. * * This is either a value as-is, a promise-like instance resolving to it, or its {@link AsyncRecipe.Evaluator evaluator} * function. * * @typeParam TValue - Evaluated value type. This can not be a function. * @typeParam TArgs - A type of parameters tuple required for value evaluation. */ export type AsyncRecipe = TValue | PromiseLike | AsyncRecipe.Evaluator; export namespace AsyncRecipe { /** * Asynchronous value evaluator signature. * * @typeParam TValue - Evaluated value type. This can not be a function. * @typeParam TArgs - A type of parameters tuple required for value evaluation. * @param args - Parameters required for value evaluation. * * @returns Either an valuated value, or a promise-like instance resolving to one. */ type Evaluator = (this: void, ...args: TArgs) => TValue | PromiseLike; } /** * Asynchronously evaluates a value by its recipe. * * @typeParam TValue - Evaluated value type. This can not be a function. * @typeParam TArgs - A type of parameters tuple required for value evaluation. * @param recipe - Asynchronous value evaluation recipe. * @param args - Parameters required for value evaluation. * * @returns A promise resolved to the value. */ export function asyncByRecipe(recipe: AsyncRecipe, ...args: TArgs): Promise; /** * Converts asynchronous value recipe to its {@link AsyncRecipe.Evaluator evaluator} function. * * @typeParam TValue - Evaluated value type. This can not be a function. * @typeParam TArgs - A type of parameters tuple required for value evaluation. * @param recipe - Asynchronous value recipe to convert. * * @returns A function asynchronously evaluating the value. */ export function asyncRecipe(recipe: AsyncRecipe): (this: void, ...args: TArgs) => Promise; } declare module "@proc7ts/primitives" { /** * Creates a provider of the only argument. * * @param value - A value to return. * * @returns A function that returns `value`. */ export function valueProvider(value: T): (this: void) => T; } declare module "@proc7ts/primitives" { /** * Creates a provider of lazily evaluated value. * * The returned function evaluates the value first time it is called. Then it just returns the previously evaluated one. * The failed value evaluation will be retried on the next call. * * @param provider - A no-arg function evaluating the value. * * @returns A function that returns the value evaluated by `provider`. */ export function lazyValue(provider: (this: void) => T): (this: void) => T; } declare module "@proc7ts/primitives" { /** * A recipe of value evaluation. * * This is either a value as-is, or its {@link ValueRecipe.Evaluator evaluator} function. * * @typeParam TValue - Evaluated value type. This can not be a function. * @typeParam TArgs - A type of parameters tuple required for value evaluation. */ export type ValueRecipe = TValue | ValueRecipe.Evaluator; export namespace ValueRecipe { /** * Value evaluator signature. * * @typeParam TValue - Evaluated value type. This can not be a function. * @typeParam TArgs - A type of parameters tuple required for value evaluation. * @param args - Parameters required for value evaluation. * * @returns Evaluated value. */ type Evaluator = (this: void, ...args: TArgs) => TValue; } /** * Evaluates a value by its recipe. * * @typeParam TValue - Evaluated value type. This can not be a function. * @typeParam TArgs - A type of parameters tuple required for value evaluation. * @param recipe - Value evaluation recipe. * @param args - Parameters required for value evaluation. * * @returns Either the value itself, or the one evaluated by the given evaluator recipe. */ export function valueByRecipe(recipe: ValueRecipe, ...args: TArgs): TValue; /** * Converts a value recipe to its {@link ValueRecipe.Evaluator evaluator} function. * * @typeParam TValue - Evaluated value type. This can not be a function. * @typeParam TArgs - A type of parameters tuple required for value evaluation. * @param recipe - Value recipe to convert. * * @returns Either evaluator itself, or the one evaluating to the given value. */ export function valueRecipe(recipe: ValueRecipe): ValueRecipe.Evaluator; } declare module "@proc7ts/primitives" { /** * Checks whether two arrays are equal. * * @typeParam TElement - Array element type. * @param first - First array to compare. * @param second - Second array to compare. * @param length - The maximum number of elements to compare. Defaults to array length. Negative value means `0`. * * @returns `true` if up to `length` corresponding array elements are strictly equal to each other. */ export function arraysAreEqual(first: ArrayLike, second: ArrayLike, length?: number | null): boolean; /** * Checks whether two array ranges are equal. * * @typeParam TElement - Array element type. * @param first - First array to compare. * @param second - Second array to compare. Negative or absent value means `0`. * @param from - The first element index to compare. Negative value means `0`. Absent value means array length. * @param to - The number one more than the last element index to compare. * * @returns `true` if all corresponding elements in corresponding array ranges are strictly equal to each other. */ export function arraysAreEqual(first: ArrayLike, second: ArrayLike, from: number | null | undefined, to: number | null): boolean; /** * Checks whether two arrays are equal by comparing corresponding elements with the given comparator function. * * @typeParam TElement - Array element type. * @param first - First array to compare. * @param elementsAreEqual - Array elements comparator. Accepts elements to compare and their index as arguments. * Returns `true` if elements are equal, or `false` otherwise. * @param second - Second array to compare. * @param length - The maximum number of elements to compare. Defaults to array length. * * @returns `true` if `elementsAreEqual` comparator returned `true` for up to `length` corresponding array element * pairs. */ export function arraysAreEqual(first: ArrayLike, second: ArrayLike, elementsAreEqual: (this: void, first: TElement, second: TElement, index: number) => boolean, length?: number | null): boolean; /** * Checks whether two array ranges are equal by comparing corresponding elements with the given comparator function. * * @typeParam TElement - Array element type. * @param first - First array to compare. * @param elementsAreEqual - Array elements comparator. Accepts elements to compare and their index as arguments. * Returns `true` if elements are equal, or `false` otherwise. * @param second - Second array to compare. * @param from - The first element index to compare. Negative value means `0`. Absent value means array length. * @param to - The number one more than the last element index to compare. * * @returns `true` if `elementsAreEqual` comparator returned `true` for up to `length` corresponding array element * pairs. */ export function arraysAreEqual(first: ArrayLike, second: ArrayLike, elementsAreEqual: (this: void, first: TElement, second: TElement, index: number) => boolean, from: number | null | undefined, to: number | null): boolean; } declare module "@proc7ts/primitives" { /** * Checks whether the given value is an array. * * @typeParam TElement - Array element type. * @typeParam TOther - Non-array value type the `value` may have. * @param value - Either element, array of elements, `null`, or `undefined`. * * @returns `true` if the given `value` is an array, or `false` otherwise. */ export function isArray(value: TElement[] | TOther): value is TElement[]; /** * Checks whether the given value is a readonly array. * * @typeParam TElement - Array element type. * @typeParam TOther - Non-array value type the `value` may have. * @param value - Either element, readonly array of elements, `null`, or `undefined`. * * @returns `true` if the given `value` is an array, or `false` otherwise. */ export function isArray(value: readonly TElement[] | TOther): value is readonly TElement[]; } declare module "@proc7ts/primitives" { /** * Checks whether the given value may have properties. * * @param value - The value to check. * * @returns `true` if the `value` is either a non-null object or function, or `false` otherwise. */ export function mayHaveProperties(value: unknown): value is object; } declare module "@proc7ts/primitives" { /** * Checks whether the given object is iterable. * * @typeParam TElement - Iterable elements type. * @typeParam TOther - Non-iterable type the `value` may have. * @param value - An object value to check. * * @returns `true` if the `value` has a `[Symbol.iterator]` method, or `false` otherwise. */ export function isIterable(value: Iterable | TOther): value is Iterable; } declare module "@proc7ts/primitives" { /** * Converts element or array to array of elements. * * @typeParam TElement - Array element type. * @param value - Either element, array of elements, iterable of elements, `null`, or `undefined`. * * @returns The `value` itself if it is an array, empty array if `value` is `null` or `undefined`, array consisting of * iterable `value` elements, or an array containing only `value` otherwise. */ export function asArray(value: TElement | TElement[] | Iterable | null | undefined): TElement[]; /** * Converts element or readonly array of elements to readonly array of elements. * * @typeParam TElement - Array element type. * @param value - Either element, readonly array of elements, `null`, or `undefined`. * * @returns The `value` itself if it is an array, empty array if the `value` is `null` or `undefined`, or an array * containing only `value` otherwise. */ export function asArray(value: TElement | readonly TElement[] | null | undefined): readonly TElement[]; } declare module "@proc7ts/primitives" { /** * Builds element or array of the given elements. * * @param source - A source of elements as their iterable or array-like container. * * @returns The only element of the `source`, an array of all elements of non-empty source, or `undefined` if the * `source` is empty. */ export function elementOrArray(source: Iterable | ArrayLike): T | T[] | undefined; } declare module "@proc7ts/primitives" { /** * Abstract constructor. * * @typeParam T - Constructed instance type. */ export type AbstractConstructor = abstract new (...args: unknown[]) => T; /** * Abstract class constructor. * * @typeParam T - A type of class instance. */ export interface AbstractClass extends AbstractConstructor { prototype: T; } } declare module "@proc7ts/primitives" { /** * Arbitrary constructor. * * @typeParam T - Constructed instance type. */ export type Constructor = new (...args: unknown[]) => T; /** * Arbitrary class constructor. * * @typeParam T - A type of class instance. */ export interface Class extends Constructor { new (...args: unknown[]): T; prototype: T; } } declare module "@proc7ts/primitives" { /** * Detects a super class of the given class optionally satisfying the given criteria. * * Traverses all class ancestors until reaches the one satisfying the given criteria, or stops when there is no more * ancestors. * * @param type - The class constructor to find super class of. * @param satisfying - The criteria of super class matching. It is a function accepting a super class constructor * as the only parameter and returning `true` if the given super class matches, or `false` otherwise. Always returns * `true` by default. * * @return A super class `satisfying` the given criteria, or `undefined` if there is no such super class, or there is no * super class at all (e.g. when `Object` is passed in). */ export function superClassOf(type: AbstractClass, satisfying?: (this: void, type: AbstractClass) => boolean): AbstractClass | undefined; } declare module "@proc7ts/primitives" { /** * Builds a set of the given element or array. * * @typeParam TElement - Type of elements in the set. * @param elements Either element, iterable of elements, `null`, or `undefined`. * * @returns A new set containing all the given elements, or empty set if `elements` is `null` or `undefined`. */ export function asSet(elements: TElement | Iterable | null | undefined): Set; } declare module "@proc7ts/primitives" { /** * A function that returns its argument as is. * * @param value - A value to return. * * @returns `value`. */ export function asis(value: T): T; } declare module "@proc7ts/primitives" { /** * Counts meaningful arguments passed to function. * * Ignores trailing `undefined` values. * * @param args - Function call arguments tuple. * * @returns The number of arguments, except for the trailing `undefined` values. */ export function countArgs(args: ArrayLike): number; } declare module "@proc7ts/primitives" { /** * Merges two functions by calling one after another. * * Optionally merges function call results. * * @typeParam TArgs - Function parameter types as tuple. * @typeParam TReturn - A type of function result. * @typeParam TThis - A type if `this` object expected by function. * @param first - The first function to call. * @param second - The second function to call. * @param merge - Optional function call results merger. Accepts two function results as arguments and returns the final * result. When omitted the first function call result is ignored and the second function's call result is returned. * * @return A function that calls both of the given ones and merges their results. If one of the functions is absent, * then just returns another one. If both are absent, then returns `undefined`. */ export function mergeFunctions(first: (this: TThis, ...args: TArgs) => TReturn, second: ((this: TThis, ...args: TArgs) => TReturn) | undefined, merge: (first: TReturn, second: TReturn) => TReturn): (this: TThis, ...args: TArgs) => TReturn; export function mergeFunctions(first: ((this: TThis, ...args: TArgs) => TReturn) | undefined, second: (this: TThis, ...args: TArgs) => TReturn, merge?: (first: TReturn, second: TReturn) => TReturn): (this: TThis, ...args: TArgs) => TReturn; export function mergeFunctions(first: ((this: TThis, ...args: TArgs) => TReturn) | undefined, second: ((this: TThis, ...args: TArgs) => TReturn) | undefined, merge?: (first: TReturn, second: TReturn) => TReturn): ((this: TThis, ...args: TArgs) => TReturn) | undefined; } declare module "@proc7ts/primitives" { /** * A function that does nothing. * * @returns `undefined`. */ export function noop(): undefined; } declare module "@proc7ts/primitives" { /** * Checks whether the `target` object has own property with the given `key`. * * This is a safer variant of `target.hasOwnProperty(key)` call. * * @param target - Target object to check. * @param key - A key of the property to check. * * @returns `true` if `target` object has own property with the given `key`, or `false` otherwise. * * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty */ export function hasOwnProperty(target: object, key: PropertyKey): boolean; } declare module "@proc7ts/primitives" { /** * Checks whether two objects have equal properties. * * @typeParam - A type of objects to check. * @param first - First object to check. * @param second - Second object to check. * @param valuesAreEqual - A function that compares corresponding property values. Accepts property values from both * objects and their key as parameters. Returns `true` if property values are equal. By default, checks property values * for {@link areTheSame strict equality}. * @param keys - Either an iterable of property keys to compare, or a function returning one. Defaults to own keys * (`Reflect.ownKeys`) of both objects. * * @returns `true` if `valuesAreEqual` returned `true` for each property key, or `false` otherwise. */ export function propertiesAreEqual(first: TObject, second: TObject, valuesAreEqual?: ((this: void, first: TObject[TPropertyKey], second: TObject[TPropertyKey], key: TPropertyKey) => boolean) | null, keys?: Iterable | ((this: void, first: TObject, second: TObject) => Iterable)): boolean; } declare module "@proc7ts/primitives" { /** * Checks whether the given value is array-like. * * @typeParam TElement - Array elements type. * @typeParam TOther - Non-array type the `value` may have. * @param value - A value to check. * * @returns `true` if the `value` has a `length` property, or `false` otherwise. */ export function isArrayLike(value: ArrayLike | TOther): value is ArrayLike; } declare module "@proc7ts/primitives" { /** * Checks if the given object is a promise-like instance. * * @typeParam TResolved - A type of the value the promise resolves to. * @typeParam TOther - A type of the plain, not promise-like, value. * @param value - A value to check. * * @returns `true` if the `value` is an object or function with `then` method, or `false` otherwise. */ export function isPromiseLike(value: PromiseLike | TOther): value is PromiseLike; } declare module "@proc7ts/primitives" { /** * Checks whether the given `value` is present. * * @typeParam T - Type of the present value. * @param value - A value to check. * * @returns `true` when the given `value` is not `null` or `undefined`, or `false` otherwise. */ export function isPresent(value: T | undefined | null): value is T; /** * Checks whether the given `value` is not present. * * This is a direct opposite to {@link isPresent()}. * * @typeParam T - Type of the present value. * @param value - A value to check. * * @returns `true` when the given `value` is `null` or `undefined`, or `false` otherwise. */ export function isNotPresent(value: T | undefined | null): value is undefined | null; /** * Checks whether the given `value` is defined. * * @typeParam T - Type of the defined value. * @param value - A value to check. * * @returns `true` when `value !== undefined`, or `false` otherwise. */ export function isDefined(value: T | undefined): value is T; /** * Checks whether the given `value` is `undefined`. * * This is a direct opposite to {@link isDefined}. * * @typeParam T - Type of the defined value. * @param value - A value to check. * * @returns `true` when `value === undefined`, or `false` otherwise. */ export function isUndefined(value: T | undefined): value is undefined; /** * Checks whether the given `value` is not `null`. * * @typeParam T - Type of the defined value. * @param value - A value to check. * * @returns `true` when `value !== null`, or `false` otherwise. */ export function isNotNull(value: T | undefined): value is T; /** * Checks whether the given `value` is `null`. * * This is a direct opposite to {@link isNotNull}`. * * @typeParam T - Type of the defined value. * @param value - A value to check. * * @returns `true` when `value === null`, or `false` otherwise. */ export function isNull(value: T | undefined): value is undefined; } //# sourceMappingURL=primitives.d.ts.map