//#region src/models.d.ts /** * A generic array or object */ type ArrayOrPlainObject = unknown[] | Record; /** * An asynchronous callback that can be canceled */ type AsyncCancelableCallback = (ReturnType extends Promise ? (...args: Parameters) => Promise>> : (...args: Parameters) => Promise>) & { /** * Cancel the callback */ cancel: () => void; }; /** * For matching any `void`, `Date`, primitive, or `RegExp` values * * _(Thanks, type-fest!)_ */ type BuiltIns = void | Date | Primitive | RegExp; /** * A synchronous callback that can be canceled */ type CancelableCallback = Callback & { /** * Cancel the callback */ cancel: () => void; }; /** * A generic class constructor */ type Constructor = new (...args: any[]) => Instance; /** * Position of an event */ type EventPosition = { x: number; y: number; }; /** * A generic async callback function */ type GenericAsyncCallback = (...args: any[]) => Promise; /** * A generic callback function */ type GenericCallback = (...args: any[]) => any; /** * A generic key type */ type Key$1 = number | string; type KeyedValue = Item[ItemKey] extends PropertyKey ? Item[ItemKey] : never; /** * A nested array */ type NestedArray = Value extends Array ? NestedArray : Value; /** * All nested keys of an object as dot notation strings _(up to 5 levels deep)_ */ type NestedKeys = _NestedKeys; type _NestedKeys = Depth extends 0 ? never : Value extends readonly any[] ? Value extends readonly [any, ...any] ? { [ItemKey in keyof Value]-?: ItemKey extends `${number}` ? NonNullable extends readonly any[] | PlainObject ? `${ItemKey}` | `${ItemKey}.${_NestedKeys, SubtractDepth>}` : `${ItemKey}` : never }[number] : never : Value extends PlainObject ? { [ItemKey in keyof Value]-?: ItemKey extends number | string ? NonNullable extends readonly any[] | PlainObject ? `${ItemKey}` | `${ItemKey}.${_NestedKeys, SubtractDepth>}` : `${ItemKey}` : never }[keyof Value] : never; /** * An extended version of `Partial` that allows for nested properties to be optional */ type NestedPartial = { [ItemKey in keyof Value]?: Value[ItemKey] extends object ? NestedPartial : Value[ItemKey] }; /** * The value for a nested key of an object */ type NestedValue = _NestedValue; type _NestedValue = Path extends `${infer ItemKey}.${infer Rest}` ? ItemKey extends keyof Value ? undefined extends Value[ItemKey] ? _NestedValue, Rest> | undefined : _NestedValue : ItemKey extends `${number}` ? Value extends readonly any[] ? _NestedValue : never : never : Path extends `${number}` ? Value extends readonly any[] ? Value[number] : never : Path extends keyof Value ? Value[Path] : never; /** * The nested _(keyed)_ values of an object _(up to 5 levels deep)_ */ type NestedValues = { [Path in NestedKeys]: NestedValue }; /** * The numerical keys of an object */ type NumericalKeys = { [ItemKey in keyof Value]: ItemKey extends number ? ItemKey : ItemKey extends `${number}` ? ItemKey : never }[keyof Value]; /** * The numerical values of an object */ type NumericalValues = { [ItemKey in keyof Item as Item[ItemKey] extends number ? ItemKey : never]: Item[ItemKey] }; /** * An asynchronous function that can only be called once, returning the same value on subsequent calls */ type OnceAsyncCallback = { /** * Did the callback's promise reject? */ readonly error: boolean; /** * Has the callback finished? */ readonly finished: boolean; } & Callback & OnceCallbackProperties; /** * A callback function that can only be called once, returning the same value on subsequent calls */ type OnceCallback = Callback & OnceCallbackProperties; type OnceCallbackProperties = { /** * Has the callback been called? */ readonly called: boolean; /** * Has the callback's value been cleared? */ readonly cleared: boolean; /** * Clear the callback's cached value */ clear: () => void; }; /** * A generic object */ type PlainObject = Record; /** * A primitive value * * _(Thanks, type-fest!)_ */ type Primitive = null | undefined | string | number | boolean | symbol | bigint; /** * Set required keys for a type */ type RequiredKeys = Required> & Omit; /** * Flattens the type to improve type hints in IDEs * * _(Thanks, type-fest!)_ */ type Simplify = { [ValueKey in keyof Value]: Value[ValueKey] } & {}; type SubtractDepth = Value extends 5 ? 4 : Value extends 4 ? 3 : Value extends 3 ? 2 : Value extends 2 ? 1 : Value extends 1 ? 0 : never; /** * Get the value's type as a string * * _(Thanks, type-fest!)_ */ type ToString = Value extends string | number ? `${Value}` : never; /** * A union type of all typed arrays */ type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array; /** * Converts a union type to an intersection type * * @example * ```typescript * type A = {a: string}; * type B = {b: number}; * type C = UnionToIntersection; // => {a: string} & {b: number} * ``` * * Thanks, type-fest! */ type UnionToIntersection = (Union extends unknown ? (distributedUnion: Union) => void : never) extends ((mergedIntersection: infer Intersection) => void) ? Intersection & Union : never; //#endregion //#region src/array/filter.d.ts /** * Get a filtered array of items that do not match the value * * _Available as `exclude` and `filter.remove`_ * * @param array Array to search in * @param callback Callback to get an item's value for matching * @param value Value to match against * @returns Filtered array of items that do not match the filter * * @example * ```typescript * exclude( * [{id: 1}, {id: 2}, {id: 3}], * item => item.id, * 2, * ); // => [{id: 1}, {id: 3}] * ``` */ declare function exclude unknown>(array: Item[], callback: Callback, value: ReturnType): unknown[]; /** * Get a filtered array of items that do not match the value * * _Available as `exclude` and `filter.remove`_ * * @param array Array to search in * @param key Key to get an item's value for matching * @param value Value to match against * @returns Filtered array of items that do not match the filter * * @example * ```typescript * exclude( * [{id: 1}, {id: 2}, {id: 3}], * 'id', * 2, * ); // => [{id: 1}, {id: 3}] * ``` */ declare function exclude(array: Item[], key: ItemKey, value: Item[ItemKey]): unknown[]; /** * Get a filtered array of items that do not match the filter * * _Available as `exclude` and `filter.remove`_ * * @param array Array to search in * @param filter Filter callback to match items * @returns Filtered array of items that do not match the filter * * @example * ```typescript * exclude( * [{id: 1}, {id: 2}, {id: 3}], * item => item.id === 2, * ); // => [{id: 1}, {id: 3}] * ``` */ declare function exclude(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): unknown[]; /** * Get a filtered array of items that do not match the given item * * _Available as `exclude` and `filter.remove`_ * * @param array Array to search in * @param item Item to match against * @returns Filtered array of items that do not match the given item * * @example * ```typescript * exclude([1, 2, 3], 2); // => [1, 3] * ``` */ declare function exclude(array: Item[], item: Item): unknown[]; /** * Get a filtered array of items * * @param array Array to search in * @param callback Callback to get an item's value for matching * @param value Value to match against * @returns Filtered array of items * * @example * ```typescript * filter( * [{id: 1}, {id: 2}, {id: 3}], * item => item.id, * 2, * ); // => [{id: 2}] * ``` */ declare function filter unknown>(array: Item[], callback: Callback, value: ReturnType): Item[]; /** * Get a filtered array of items * * @param array Array to search in * @param key Key to get an item's value for matching * @param value Value to match against * @returns Filtered array of items * * @example * ```typescript * filter( * [{id: 1}, {id: 2}, {id: 3}], * 'id', * 2, * ); // => [{id: 2}] * ``` */ declare function filter(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[]; /** * Get a filtered array of items matching the filter * * @param array Array to search in * @param filter Filter callback to match items * @returns Filtered array of items * * @example * ```typescript * filter( * [{id: 1}, {id: 2}, {id: 3}], * item => item.id === 2, * ); // => [{id: 2}] * ``` */ declare function filter(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item[]; /** * Get a filtered array of items matching the given item * * @param array Array to search in * @param item Item to match against * @returns Filtered array of items * * @example * ```typescript * filter([1, 2, 3], 2); // => [2] * ``` */ declare function filter(array: Item[], item: Item): Item[]; declare namespace filter { var remove: typeof exclude; } //#endregion //#region src/array/first.d.ts /** * Get the first item matching the given value * * @param array Array to search in * @param callback Callback to get an item's value for matching * @param value Value to match against * @returns First item that matches the value, or `undefined` if no match is found * * @example * ```typescript * first( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * 10, * ); // => {id: 1, value: 10} * ``` */ declare function first unknown>(array: Item[], callback: Callback, value: ReturnType): Item | undefined; /** * Get the first item matching the given value by key * * @param array Array to search in * @param key Key to get an item's value for matching * @param value Value to match against * @returns First item that matches the value, or `undefined` if no match is found * * @example * ```typescript * first( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * 10, * ); // => {id: 1, value: 10} * ``` */ declare function first(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined; /** * Get the first item matching the filter * * @param array Array to search in * @param filter Filter callback to match items * @returns First item that matches the filter, or `undefined` if no match is found * * @example * ```typescript * first( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value === 10, * ); // => {id: 1, value: 10} * ``` */ declare function first(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item | undefined; /** * Get the first item from an array * * @param array Array to get from * @returns First item from the array, or `undefined` if the array is empty * * @example * ```typescript * first( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * ); // => {id: 1, value: 10} * ``` */ declare function first(array: Item[]): Item | undefined; declare namespace first { var _a: typeof firstOrDefault; export { _a as default }; } /** * Get the first item matching the given value, or a default value if no match is found * * _Available as `firstOrDefault` and `first.default`_ * * @param array Array to search in * @param defaultValue Default value to return if no match is found * @param callback Callback to get an item's value for matching * @param value Value to match against * @returns First item that matches the value, or the default value if no match is found * * @example * ```typescript * firstOrDefault( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * {id: -1, value: 30}, * item => item.value, * 30, * ); // => {id: -1, value: 30} * ``` */ declare function firstOrDefault unknown>(array: Item[], defaultValue: Item, callback: Callback, value: ReturnType): Item; /** * Get the first item matching the given value by key, or a default value if no match is found * * _Available as `firstOrDefault` and `first.default`_ * * @param array Array to search in * @param defaultValue Default value to return if no match is found * @param key Key to get an item's value for matching * @param value Value to match against * @returns First item that matches the value, or the default value if no match is found * * @example * ```typescript * firstOrDefault( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * {id: -1, value: 30}, * 'value', * 30, * ); // => {id: -1, value: 30} * ``` */ declare function firstOrDefault(array: Item[], defaultValue: Item, key: ItemKey, value: Item[ItemKey]): Item; /** * Get the first item matching the filter, or a default value if no match is found * * _Available as `firstOrDefault` and `first.default`_ * * @param array Array to search in * @param defaultValue Default value to return if no match is found * @param filter Filter callback to match items * @returns First item that matches the filter, or the default value if no match is found * * @example * ```typescript * firstOrDefault( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * {id: -1, value: 30}, * item => item.value === 30, * ); // => {id: -1, value: 30} * ``` */ declare function firstOrDefault(array: Item[], defaultValue: Item, filter: (item: Item, index: number, array: Item[]) => boolean): Item; /** * Get the first item from an array, or a default value if the array is empty * * _Available as `firstOrDefault` and `first.default`_ * * @param array Array to get from * @param defaultValue Default value to return if the array is empty * @returns First item from the array, or the default value if the array is empty * * @example * ```typescript * firstOrDefault([], {id: -1, value: 30}); // => {id: -1, value: 30} * ``` */ declare function firstOrDefault(array: Item[], defaultValue: Item): Item; //#endregion //#region src/array/group-by.d.ts /** * Create a record from an array of items using a specific key and value * * If multiple items have the same key, the latest item's value will be used * * @param array Array to group * @param key Callback to get an item's grouping key * @param value Callback to get an item's value * @returns Record of keyed values * * @example * ```typescript * groupBy( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * item => item, * ); // => {10: {id: 3, value: 10}, 20: {id: 2, value: 20}} * ``` */ declare function groupBy Key$1, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Simplify, ReturnType>>; /** * Create a record from an array of items using a specific key and value * * If multiple items have the same key, the latest item's value will be used * * @param array Array to group * @param key Callback to get an item's grouping key * @param value Key to use for value * @returns Record of keyed values * * @example * ```typescript * groupBy( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * 'id' * ); // => {10: 3, 20: 2} * ``` */ declare function groupBy Key$1, ItemValue extends keyof Item>(array: Item[], key: KeyCallback, value: ItemValue): Record, Item[ItemValue]>; /** * Create a record from an array of items using a specific key and value * * If multiple items have the same key, the latest item's value will be used * * @param array Array to group * @param key Key to use for grouping * @param value Callback to get an item's value * @returns Record of keyed values * * @example * ```typescript * groupBy( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * item => item, * ); // => {10: {id: 3, value: 10}, 20: {id: 2, value: 20}} * ``` */ declare function groupBy unknown>(array: Item[], key: ItemKey, value: ValueCallback): Simplify, ReturnType>>; /** * Create a record from an array of items using a specific key and value * * If multiple items have the same key, the latest item's value will be used * * @param array Array to group * @param key Key to use for grouping * @param value Key to use for value * @returns Record of keyed values * * @example * ```typescript * groupBy( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * 'id' * ); // => {10: 3, 20: 2} * ``` */ declare function groupBy(array: Item[], key: ItemKey, value: ItemValue): Simplify, Item[ItemValue]>>; /** * Create a record from an array of items using a specific key * * If multiple items have the same key, the latest item will be used * * @param array Array to group * @param callback Callback to get an item's grouping key * @returns Record of keyed items * * @example * ```typescript * groupBy( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * ); // => {10: {id: 3, value: 10}, 20: {id: 2, value: 20}} * ``` */ declare function groupBy Key$1>(array: Item[], callback: Callback): Record, Item>; /** * Create a record from an array of items using a specific key * * If multiple items have the same key, the latest item will be used * * @param array Array to group * @param key Key to use for grouping * @returns Record of keyed items * * @example * ```typescript * groupBy( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * ); // => {10: {id: 3, value: 10}, 20: {id: 2, value: 20}} * ``` */ declare function groupBy(array: Item[], key: ItemKey): Simplify, Item>>; /** * Create a record from an array of items _(using indices as keys)_ * * @param array Array to group * @returns Record of indiced items * * @example * ```typescript * groupBy( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * ); // => {0: {id: 1, value: 10}, 1: {id: 2, value: 20}, 2: {id: 3, value: 10}} * ``` */ declare function groupBy(array: Item[]): Record; declare namespace groupBy { var arrays: typeof groupArraysBy; } /** * Create a record from an array of items using a specific key and value, grouping values into arrays * * _Available as `groupArraysBy` and `groupBy.arrays`_ * * @param array Array to group * @param key Callback to get an item's grouping key * @param value Callback to get an item's value * @returns Record of keyed values * * @example * ```typescript * groupArraysBy( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * item => item, * ); // => { * // 10: [{id: 1, value: 10}, {id: 3, value: 10}], * // 20: [{id: 2, value: 20}], * // } * ``` */ declare function groupArraysBy Key$1, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Record, ReturnType[]>; /** * Create a record from an array of items using a specific key and value, grouping values into arrays * * _Available as `groupArraysBy` and `groupBy.arrays`_ * * @param array Array to group * @param key Callback to get an item's grouping key * @param value Key to use for value * @returns Record of keyed values * * @example * ```typescript * groupArraysBy( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * 'id', * ); // => { * // 10: [1, 3], * // 20: [2], * // } * ``` */ declare function groupArraysBy Key$1, ItemValue extends keyof Item>(array: Item[], key: KeyCallback, value: ItemValue): Record, Item[ItemValue][]>; /** * Create a record from an array of items using a specific key and value, grouping values into arrays * * _Available as `groupArraysBy` and `groupBy.arrays`_ * * @param array Array to group * @param key Key to use for grouping * @param value Callback to get an item's value * @returns Record of keyed values * * @example * ```typescript * groupArraysBy( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * item => item, * ); // => { * // 10: [{id: 1, value: 10}, {id: 3, value: 10}], * // 20: [{id: 2, value: 20}], * // } * ``` */ declare function groupArraysBy unknown>(array: Item[], key: ItemKey, value: ValueCallback): Simplify, ReturnType[]>>; /** * Create a record from an array of items using a specific key and value, grouping values into arrays * * _Available as `groupArraysBy` and `groupBy.arrays`_ * * @param array Array to group * @param key Key to use for grouping * @param value Key to use for value * @returns Record of keyed values * * @example * ```typescript * groupArraysBy( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * 'id', * ); // => { * // 10: [1, 3], * // 20: [2], * // } * ``` */ declare function groupArraysBy(array: Item[], key: ItemKey, value: ItemValue): Simplify, Item[ItemValue][]>>; /** * Create a record from an array of items using a specific key, grouping items into arrays * * _Available as `groupArraysBy` and `groupBy.arrays`_ * * @param array Array to group * @param callback Callback to get an item's grouping key * @returns Record of keyed items * * @example * ```typescript * groupArraysBy( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * ); // => { * // 10: [{id: 1, value: 10}, {id: 3, value: 10}], * // 20: [{id: 2, value: 20}], * // } * ``` */ declare function groupArraysBy Key$1>(array: Item[], callback: Callback): Record, Item[]>; /** * Create a record from an array of items using a specific key, grouping items into arrays * * _Available as `groupArraysBy` and `groupBy.arrays`_ * * @param array Array to group * @param key Key to use for grouping * @returns Record of keyed items * * @example * ```typescript * groupArraysBy( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * ); // => { * // 10: [{id: 1, value: 10}, {id: 3, value: 10}], * // 20: [{id: 2, value: 20}], * // } * ``` */ declare function groupArraysBy(array: Item[], key: ItemKey): Simplify, Item[]>>; //#endregion //#region src/internal/array/chunk.d.ts /** * Chunk an array into smaller arrays * * @param array Array to chunk * @param size Size of each chunk _(minimum is `1`, maximum is `5000`; defaults to `5000`)_ * @returns Array of arrays * * @example * ```typescript * chunk([1, 2, 3, 4, 5], 2); // => [[1, 2], [3, 4], [5]] * ``` */ declare function chunk(array: Item[], size?: number): Item[][]; //#endregion //#region src/internal/array/compact.d.ts /** * Compact an array _(removing all false-y values)_ * * @param array Array to compact * @param strict True to remove all false-y values * @returns Compacted array * * @example * ```typescript * compact([0, 1, '', 'hello', false, true, null, undefined]); // => [1, 'hello', true] * ``` */ declare function compact(array: Item[], strict: true): Exclude[]; /** * Compact an array _(removing all `null` and `undefined` values)_ * * @param array Array to compact * @returns Compacted array * * @example * ```typescript * compact([0, 1, '', 'hello', false, true, null, undefined]); // => [0, 1, '', 'hello', false, true] * ``` */ declare function compact(array: Item[]): Exclude[]; //#endregion //#region src/internal/array/index-of.d.ts /** * Get the index of the first matching item by callback * * @param array Array to search in * @param callback Callback to get an item's value * @param value Value to match against * @returns Index of the first matching item, or `-1` if no match is found * * @example * ```typescript * indexOf( * [{id: 1}, {id: 2}, {id: 3}], * item => item.id, * 2, * ); // => 1 * ``` */ declare function indexOf unknown>(array: Item[], callback: Callback, value: ReturnType): number; /** * Get the index of the first matching item by key * * @param array Array to search in * @param key Key to match items by * @param value Value to match against * @returns Index of the first matching item, or `-1` if no match is found * * @example * ```typescript * indexOf( * [{id: 1}, {id: 2}, {id: 3}], * 'id', * 2, * ); // => 1 * ``` */ declare function indexOf(array: Item[], key: ItemKey, value: Item[ItemKey]): number; /** * Get the index of the first item matching the filter * * @param array Array to search in * @param filter Filter callback to match items * @returns Index of the first matching item, or `-1` if no match is found * * @example * ```typescript * indexOf( * [{id: 1}, {id: 2}, {id: 3}], * item => item.id === 2, * ); // => 1 * ``` */ declare function indexOf(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): number; /** * Get the index of the first item matching the given item * * @param array Array to search in * @param item Item to match against * @returns Index of the first matching item, or `-1` if no match is found * * @example * ```typescript * indexOf([1, 2, 3, 4, 5], 3); // => 2 * ``` */ declare function indexOf(array: Item[], item: Item): number; declare namespace indexOf { var last: typeof lastIndexOf; } /** * Get the index of the last matching item by callback * * _Available as `lastIndexOf` and `indexOf.last`_ * * @param array Array to search in * @param callback Callback to get an item's value * @param value Value to match against * @returns Index of the last matching item, or `-1` if no match is found * * @example * ```typescript * lastIndexOf( * [{id: 1}, {id: 2}, {id: 3}, {id: 2}], * item => item.id, * 2, * ); // => 3 * ``` */ declare function lastIndexOf unknown>(array: Item[], callback: Callback, value: ReturnType): number; /** * Get the index of the last matching item by key * * _Available as `lastIndexOf` and `indexOf.last`_ * * @param array Array to search in * @param key Key to match items by * @param value Value to match against * @returns Index of the last matching item, or `-1` if no match is found * * @example * ```typescript * lastIndexOf( * [{id: 1}, {id: 2}, {id: 3}, {id: 2}], * 'id', * 2, * ); // => 3 * ``` */ declare function lastIndexOf(array: Item[], key: ItemKey, value: Item[ItemKey]): number; /** * Get the index of the last item matching the filter * * _Available as `lastIndexOf` and `indexOf.last`_ * * @param array Array to search in * @param filter Filter callback to match items * @returns Index of the last matching item, or `-1` if no match is found * * @example * ```typescript * lastIndexOf( * [{id: 1}, {id: 2}, {id: 3}, {id: 2}], * item => item.id === 2, * ); // => 3 * ``` */ declare function lastIndexOf(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): number; /** * Get the index of the last item matching the given item * * _Available as `lastIndexOf` and `indexOf.last`_ * * @param array Array to search in * @param item Item to match against * @returns Index of the last matching item, or `-1` if no match is found * * @example * ```typescript * lastIndexOf([1, 2, 3, 2, 1], 2); // => 3 * ``` */ declare function lastIndexOf(array: Item[], item: Item): number; //#endregion //#region src/internal/array/shuffle.d.ts /** * Shuffle items in array * * @param array Original array * @returns Shuffled array */ declare function shuffle(array: Item[]): Item[]; //#endregion //#region src/array/difference.d.ts /** * Get the items from the first array that are not in the second array * * @param first First array * @param second Second array * @param callback Callback to get an item's value for comparison * @returns Unique values from the first array * * @example * ```typescript * difference( * [{id: 1}, {id: 2}, {id: 3}], * [{id: 2}, {id: 4}], * item => item.id, * ); // => [{id: 1}, {id: 3}] * ``` */ declare function difference(first: First[], second: Second[], callback: (item: First | Second) => unknown): First[]; /** * Get the items from the first array that are not in the second array * * @param first First array * @param second Second array * @param key Key to get an item's value for comparison * @returns Unique values from the first array * * @example * ```typescript * difference( * [{id: 1}, {id: 2}, {id: 3}], * [{id: 2}, {id: 4}], * 'id', * ); // => [{id: 1}, {id: 3}] * ``` */ declare function difference(first: First[], second: Second[], key: SharedKey): First[]; /** * Get the items from the first array that are not in the second array * * @param first First array * @param second Second array * @returns Unique values from the first array * * @example * ```typescript * difference( * [1, 2, 3], * [2, 4], * ); // => [1, 3] * ``` */ declare function difference(first: First[], second: Second[]): First[]; //#endregion //#region src/array/exists.d.ts /** * Does an item with a specific value exist in the array? * * @param array Array to search in * @param callback Callback to get an item's value for matching * @param value Value to match against * @returns `true` if the item exists in the array, otherwise `false` * * @example * ```typescript * exists( * [{id: 1}, {id: 2}, {id: 3}], * item => item.id, * 2, * ); // => true * ``` */ declare function exists unknown>(array: Item[], callback: Callback, value: ReturnType): boolean; /** * Does an item with a specific value exist in the array? * * @param array Array to search in * @param key Key to get an item's value for matching * @param value Value to match against * @returns `true` if the item exists in the array, otherwise `false` * * @example * ```typescript * exists( * [{id: 1}, {id: 2}, {id: 3}], * 'id', * 2, * ); // => true * ``` */ declare function exists(array: Item[], key: ItemKey, value: Item[ItemKey]): boolean; /** * Does an item in the array match the filter? * * @param array Array to search in * @param filter Filter callback to match items * @returns `true` if a matching item exists, otherwise `false` * * @example * ```typescript * exists( * [{id: 1}, {id: 2}, {id: 3}], * item => item.id === 2, * ); // => true * ``` */ declare function exists(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): boolean; /** * Does the item exist in the array? * * @param array Array to search in * @param item Item to search for * @returns `true` if the item exists in the array, otherwise `false` * * @example * ```typescript * exists([1, 2, 3], 2); // => true * ``` */ declare function exists(array: Item[], item: Item): boolean; //#endregion //#region src/array/find.d.ts /** * Get the first item matching the given value * * @param array Array to search in * @param callback Callback to get an item's value for matching * @param value Value to match against * @returns First item that matches the value, or `undefined` if no match is found * * @example * ```typescript * find( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * 10, * ); // => {id: 1, value: 10} * ``` */ declare function find unknown>(array: Item[], callback: Callback, value: ReturnType): Item | undefined; /** * Get the first item matching the given value by key * * @param array Array to search in * @param key Key to get an item's value for matching * @param value Value to match against * @returns First item that matches the value, or `undefined` if no match is found * * @example * ```typescript * find( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * 10, * ); // => {id: 1, value: 10} * ``` */ declare function find(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined; /** * Get the first item matching the filter * * @param array Array to search in * @param filter Filter callback to match items * @returns First item that matches the filter, or `undefined` if no match is found * * @example * ```typescript * find( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value === 10, * ); // => {id: 1, value: 10} * ``` */ declare function find(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item | undefined; /** * Get the first item matching the given value * * @param array Array to search in * @param value Value to match against * @returns First item that matches the value, or `undefined` if no match is found * * @example * ```typescript * find([1, 2, 3, 2, 1], 1); // => 1 * ``` */ declare function find(array: Item[], value: Item): Item | undefined; declare namespace find { var last: typeof findLast; } /** * Get the last item matching the given value * * _Available as `findLast` and `find.last`_ * * @param array Array to search in * @param callback Callback to get an item's value for matching * @param value Value to match against * @returns Last item that matches the value, or `undefined` if no match is found * * @example * ```typescript * findLast( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * 10, * ); // => {id: 3, value: 10} * ``` */ declare function findLast unknown>(array: Item[], callback: Callback, value: ReturnType): Item | undefined; /** * Get the last item matching the given value by key * * _Available as `findLast` and `find.last`_ * * @param array Array to search in * @param key Key to get an item's value for matching * @param value Value to match against * @returns Last item that matches the value, or `undefined` if no match is found * * @example * ```typescript * findLast( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * 10, * ); // => {id: 3, value: 10} * ``` */ declare function findLast(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined; /** * Get the last item matching the filter * * _Available as `findLast` and `find.last`_ * * @param array Array to search in * @param filter Filter callback to match items * @returns Last item that matches the filter, or `undefined` if no match is found * * @example * ```typescript * findLast( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value === 10, * ); // => {id: 3, value: 10} * ``` */ declare function findLast(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item | undefined; /** * Get the last item matching the given value * * _Available as `findLast` and `find.last`_ * * @param array Array to search in * @param value Value to match against * @returns Last item that matches the value, or `undefined` if no match is found * * @example * ```typescript * findLast([1, 2, 3, 2, 1], 1); // => 1 * ``` */ declare function findLast(array: Item[], value: Item): Item | undefined; //#endregion //#region src/array/flatten.d.ts /** * Flatten an array _(using native `flat` and maximum depth)_ * * @param array Array to flatten * @returns Flattened array * * @example * ```typescript * flatten([1, [2, [3, 4], 5], 6]); // => [1, 2, 3, 4, 5, 6] * ``` */ declare function flatten(array: Item[]): NestedArray[]; //#endregion //#region src/array/from.d.ts /** * Get an array with a specified length, filled with indices * * @param length Length of the array * @returns Array of indices * * @example * ```typescript * range(5); // => [0, 1, 2, 3, 4] * ``` */ declare function range(length: number): number[]; /** * Get an array of numbers in a specified range * * @param start Starting number _(inclusive)_ * @param end Ending number _(exclusive)_ * @returns Array of numbers in range * * @example * ```typescript * range(2, 5); // => [2, 3, 4] * ``` */ declare function range(start: number, end: number): number[]; /** * Get an array of numbers in a specified range with a specified step * * @param start Starting number _(inclusive)_ * @param end Ending number _(exclusive)_ * @param step Step between numbers * @returns Array of numbers in range * * @example * ```typescript * range(0, 10, 2); // => [0, 2, 4, 6, 8] * ``` */ declare function range(start: number, end: number, step: number): number[]; /** * Get an array with a specified length, filled with indices * * @param length Length of the array * @returns Array of indices * * @example * ```typescript * times(5); // => [0, 1, 2, 3, 4] * ``` */ declare function times(length: number): number[]; /** * Get an array with a specified length, filled by values from a callback * * @param length Length of the array * @param callback Callback function to generate values * @returns Array of values generated by the callback * * @example * ```typescript * times(5, index => index * 2); // => [0, 2, 4, 6, 8] * ``` */ declare function times unknown>(length: number, callback: Callback): ReturnType[]; /** * Get an array with a specified length, filled with a specified value * * @param length Length of the array * @param value Value to fill the array with * @returns Array filled with the specified value * * @example * ```typescript * times(5, 'a'); // => ['a', 'a', 'a', 'a', 'a'] * ``` */ declare function times(length: number, value: Value): Value[]; //#endregion //#region src/array/get.d.ts /** * Get an array from an object, where only values with numerical keys will be included * * @param value Object to convert to an array * @returns Array holding the values of the object's numerical keys * * @example * ```typescript * getArray({0: 'a', 1: 'b', 2: 'c', d: 'd'}, true); // => ['a', 'b', 'c'] * getArray({a: 'a', b: 'b', c: 'c', d: 'd'}, true); // => [] * ``` */ declare function getArray(value: Value, indiced: true): Value[NumericalKeys][]; /** * Get an array from a map * * @param value Map to convert to an array * @returns Array holding the entries of the map * * @example * ```typescript * getArray( * new Map([['a', 1], ['b', 2], ['c', 3]]), * ); // => [['a', 1], ['b', 2], ['c', 3]] * ``` */ declare function getArray(map: Map): [Key, Value][]; /** * Get an array from an object * * @param value Object to convert to an array * @returns Array holding the values of the object * * @example * ```typescript * getArray({0: 'a', 1: 'b', 2: 'c', d: 'd'}); // => ['a', 'b', 'c', 'd'] * getArray({a: 'a', b: 'b', c: 'c', d: 'd'}); // => ['a', 'b', 'c', 'd'] * ``` */ declare function getArray(value: Value): [keyof Value, Value[keyof Value]][]; /** * Get an array from a set * * @param value Set to convert to an array * @returns Array holding the values of the set * * @example * ```typescript * getArray(new Set([123, 456, 789])); // => [123, 456, 789] * ``` */ declare function getArray(set: Set): Value[]; /** * Get an array from a value * * @param value Original array * @returns Original array * * @example * ```typescript * getArray([123]); // => [123] * ``` */ declare function getArray(value: Item[]): Item[]; /** * Get an array from an unknown value * * @param value Value to convert to an array * @returns Array of value * * @example * ```typescript * getArray(123); // => [123] * ``` */ declare function getArray(value: Value): Value[]; //#endregion //#region src/array/insert.d.ts /** * Insert items into an array at a specified index * * _(Uses chunking to avoid call stack size being exceeded)_ * * @param array Original array * @param index Index to insert at * @param items Inserted items * @returns Updated array * * @example * ```typescript * insert([1, 2, 3], 1, [4, 5]); // => [1, 4, 5, 2, 3] * ``` */ declare function insert(array: Item[], index: number, items: Item[]): Item[]; /** * Insert items into an array _(at the end)_ * * _(Uses chunking to avoid call stack size being exceeded)_ * * @param array Original array * @param items Inserted items * @returns Updated array * * @example * ```typescript * insert([1, 2, 3], [4, 5]); // => [1, 2, 3, 4, 5] * ``` */ declare function insert(array: Item[], items: Item[]): Item[]; //#endregion //#region src/array/intersection.d.ts /** * Get the common values between two arrays * * @param first First array * @param second Second array * @param callback Callback to get an item's value for comparison * @returns Common values from both arrays * * @example * ```typescript * intersection( * [{id: 1}, {id: 2}, {id: 3}], * [{id: 2}, {id: 3}, {id: 4}], * item => item.id, * ); // => [{id: 2}, {id: 3}] * ``` */ declare function intersection(first: First[], second: Second[], callback: (item: First | Second) => unknown): First[]; /** * Get the common values between two arrays * * @param first First array * @param second Second array * @param key Key to get an item's value for comparison * @returns Common values from both arrays * * @example * ```typescript * intersection( * [{id: 1}, {id: 2}, {id: 3}], * [{id: 2}, {id: 3}, {id: 4}], * 'id', * ); // => [{id: 2}, {id: 3}] * ``` */ declare function intersection, Second extends Record, SharedKey extends keyof First & keyof Second>(first: First[], second: Second[], key: SharedKey): First[]; /** * Get the common values between two arrays * * @param first First array * @param second Second array * @returns Common values from both arrays * * @example * ```typescript * intersection( * [1, 2, 3], * [2, 3, 4], * ); // => [2, 3] * ``` */ declare function intersection(first: First[], second: Second[]): First[]; //#endregion //#region src/array/partition.d.ts /** * Get a partitioned array of items * * @param array Array to search in * @param callback Callback to get an item's value for matching * @param value Value to match against * @returns Partitioned array of items * * @example * ```typescript * partition( * [{id: 1}, {id: 2}, {id: 3}], * item => item.id, * 2, * ); // => [[{id: 2}], [{id: 1}, {id: 3}]] * ``` */ declare function partition unknown>(array: Item[], callback: Callback, value: ReturnType): Item[][]; /** * Get a partitioned array of items * * @param array Array to search in * @param key Key to get an item's value for matching * @param value Value to match against * @returns Partitioned array of items * * @example * ```typescript * partition( * [{id: 1}, {id: 2}, {id: 3}], * 'id', * 2, * ); // => [[{id: 2}], [{id: 1}, {id: 3}]] * ``` */ declare function partition(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[][]; /** * Get a partitioned array of items * * @param array Array to search in * @param filter Filter callback to match items * @returns Partitioned array of items * * @example * ```typescript * partition( * [{id: 1}, {id: 2}, {id: 3}], * item => item.id === 2, * ); // => [[{id: 2}], [{id: 1}, {id: 3}]] * ``` */ declare function partition(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item[][]; /** * Get a partitioned array of items matching the given item * * @param array Array to search in * @param item Item to match against * @returns Partitioned array of items * * @example * ```typescript * partition([1, 2, 3, 4, 5], 3); // => [[3], [1, 2, 4, 5]] * ``` */ declare function partition(array: Item[], item: Item): Item[][]; //#endregion //#region src/array/match.d.ts /** * Comparison of an array within another array */ type ArrayComparison = 'end' | 'inside' | 'invalid' | 'outside' | 'same' | 'start'; /** * Is the needle array at the end of the haystack array? * * @param haystack Haystack array * @param needle Needle array * @param callback Callback to get an item's value for matching * @returns `true` if the haystack ends with the needle, otherwise `false` * * @example * ```typescript * endsWithArray( * [{id: 1}, {id: 2}, {id: 3}], * [{id: 2}, {id: 3}], * item => item.id, * ); // => true * ``` */ declare function endsWithArray(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean; /** * Is the needle array at the end of the haystack array? * * @param haystack Haystack array * @param needle Needle array * @param key Key to get an item's value for matching * @returns `true` if the haystack ends with the needle, otherwise `false` * * @example * ```typescript * endsWithArray( * [{id: 1}, {id: 2}, {id: 3}], * [{id: 2}, {id: 3}], * 'id', * ); // => true * ``` */ declare function endsWithArray(haystack: Item[], needle: Item[], key: keyof Item): boolean; /** * Is the needle array at the end of the haystack array? * * @param haystack Haystack array * @param needle Needle array * @returns `true` if the haystack ends with the needle, otherwise `false` * * @example * ```typescript * endsWithArray([1, 2, 3], [2, 3]); // => true * ``` */ declare function endsWithArray(haystack: Item[], needle: Item[]): boolean; /** * Get the position of an array within another array * * @param haystack Haystack array * @param needle Needle array * @param callback Callback to get an item's value for matching * @returns Position of the needle within the haystack * * @example * ```typescript * getArrayComparison( * [{id: 1}, {id: 2}, {id: 3}], * [{id: 2}, {id: 3}], * item => item.id, * ); // => 'end' * ``` */ declare function getArrayComparison(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): ArrayComparison; /** * Get the position of an array within another array * * @param haystack Haystack array * @param needle Needle array * @param key Key to get an item's value for matching * @returns Position of the needle within the haystack * * @example * ```typescript * getArrayComparison( * [{id: 1}, {id: 2}, {id: 3}], * [{id: 2}, {id: 3}], * 'id', * ); // => 'end' * ``` */ declare function getArrayComparison(haystack: Item[], needle: Item[], key: keyof Item): ArrayComparison; /** * Get the position of an array within another array * * @param haystack Haystack array * @param needle Needle array * @returns Position of the needle within the haystack * * @example * ```typescript * getArrayComparison([1, 2, 3], [2, 3]); // => 'end' * ``` */ declare function getArrayComparison(haystack: Item[], needle: Item[]): ArrayComparison; /** * Does the needle array exist within the haystack array? * * @param haystack Haystack array * @param needle Needle array * @param callback Callback to get an item's value for matching * @returns `true` if the haystack includes the needle, otherwise `false` * * @example * ```typescript * includesArray( * [{id: 1}, {id: 2}, {id: 3}], * [{id: 2}, {id: 3}], * item => item.id, * ); // => true * ``` */ declare function includesArray(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean; /** * Does the needle array exist within the haystack array? * * @param haystack Haystack array * @param needle Needle array * @param key Key to get an item's value for matching * @returns `true` if the haystack includes the needle, otherwise `false` * * @example * ```typescript * includesArray( * [{id: 1}, {id: 2}, {id: 3}], * [{id: 2}, {id: 3}], * 'id', * ); // => true * ``` */ declare function includesArray(haystack: Item[], needle: Item[], key: keyof Item): boolean; /** * Does the needle array exist within the haystack array? * * @param haystack Haystack array * @param needle Needle array * @returns `true` if the haystack includes the needle, otherwise `false` * * @example * ```typescript * includesArray([1, 2, 3], [2, 3]); // => true * ``` */ declare function includesArray(haystack: Item[], needle: Item[]): boolean; /** * Get the index of an array within another array * * @param haystack Haystack array * @param needle Needle array * @param callback Callback to get an item's value for matching * @returns Index of the needle's start within the haystack, or `-1` if it is not found * * @example * ```typescript * indexOfArray( * [{id: 1}, {id: 2}, {id: 3}], * [{id: 2}, {id: 3}], * item => item.id, * ); // => 1 * ``` */ declare function indexOfArray(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): number; /** * Get the index of an array within another array * * @param haystack Haystack array * @param needle Needle array * @param key Key to get an item's value for matching * @returns Index of the needle's start within the haystack, or `-1` if it is not found * * @example * ```typescript * indexOfArray( * [{id: 1}, {id: 2}, {id: 3}], * [{id: 2}, {id: 3}], * 'id', * ); // => 1 * ``` */ declare function indexOfArray(haystack: Item[], needle: Item[], key: keyof Item): number; /** * Get the index of an array within another array * * @param haystack Haystack array * @param needle Needle array * @returns Index of the needle's start within the haystack, or `-1` if it is not found * * @example * ```typescript * indexOfArray([1, 2, 3], [2, 3]); // => 1 * ``` */ declare function indexOfArray(haystack: Item[], needle: Item[]): number; /** * Is the needle array at the start of the haystack array? * * @param haystack Haystack array * @param needle Needle array * @param callback Callback to get an item's value for matching * @returns `true` if the haystack starts with the needle, otherwise `false` * * @example * ```typescript * startsWithArray( * [{id: 1}, {id: 2}, {id: 3}], * [{id: 1}, {id: 2}], * item => item.id, * ); // => true * ``` */ declare function startsWithArray(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean; /** * Is the needle array at the start of the haystack array? * * @param haystack Haystack array * @param needle Needle array * @param key Key to get an item's value for matching * @returns `true` if the haystack starts with the needle, otherwise `false` * * @example * ```typescript * startsWithArray( * [{id: 1}, {id: 2}, {id: 3}], * [{id: 1}, {id: 2}], * 'id', * ); // => true * ``` */ declare function startsWithArray(haystack: Item[], needle: Item[], key: keyof Item): boolean; /** * Is the needle array at the start of the haystack array? * * @param haystack Haystack array * @param needle Needle array * @returns `true` if the haystack starts with the needle, otherwise `false` * * @example * ```typescript * startsWithArray([1, 2, 3], [1, 2]); // => true * ``` */ declare function startsWithArray(haystack: Item[], needle: Item[]): boolean; //#endregion //#region src/array/push.d.ts /** * Push items into an array _(at the end)_ * * _(Uses chunking to avoid call stack size being exceeded)_ * * @param array Original array * @param pushed Pushed items * @returns New length of the array * * @example * ```typescript * push([1, 2, 3], [4, 5]); // => 5 (new length); array becomes [1, 2, 3, 4, 5] * ``` */ declare function push(array: Item[], pushed: Item[]): number; //#endregion //#region src/array/reverse.d.ts /** * Reverse the order of items in an array * * @param array Array to reverse * @returns Reversed array */ declare function reverse(array: Item[]): Item[]; //#endregion //#region src/array/select.d.ts /** * Get a filtered and mapped array of items * * @param array Array to search in * @param filterCallback Callback to get an item's value for matching * @param filterValue Value to match against * @param mapCallback Callback to map the matched items * @returns Filtered and mapped array of items * * @example * ```typescript * select( * [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}], * item => item.id, * 2, * item => item.name, * ); // => ['Bob'] * ``` */ declare function select unknown, MapCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], filterCallback: FilterCallback, filterValue: ReturnType, mapCallback: MapCallback): Array>; /** * Get a filtered and mapped array of items * * @param array Array to search in * @param filterCallback Callback to get an item's value for matching * @param filterValue Value to match against * @param mapKey Key to get an item's value for mapping * @returns Filtered and mapped array of items * * @example * ```typescript * select( * [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}], * item => item.id, * 2, * 'name', * ); // => ['Bob'] * ``` */ declare function select unknown, MapKey extends keyof Item>(array: Item[], filterCallback: FilterCallback, filterValue: ReturnType, mapKey: MapKey): Array; /** * Get a filtered and mapped array of items * * @param array Array to search in * @param filterKey Key to get an item's value for matching * @param filterValue Value to match against * @param mapCallback Callback to map the matched items * @returns Filtered and mapped array of items * * @example * ```typescript * select( * [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}], * 'id', * 2, * item => item.name, * ); // => ['Bob'] * ``` */ declare function select unknown>(array: Item[], filterKey: ItemKey, filterValue: Item[ItemKey], mapCallback: MapCallback): Array>; /** * Get a filtered and mapped array of items * * @param array Array to search in * @param filterKey Key to get an item's value for matching * @param filterValue Value to match against * @param mapKey Key to get an item's value for mapping * @returns Filtered and mapped array of items * * @example * ```typescript * select( * [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}], * 'id', * 2, * 'name', * ); // => ['Bob'] * ``` */ declare function select(array: Item[], filterKey: ItemKey, filterValue: Item[ItemKey], mapKey: MapKey): Array; /** * Get a filtered and mapped array of items * * @param array Array to search in * @param filterCallback Filter callback to match items * @param mapCallback Callback to map the matched items * @returns Filtered and mapped array of items * * @example * ```typescript * select( * [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}], * item => item.id === 2, * item => item.name, * ); // => ['Bob'] * ``` */ declare function select unknown, MapCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], filterCallback: FilterCallback, filterValue: ReturnType, mapCallback: MapCallback): Array>; /** * Get a filtered and mapped array of items * * @param array Array to search in * @param filterCallback Filter callback to match items * @param mapKey Key to get an item's value for mapping * @returns Filtered and mapped array of items * * @example * ```typescript * select( * [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}], * item => item.id, * 2, * 'name' * ); // => ['Bob'] * ``` */ declare function select unknown, MapKey extends keyof Item>(array: Item[], filterCallback: FilterCallback, filterValue: ReturnType, mapKey: MapKey): Array; /** * Get a filtered and mapped array of items * * @param array Array to search in * @param filter Filter callback to match items * @param map Callback to map the matched items * @returns Filtered and mapped array of items * * @example * ```typescript * select( * [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}], * item => item.id === 2, * item => item.name, * ); // => ['Bob'] * ``` */ declare function select unknown>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean, map: MapCallback): Array>; /** * Get a filtered and mapped array of items * * @param array Array to search in * @param filter Filter callback to match items * @param map Key to get an item's value for mapping * @returns Filtered and mapped array of items * * @example * ```typescript * select( * [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}], * item => item.id === 2, * 'name' * ); // => ['Bob'] * ``` */ declare function select(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean, map: MapKey): Array; /** * Get a filtered and mapped array of items * * @param array Array to search in * @param item Item to match against * @param map Callback to map the matched items * @returns Filtered and mapped array of items * * @example * ```typescript * select( * [1, 2, 3, 2, 1], * 3, * value => value ** 2, * ); // => [9] * ``` */ declare function select unknown>(array: Item[], item: Item, map: MapCallback): Array>; //#endregion //#region src/array/single.d.ts /** * Get the _only_ item matching the given value * * Throws an error if multiple items match the value * * @param array Array to search in * @param callback Callback to get an item's value for matching * @param value Value to match against * @returns Only item that matches the value, or `undefined` if no match is found * * @example * ```typescript * single( * [{id: 1}, {id: 2}, {id: 3}], * item => item.id, * 2 * ); // => {id: 2} * ``` */ declare function single unknown>(array: Item[], callback: Callback, value: ReturnType): Item | undefined; /** * Get the _only_ item matching the given value by key * * Throws an error if multiple items match the value * * @param array Array to search in * @param key Key to get an item's value for matching * @param value Value to match against * @returns Only item that matches the value, or `undefined` if no match is found * * @example * ```typescript * single( * [{id: 1}, {id: 2}, {id: 3}], * 'id', * 2 * ); // => {id: 2} * ``` */ declare function single(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined; /** * Get the _only_ item matching the filter * * Throws an error if multiple items match the filter * * @param array Array to search in * @param filter Filter callback to match items * @returns Only item that matches the filter, or `undefined` if no match is found * * @example * ```typescript * single( * [{id: 1}, {id: 2}, {id: 3}], * item => item.id === 2 * ); // => {id: 2} * ``` */ declare function single(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item | undefined; //#endregion //#region src/array/slice.d.ts /** * Drop items from the start of an array until they match a value * * @param array Original array * @param callback Callback to get an item's value for matching * @param value Value to match against * @returns New array with items dropped * * @example * ```typescript * drop( * [{id: 1}, {id: 2}, {id: 3}], * item => item.id, * 2, * ); // => [{id: 2}, {id: 3}] * ``` */ declare function drop unknown>(array: Item[], callback: Callback, value: ReturnType): Item[]; /** * Drop items from the start of an array until they match a value * * @param array Original array * @param key Key to get an item's value for matching * @param value Value to match against * @returns New array with items dropped * * @example * ```typescript * drop( * [{id: 1}, {id: 2}, {id: 3}], * 'id', * 2, * ); // => [{id: 2}, {id: 3}] * ``` */ declare function drop(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[]; /** * Drop items from the start of an array while they match a filter * * @param array Original array * @param callback Filter callback to match items * @returns New array with items dropped * * @example * ```typescript * drop( * [{id: 1}, {id: 2}, {id: 3}], * item => item.id === 2, * ); // => [{id: 2}, {id: 3}] * ``` */ declare function drop(array: Item[], callback: (item: Item, index: number, array: Item[]) => boolean): Item[]; /** * Drop a specified number of items, from the start if `>= 0`, or from the end if `< 0` * * @param array Original array * @param count Number of items to drop * @returns New array with items dropped * * @example * ```typescript * drop([1, 2, 3, 4, 5], 2); // => [3, 4, 5] * drop([1, 2, 3, 4, 5], -2); // => [1, 2, 3] * ``` */ declare function drop(array: unknown[], count: number): unknown[]; /** * Slice an array _(returning a new array with a specified range of items)_ * * @param array Original array * @param start Start index _(inclusive)_ * @param end End index _(exclusive)_ * @returns New array with sliced items * * @example * ```typescript * slice([1, 2, 3, 4, 5], 1, 4); // => [2, 3, 4] * ``` */ declare function slice(array: Item[], start: number, end: number): Item[]; /** * Slice an array _(returning a new array with a specified number of items, from the start)_ * * @param array Original array * @param count Maximum size of the new array * @returns New array with sliced items * * @example * ```typescript * slice([1, 2, 3, 4, 5], 3); // => [1, 2, 3] * ``` */ declare function slice(array: Item[], count: number): Item[]; /** * Slice an array _(returning a new array with all items)_ * * @param array Array to slice * @returns Sliced array * * @example * ```typescript * slice([1, 2, 3]); // => [1, 2, 3] * ``` */ declare function slice(array: Item[]): Item[]; /** * Take items from the start of an array until they match a value * * @param array Original array * @param callback Callback to get an item's value for matching * @param value Value to match against * @returns New array with taken items * * @example * ```typescript * take( * [{id: 1}, {id: 2}, {id: 3}], * item => item.id, * 2, * ); // => [{id: 1}] * ``` */ declare function take unknown>(array: Item[], callback: Callback, value: ReturnType): Item[]; /** * Take items from the start of an array until they match a value * * @param array Original array * @param key Key to get an item's value for matching * @param value Value to match against * @returns New array with taken items * * @example * ```typescript * take( * [{id: 1}, {id: 2}, {id: 3}], * 'id', * 2, * ); // => [{id: 1}] * ``` */ declare function take(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[]; /** * Take items from the start of an array while they match a filter * * @param array Original array * @param callback Filter callback to match items * @returns New array with taken items * * @example * ```typescript * take( * [{id: 1}, {id: 2}, {id: 3}], * item => item.id === 2, * ); // => [{id: 1}] * ``` */ declare function take(array: Item[], callback: (item: Item, index: number, array: Item[]) => boolean): Item[]; /** * Take a specified number of items, from the start if `>= 0`, or from the end if `< 0` * * @param array Original array * @param count Number of items to take * @returns New array with taken items * * @example * ```typescript * take([1, 2, 3, 4, 5], 2); // => [1, 2] * take([1, 2, 3, 4, 5], -2); // => [4, 5] * ``` */ declare function take(array: unknown[], count: number): unknown[]; //#endregion //#region src/array/splice.d.ts /** * Adds items into an array at a specific index and removes a specific amount of items * * _(Uses chunking to avoid call stack size being exceeded)_ * * @param array Original array * @param start Index to start splicing from * @param amount Number of items to remove * @param added Added items * @returns Removed items * * @example * ```typescript * splice( * [1, 2, 3, 4, 5], * 2, * 2, * [6, 7] * ); // => [3, 4], array becomes [1, 2, 6, 7, 5] * ``` */ declare function splice(array: Item[], start: number, amount: number, added: Item[]): Item[]; /** * Adds items into an array at a specific index * * _(Uses chunking to avoid call stack size being exceeded)_ * * @param array Original array * @param start Index to start splicing from * @param added Added items * @returns Removed items * * @example * ```typescript * splice( * [1, 2, 3, 4, 5], * 2, * [6, 7] * ); // => [], array becomes [1, 2, 6, 7, 3, 4, 5] * ``` */ declare function splice(array: Item[], start: number, added: Item[]): Item[]; /** * Removes and returns _(up to)_ a specific amount of items from an array, starting from a specific index * * _(Uses chunking to avoid call stack size being exceeded)_ * * @param array Original array * @param start Index to start splicing from * @param amount Number of items to remove * @returns Removed items * * @example * ```typescript * splice( * [1, 2, 3, 4, 5], * 2, * 2, * ); // => [3, 4], array becomes [1, 2, 5] * ``` */ declare function splice(array: Item[], start: number, amount: number): Item[]; /** * Removes and returns all items from an array starting from a specific index * * _(Uses chunking to avoid call stack size being exceeded)_ * * @param array Original array * @param start Index to start splicing from * @returns Removed items * * @example * ```typescript * splice( * [1, 2, 3, 4, 5], * 2, * ); // => [3, 4, 5], array becomes [1, 2] * ``` */ declare function splice(array: Item[], start: number): Item[]; //#endregion //#region src/array/to-set.d.ts /** * Create a _Set_ from an array of items using a callback * * @param array Array to convert * @param callback Callback to get an item's value * @returns _Set_ of values * * @example * ```typescript * toSet( * [{id: 1}, {id: 2}, {id: 3}], * item => item.id, * ); // => Set { 1, 2, 3 } * ``` */ declare function toSet unknown>(array: Item[], callback: Callback): Set>; /** * Create a _Set_ from an array of items using a key * * @param array Array to convert * @param key Key to use for value * @returns _Set_ of values * * @example * ```typescript * toSet( * [{id: 1}, {id: 2}, {id: 3}], * 'id', * ); // => Set { 1, 2, 3 } * ``` */ declare function toSet(array: Item[], key: ItemKey): Set; /** * Create a _Set_ from an array of items * * @param array Array to convert * @returns _Set_ of items * * @example * ```typescript * toSet([1, 2, 3]); // => Set { 1, 2, 3 } * ``` */ declare function toSet(array: Item[]): Set; //#endregion //#region src/array/toggle.d.ts /** * Toggle an item in an array * * If the item exists, it will be removed; if it doesn't, it will be added * * @param destination Array to toggle within * @param toggled Toggled items * @param callback Callback to find existing item * @returns Original array * * @example * ```typescript * toggle( * [{id: 1}, {id: 2}, {id: 3}], * [{id: 2}, {id: 4}], * item => item.id, * ); // => [{id: 1}, {id: 3}, {id: 4}] * ``` */ declare function toggle(destination: Item[], toggled: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[]; /** * Toggle an item in an array * * If the item exists, it will be removed; if it doesn't, it will be added * * @param destination Array to toggle within * @param toggled Toggled items * @param key Key to find existing item * @returns Original array * * @example * ```typescript * toggle( * [{id: 1}, {id: 2}, {id: 3}], * [{id: 2}, {id: 4}], * 'id', * ); // => [{id: 1}, {id: 3}, {id: 4}] * ``` */ declare function toggle(destination: Item[], toggled: Item[], key: ItemKey): Item[]; /** * Toggle an item in an array * * If the item exists, it will be removed; if it doesn't, it will be added * * @param destination Array to toggle within * @param toggled Toggled items * @returns Original array * * @example * ```typescript * toggle( * [1, 2, 3], * [2, 4], * ); // => [1, 3, 4] * ``` */ declare function toggle(destination: Item[], toggled: Item[]): Item[]; //#endregion //#region src/array/union.d.ts /** * Get the combined, unique values from two arrays * * @param first First array * @param second Second array * @param callback Callback to get an item's value for comparison * @returns Combined, unique values from both arrays * * @example * ```typescript * union( * [{id: 1}, {id: 2}, {id: 3}], * [{id: 2}, {id: 4}], * item => item.id, * ); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}] * ``` */ declare function union(first: First[], second: Second[], callback: (item: First | Second) => unknown): (First | Second)[]; /** * Get the combined, unique values from two arrays * * @param first First array * @param second Second array * @param key Key to get an item's value for comparison * @returns Combined, unique values from both arrays * * @example * ```typescript * union( * [{id: 1}, {id: 2}, {id: 3}], * [{id: 2}, {id: 4}], * 'id', * ); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}] * ``` */ declare function union, Second extends Record, SharedKey extends keyof First & keyof Second>(first: First[], second: Second[], key: SharedKey): (First | Second)[]; /** * Get the combined, unique values from two arrays * * @param first First array * @param second Second array * @returns Combined, unique values from both arrays * * @example * ```typescript * union( * [1, 2, 3], * [2, 4], * ); // => [1, 2, 3, 4] * ``` */ declare function union(first: First[], second: Second[]): (First | Second)[]; //#endregion //#region src/array/unique.d.ts /** * Get an array of unique items * * @param array Original array * @param callback Callback to get an item's value * @returns Array of unique items * * @example * ```typescript * unique( * [{id: 1}, {id: 2}, {id: 3}, {id: 2}], * item => item.id, * ); // => [{id: 1}, {id: 2}, {id: 3}] * ``` */ declare function unique(array: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[]; /** * Get an array of unique items * * @param array Original array * @param key Key to use for unique value * @returns Array of unique items * * @example * ```typescript * unique( * [{id: 1}, {id: 2}, {id: 3}, {id: 2}], * 'id', * ); // => [{id: 1}, {id: 2}, {id: 3}] * ``` */ declare function unique(array: Item[], key: ItemKey): Item[]; /** * Get an array of unique items * * @param array Original array * @returns Array of unique items * * @example * ```typescript * unique([1, 2, 3, 2]); // => [1, 2, 3] * ``` */ declare function unique(array: Item[]): Item[]; //#endregion //#region src/array/update.d.ts /** * Update an item in an array * * If the item exists, it will be updated; if it doesn't, it will be added * * @param destination Array to update within * @param updated Updated items * @param callback Callback to find existing item * @returns Original array * * @example * ```typescript * update( * [{id: 1}, {id: 2}, {id: 3}], * [{id: 2, name: 'Updated'}, {id: 4, name: 'New'}], * item => item.id, * ); // => [{id: 1}, {id: 2, name: 'Updated'}, {id: 3}, {id: 4, name: 'New'}] * ``` */ declare function update(destination: Item[], updated: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[]; /** * Update an item in an array * * If the item exists, it will be updated; if it doesn't, it will be added * * @param destination Array to update within * @param updated Updated items * @param key Key to find existing item * @returns Original array * * @example * ```typescript * update( * [{id: 1}, {id: 2}, {id: 3}], * [{id: 2, name: 'Updated'}, {id: 4, name: 'New'}], * 'id', * ); // => [{id: 1}, {id: 2, name: 'Updated'}, {id: 3}, {id: 4, name: 'New'}] * ``` */ declare function update(destination: Item[], updated: Item[], key: ItemKey): Item[]; /** * Update an item in an array * * If the item exists, it will be updated; if it doesn't, it will be added * * @param destination Array to update within * @param updated Updated items * @returns Original array * * @example * ```typescript * update( * [1, 2, 3], * [2, 4], * ); // => [1, 2, 3, 4] * ``` */ declare function update(destination: Item[], updated: Item[]): Item[]; //#endregion //#region src/array/last.d.ts /** * Get the last items matching the given value * * @param array Array to search in * @param callback Callback to get an item's value for matching * @param value Value to match against * @returns Last item that matches the value, or `undefined` if no match is found * * @example * ```typescript * last( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * 10, * ); // => {id: 3, value: 10} * ``` */ declare function last unknown>(array: Item[], callback: Callback, value: ReturnType): Item | undefined; /** * Get the first item matching the given value by key * * @param array Array to search in * @param key Key to get an item's value for matching * @param value Value to match against * @returns Last item that matches the value, or `undefined` if no match is found * * @example * ```typescript * last( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * 10, * ); // => {id: 3, value: 10} * ``` */ declare function last(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined; /** * Get the last item matching the filter * * @param array Array to search in * @param filter Filter callback to match items * @returns Last item that matches the filter, or `undefined` if no match is found * * @example * ```typescript * last( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value === 10, * ); // => {id: 3, value: 10} * ``` */ declare function last(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item | undefined; /** * Get the last item from an array * * @param array Array to get from * @returns Last item from the array, or `undefined` if the array is empty * * @example * ```typescript * last([1, 2, 3]); // => 3 * ``` */ declare function last(array: Item[]): Item | undefined; declare namespace last { var _a: typeof lastOrDefault; export { _a as default }; } /** * Get the last item matching the given value * * _Available as `lastOrDefault` and `last.default`_ * * @param array Array to search in * @param defaultValue Default value to return if no match is found * @param callback Callback to get an item's value for matching * @param value Value to match against * @returns Last item that matches the value, or the default value if no match is found * * @example * ```typescript * lastOrDefault( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * {id: -1, value: 30}, * item => item.value, * 30, * ); // => {id: -1, value: 30} * ``` */ declare function lastOrDefault unknown>(array: Item[], defaultValue: Item, callback: Callback, value: ReturnType): Item; /** * Get the last item matching the given value by key * * _Available as `lastOrDefault` and `last.default`_ * * @param array Array to search in * @param defaultValue Default value to return if no match is found * @param key Key to get an item's value for matching * @param value Value to match against * @returns Last item that matches the value, or the default value if no match is found * * @example * ```typescript * lastOrDefault( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * {id: -1, value: 30}, * 'value', * 30, * ); // => {id: -1, value: 30} * ``` */ declare function lastOrDefault(array: Item[], defaultValue: Item, key: ItemKey, value: Item[ItemKey]): Item; /** * Get the last item matching the filter * * _Available as `lastOrDefault` and `last.default`_ * * @param array Array to search in * @param defaultValue Default value to return if no match is found * @param filter Filter callback to match items * @returns Last item that matches the filter, or the default value if no match is found * * @example * ```typescript * lastOrDefault( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * {id: -1, value: 30}, * item => item.value === 30, * ); // => {id: -1, value: 30} * ``` */ declare function lastOrDefault(array: Item[], defaultValue: Item, filter: (item: Item, index: number, array: Item[]) => boolean): Item; /** * Get the last item from an array * * _Available as `lastOrDefault` and `last.default`_ * * @param array Array to get from * @param defaultValue Default value to return if the array is empty * @returns Last item from the array, or the default value if the array is empty * * @example * ```typescript * lastOrDefault([], {id: -1, value: 30}); // => {id: -1, value: 30} * ``` */ declare function lastOrDefault(array: Item[], defaultValue: Item): Item; //#endregion //#region src/array/move.d.ts /** * Move an item _(or array of items)_ to the position of another item _(or array of items)_ within an array * * When moving to the front of the array, the moved items will be placed __before__ the target item. When moving to the back of the array, the moved items will be placed __after__ the target item * * If either of values are not present in the array, or if they overlap, the array will be returned unchanged * * @param array Array to move within * @param from Item or items to move * @param to Item or items to move to * @param callback Callback to get an item's value for matching * @returns Original array with items moved _(or unchanged if unable to move)_ * * @example * ```typescript * const array = [{id: 1}, {id: 2}, {id: 3}, {id: 4}]; * * move(array, {id: 1}, {id: 3}, item => item.id); // => [{id: 2}, {id: 3}, {id: 1}, {id: 4}] * move(array, [{id: 2}, {id: 3}], {id: 4}, item => item.id); // => [{id: 1}, {id: 4}, {id: 2}, {id: 3}] * move(array, {id: 5}, {id: 1}, item => item.id); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}] (unchanged) * ``` */ declare function move(array: Item[], from: Item | Item[], to: Item | Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[]; /** * Move an item _(or array of items)_ to the position of another item _(or array of items)_ within an array * * When moving to the front of the array, the moved items will be placed __before__ the target item. When moving to the back of the array, the moved items will be placed __after__ the target item * * If either of values are not present in the array, or if they overlap, the array will be returned unchanged * * @param array Array to move within * @param from Item or items to move * @param to Item or items to move to * @param key Key to get an item's value for matching * @returns Original array with items moved _(or unchanged if unable to move)_ * * @example * ```typescript * const array = [{id: 1}, {id: 2}, {id: 3}, {id: 4}]; * * move(array, {id: 1}, {id: 3}, 'id'); // => [{id: 2}, {id: 3}, {id: 1}, {id: 4}] * move(array, [{id: 2}, {id: 3}], {id: 4}, 'id'); // => [{id: 1}, {id: 4}, {id: 2}, {id: 3}] * move(array, {id: 5}, {id: 1}, 'id'); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}] (unchanged) * ``` */ declare function move(array: Item[], from: Item | Item[], to: Item | Item[], key: ItemKey): Item[]; /** * Move an item _(or array of items)_ to the position of another item _(or array of items)_ within an array * * When moving to the front of the array, the moved items will be placed __before__ the target item. When moving to the back of the array, the moved items will be placed __after__ the target item * * If either of values are not present in the array, or if they overlap, the array will be returned unchanged * * @param array Array to move within * @param from Item or items to move * @param to Item or items to move to * @returns Original array with items moved _(or unchanged if unable to move)_ * * @example * ```typescript * const array = [1, 2, 3, 4]; * * move(array, 1, 3); // => [2, 3, 1, 4] * move(array, [2, 3], 4); // => [1, 4, 2, 3] * move(array, 5, 1); // => [1, 2, 3, 4] (unchanged) * ``` */ declare function move(array: Item[], from: Item | Item[], to: Item | Item[]): Item[]; declare namespace move { var indices: typeof moveIndices; var toIndex: typeof moveToIndex; } /** * Move an item from one index to another within an array * * If the from index is out of bounds, the array will be returned unchanged * * _Available as `moveIndices` and `move.indices`_ * * @param array Array to move within * @param from Index to move from * @param to Index to move to * @returns Original array with item moved _(or unchanged if unable to move)_ * * @example * ```typescript * const array = [1, 2, 3, 4]; * * moveIndices(array, 0, 2); // => [2, 3, 1, 4] * moveIndices(array, -1, 0); // => [4, 2, 3, 1] * moveIndices(array, 5, 1); // => [4, 2, 3, 1] (unchanged) * ``` */ declare function moveIndices(array: Item[], from: number, to: number): Item[]; /** * Move an item _(or array of items)_ to an index within an array * * If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged * * _Available as `moveToIndex` and `move.toIndex`_ * * @example * ```typescript * const array = [{id: 1}, {id: 2}, {id: 3}, {id: 4}]; * * moveToIndex(array, {id: 1}, 2, item => item.id); // => [{id: 2}, {id: 3}, {id: 1}, {id: 4}] * moveToIndex(array, [{id: 2}, {id: 3}], 3, item => item.id); // => [{id: 1}, {id: 4}, {id: 2}, {id: 3}] * moveToIndex(array, {id: 5}, 1, item => item.id); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}] (unchanged) * ``` * * @param array Array to move within * @param value Item or items to move * @param index Index to move to * @param callback Callback to get an item's value for matching * @returns Original array with items moved _(or unchanged if unable to move)_ */ declare function moveToIndex(array: Item[], value: Item | Item[], index: number, callback: (item: Item, index: number, array: Item[]) => unknown): Item[]; /** * Move an item _(or array of items)_ to an index within an array * * If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged * * _Available as `moveToIndex` and `move.toIndex`_ * * @param array Array to move within * @param value Item or items to move * @param index Index to move to * @param key Key to get an item's value for matching * @returns Original array with items moved _(or unchanged if unable to move)_ * * @example * ```typescript * const array = [{id: 1}, {id: 2}, {id: 3}, {id: 4}]; * * moveToIndex(array, {id: 1}, 2, 'id'); // => [{id: 2}, {id: 3}, {id: 1}, {id: 4}] * moveToIndex(array, [{id: 2}, {id: 3}], 3, 'id'); // => [{id: 1}, {id: 4}, {id: 2}, {id: 3}] * moveToIndex(array, {id: 5}, 1, 'id'); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}] (unchanged) * ``` */ declare function moveToIndex(array: Item[], value: Item | Item[], index: number, key: ItemKey): Item[]; /** * Move an item _(or array of items)_ to an index within an array * * If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged * * _Available as `moveToIndex` and `move.toIndex`_ * * @param array Array to move within * @param value Item or items to move * @param index Index to move to * @returns Original array with items moved _(or unchanged if unable to move)_ * * @example * ```typescript * const array = [1, 2, 3, 4]; * * moveToIndex(array, 1, 2); // => [2, 3, 1, 4] * moveToIndex(array, [2, 3], 3); // => [1, 4, 2, 3] * moveToIndex(array, 5, 1); // => [1, 2, 3, 4] (unchanged) * ``` */ declare function moveToIndex(array: Item[], value: Item | Item[], index: number): Item[]; //#endregion //#region src/array/sort.d.ts /** * Sorting information for arrays _(using a comparison callback)_ */ type ArrayComparisonSorter = { /** * Callback to use when comparing items and values */ comparison: ComparisonSorter; /** * Direction to sort by */ direction?: SortDirection; }; /** * Sorting information for arrays _(using a key)_ */ type ArrayKeySorter = { /** * Comparator to use when comparing items and values */ compare?: CompareCallback; /** * Direction to sort by */ direction?: SortDirection; /** * Key to sort by */ key: ItemKey; }; /** * Sorters based on keys in an object */ type ArrayKeySorters = { [ItemKey in keyof Item]: ArrayKeySorter }[keyof Item]; /** * Sorter to use for sorting */ type ArraySorter = Item extends PlainObject ? keyof Item | ArrayComparisonSorter | ArrayKeySorters | ArrayValueSorter | ComparisonSorter : ArrayComparisonSorter | ArrayValueSorter | ComparisonSorter; /** * Sorting information for arrays _(using a value callback and built-in comparison)_ */ type ArrayValueSorter = { /** * Direction to sort by */ direction?: SortDirection; /** * Value to sort by */ value: (item: Item) => unknown; }; /** * Comparator to use when comparing items and values */ type CompareCallback> = (first: Item, firstValue: Value, second: Item, secondValue: Value) => number; type CompareCallbackValue = Item extends Primitive ? Item : unknown; /** * Callback to use when comparing items and values */ type ComparisonSorter = (first: Item, second: Item) => number; /** * Direction to sort by */ type SortDirection = 'ascending' | 'descending'; /** * Sorter for an array with predefined sorters * * Can be used to sort an array, get the predicted index for an item, and check if an array is sorted */ type Sorter = { /** * Sort an array of items * * @param array Array to sort * @returns Sorted array */ (array: Item[]): Item[]; /** * Get the index for an item _(to be inserted into an array of items)_ * * _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_ * * @param array Array to get the index from * @param item Item to get the index for * @returns Index for item */ index(array: Item[], item: Item): number; /** * Is the array sorted? * * @param array Array to check * @returns `true` if sorted, otherwise `false` */ is(array: Item[]): boolean; }; /** * Get the index for an item _(to be inserted into an array of items)_ based on sorters _(and an optional default direction)_ * * _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_ * * _Available as `getSortedIndex` and `sort.getIndex`_ * * @param array Array to get the index from * @param item Item to get the index for * @param sorters Sorters to use to determine sorting * @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_ * @returns Index for item */ declare function getSortedIndex(array: Item[], item: Item, sorters: Array>, descending?: boolean): number; /** * Get the index for an item _(to be inserted into an array of items)_ based on a sorter _(and an optional default direction)_ * * _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_ * * _Available as `getSortedIndex` and `sort.getIndex`_ * * @param array Array to get the index from * @param item Item to get the index for * @param sorter Sorter to use to determine sorting * @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_ * @returns Index for item */ declare function getSortedIndex(array: Item[], item: Item, sorter: ArraySorter, descending?: boolean): number; /** * Get the index for an item _(to be inserted into an array of items)_ based on an optional default direction_ * * _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_ * * _Available as `getSortedIndex` and `sort.getIndex`_ * * @param array Array to get the index from * @param item Item to get the index for * @param descending Sorted in descending order? _(defaults to `false`)_ * @returns Index for item */ declare function getSortedIndex(array: Item[], item: Item, descending?: boolean): number; /** * Initialize a sort handler with sorters _(and an optional default direction)_ * * _Available as `initializeSorter` and `sort.initialize`_ * * @param sorters Sorters to use for sorting * @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_ * @returns Sort handler */ declare function initializeSorter(sorters: Array>, descending?: boolean): Sorter; /** * Initialize a sort handler with a sorter _(and an optional default direction)_ * * _Available as `initializeSorter` and `sort.initialize`_ * * @param sorter Sorter to use for sorting * @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_ * @returns Sort handler */ declare function initializeSorter(sorter: ArraySorter, descending?: boolean): Sorter; /** * Initialize a sort handler _(with an optional default direction)_ * * _Available as `initializeSorter` and `sort.initialize`_ * * @param descending Sort in descending order? _(defaults to `false`)_ * @returns Sort handler */ declare function initializeSorter(descending?: boolean): Sorter; /** * Is the array sorted according to the sorters _(and the optional default direction)_? * * @param array Array to check * @param sorters Sorters to determine sorting * @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_ * @returns `true` if sorted, otherwise `false` */ declare function isSorted(array: Item[], sorters: Array>, descending?: boolean): boolean; /** * Is the array sorted according to the sorter _(and the optional default direction)_? * * @param array Array to check * @param sorter Sorter to determine sorting * @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_ * @returns `true` if sorted, otherwise `false` */ declare function isSorted(array: Item[], sorter: ArraySorter, descending?: boolean): boolean; /** * Is the array sorted? * * _Available as `isSorted` and `sort.is`_ * * @param array Array to check * @param descending Sorted in descending order? _(defaults to `false`)_ * @returns `true` if sorted, otherwise `false` */ declare function isSorted(array: Item[], descending?: boolean): boolean; /** * Sort an array of items using a comparison callback * * @param array Array to sort * @param comparator Comparator to use for sorting * @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_ * @returns Sorted array * * @example * ```typescript * sort( * [{id: 3}, {id: 1}, {id: 2}], * (first, second) => first.id - second.id, * ); // => [{id: 1}, {id: 2}, {id: 3}] * ``` */ declare function sort(array: Item[], comparator: (first: Item, second: Item) => number, descending?: boolean): Item[]; /** * Sort an array of items, using multiple sorters to sort by specific values * * @param array Array to sort * @param sorters Sorters to use for sorting * @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_ * @returns Sorted array */ declare function sort(array: Item[], sorters: Array>, descending?: boolean): Item[]; /** * Sort an array of items, using a single sorter to sort by a specific value * * @param array Array to sort * @param sorter Sorter to use for sorting * @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_ * @returns Sorted array */ declare function sort(array: Item[], sorter: ArraySorter, descending?: boolean): Item[]; /** * Sort an array of items * * @param array Array to sort * @param descending Sort in descending order? _(defaults to `false`)_ * @returns Sorted array */ declare function sort(array: Item[], descending?: boolean): Item[]; declare namespace sort { var getIndex: typeof getSortedIndex; var initialize: typeof initializeSorter; var is: typeof isSorted; } declare const SORT_DIRECTION_ASCENDING: SortDirection; declare const SORT_DIRECTION_DESCENDING: SortDirection; //#endregion //#region src/array/swap.d.ts /** * Swap two smaller arrays within a larger array * * If either of the smaller arrays are not present in the larger array, or if they overlap, the larger array will be returned unchanged * * @param array Array of items to swap * @param first First array * @param second Second array * @param callback Callback to get an item's value for matching * @returns Original array with items swapped _(or unchanged if unable to swap)_ * * @example * ```typescript * swap( * [ * {id: 1, name: 'Alice'}, * {id: 2, name: 'Bob'}, * {id: 3, name: 'Charlie'}, * ], * [ * {id: 2, name: 'Bob'}, * ], * [ * {id: 3, name: 'Charlie'}, * ], * item => item.id, * ); // => [ * // {id: 1, name: 'Alice'}, * // {id: 3, name: 'Charlie'}, * // {id: 2, name: 'Bob'}, * // ] * ``` */ declare function swap(array: Item[], first: Item[], second: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[]; /** * Swap two smaller arrays within a larger array * * If either of the smaller arrays are not present in the larger array, or if they overlap, the larger array will be returned unchanged * * @param array Array of items to swap * @param first First array * @param second Second array * @param key Key to get an item's value for matching * @returns Original array with items swapped _(or unchanged if unable to swap)_ * * @example * ```typescript * swap( * [ * {id: 1, name: 'Alice'}, * {id: 2, name: 'Bob'}, * {id: 3, name: 'Charlie'}, * ], * [ * {id: 2, name: 'Bob'}, * ], * [ * {id: 3, name: 'Charlie'}, * ], * 'id', * ); // => [ * // {id: 1, name: 'Alice'}, * // {id: 3, name: 'Charlie'}, * // {id: 2, name: 'Bob'}, * // ] * ``` */ declare function swap(array: Item[], first: Item[], second: Item[], key: ItemKey): Item[]; /** * Swap two smaller arrays within a larger array * * If either of the smaller arrays are not present in the larger array, or if they overlap, the larger array will be returned unchanged * * @param array Array of items to swap * @param first First array * @param second Second array * @returns Original array with items swapped _(or unchanged if unable to swap)_ * * @example * ```typescript * swap( * [1, 2, 3, 4, 5, 6], * [1, 2], * [5, 6], * ); // => [5, 6, 3, 4, 1, 2] * ``` */ declare function swap(array: Item[], first: Item[], second: Item[]): Item[]; /** * Swap two indiced items in an array * * If either of the items are not present in the array, the array will be returned unchanged * * @param array Array of items to swap * @param first First item * @param second Second item * @param callback Callback to get an item's value for matching * @returns Original array with items swapped _(or unchanged if unable to swap)_ * * @example * ```typescript * swap( * [ * {id: 1, name: 'Alice'}, * {id: 2, name: 'Bob'}, * {id: 3, name: 'Charlie'}, * ], * {id: 2, name: 'Bob'}, * {id: 3, name: 'Charlie'}, * item => item.id, * ); // => [ * // {id: 1, name: 'Alice'}, * // {id: 3, name: 'Charlie'}, * // {id: 2, name: 'Bob'}, * // ] * ``` */ declare function swap(array: Item[], first: Item, second: Item, callback: (item: Item, index: number, array: Item[]) => unknown): Item[]; /** * Swap two indiced items in an array * * If either of the items are not present in the array, the array will be returned unchanged * * @param array Array of items to swap * @param first First item * @param second Second item * @param key Key to get an item's value for matching * @returns Original array with items swapped _(or unchanged if unable to swap)_ * * @example * ```typescript * swap( * [ * {id: 1, name: 'Alice'}, * {id: 2, name: 'Bob'}, * {id: 3, name: 'Charlie'}, * ], * {id: 2, name: 'Bob'}, * {id: 3, name: 'Charlie'}, * 'id', * ); // => [ * // {id: 1, name: 'Alice'}, * // {id: 3, name: 'Charlie'}, * // {id: 2, name: 'Bob'}, * // ] * ``` */ declare function swap(array: Item[], first: Item, second: Item, key: ItemKey): Item[]; /** * Swap two indiced items in an array * * @param array Array of items to swap * @param first First item * @param second Second item * @returns Original array with items swapped _(or unchanged if unable to swap)_ * * @example * ```typescript * swap( * [1, 2, 3, 4, 5, 6], * 2, * 5, * ); // => [1, 5, 3, 4, 2, 6] * ``` */ declare function swap(array: Item[], first: Item, second: Item): Item[]; declare namespace swap { var indices: typeof swapIndices; } /** * Swap two indiced items in an array * * If either index is out of bounds, the array will be returned unchanged * * _Available as `swapIndices` and `swap.indices`_ * * @param array Array of items to swap * @param first First index _(can be negative to count from the end)_ * @param second Second index _(can be negative to count from the end)_ * @returns Original array with items swapped _(or unchanged if unable to swap)_ */ declare function swapIndices(array: Item[], first: number, second: number): Item[]; //#endregion //#region src/array/to-map.d.ts /** * Create a _Map_ from an array of items using callbacks * * If multiple items have the same key, the latest item's value will be used * * @param array Array to convert * @param key Callback to get an item's grouping key * @param value Callback to get an item's value * @returns _Map_ of keyed values * * @example * ```typescript * toMap( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * item => item.id, * ); // => Map { 10 => 3, 20 => 2 } * ``` */ declare function toMap Key$1, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Map, ReturnType>; /** * Create a _Map_ from an array of items using a callback and value * * If multiple items have the same key, the latest item's value will be used * * @param array Array to convert * @param key Callback to get an item's grouping key * @param value Key to use for value * @returns _Map_ of keyed values * * @example * ```typescript * toMap( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * 'id', * ); // => Map { 10 => 3, 20 => 2 } * ``` */ declare function toMap Key$1, ItemValue extends keyof Item>(array: Item[], key: KeyCallback, value: ItemValue): Map, Item[ItemValue]>; /** * Create a _Map_ from an array of items using a key and callback * * If multiple items have the same key, the latest item's value will be used * * @param array Array to convert * @param key Key to use for grouping * @param value Callback to get an item's value * @returns _Map_ of keyed values * * @example * ```typescript * toMap( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * item => item.id, * ); // => Map { 10 => 3, 20 => 2 } * ``` */ declare function toMap unknown>(array: Item[], key: ItemKey, value: ValueCallback): Map>; /** * Create a _Map_ from an array of items using a key and value * * If multiple items have the same key, the latest item's value will be used * * @param array Array to convert * @param key Key to use for grouping * @param value Key to use for value * @returns _Map_ of keyed values * * @example * ```typescript * toMap( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * 'id', * ); // => Map { 10 => 3, 20 => 2 } * ``` */ declare function toMap(array: Item[], key: ItemKey, value: ItemValue): Map; /** * Create a _Map_ from an array of items using a callback * * If multiple items have the same key, the latest item will be used * * @param array Array to convert * @param callback Callback to get an item's grouping key * @returns _Map_ of keyed items * * @example * ```typescript * toMap( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * ); // => Map { 10 => {id: 3, value: 10}, 20 => {id: 2, value: 20} } * ``` */ declare function toMap Key$1>(array: Item[], callback: Callback): Map, Item>; /** * Create a _Map_ from an array of items using a key * * If multiple items have the same key, the latest item will be used * * @param array Array to convert * @param key Key to use for grouping * @returns _Map_ of keyed items * * @example * ```typescript * toMap( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * ); // => Map { 10 => {id: 3, value: 10}, 20 => {id: 2, value: 20} } * ``` */ declare function toMap(array: Item[], key: ItemKey): Map; /** * Create a _Map_ from an array of items _(using indices as keys)_ * * @param array Array to convert * @returns _Map_ of indiced items * * @example * ```typescript * toMap( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * ); // => Map { 0 => {id: 1, value: 10}, 1 => {id: 2, value: 20}, 2 => {id: 3, value: 10} } * ``` */ declare function toMap(array: Item[]): Map; declare namespace toMap { var arrays: typeof toMapArrays; } /** * Create a _Map_ from an array of items using callbacks, grouping values into arrays * * _Available as `toMapArrays` and `toMap.arrays`_ * * @param array Array to convert * @param key Callback to get an item's grouping key * @param value Callback to get an item's value * @returns _Map_ of keyed arrays of values * * @example * ```typescript * toMapArrays( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * item => item.id, * ); // => Map { 10 => [1, 3], 20 => [2] } * ``` */ declare function toMapArrays Key$1, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Map, ReturnType[]>; /** * Create a _Map_ from an array of items using a callback and value, grouping values into arrays * * _Available as `toMapArrays` and `toMap.arrays`_ * * @param array Array to convert * @param key Callback to get an item's grouping key * @param value Key to use for value * @returns _Map_ of keyed arrays of values * * @example * ```typescript * toMapArrays( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * 'id', * ); // => Map { 10 => [1, 3], 20 => [2] } * ``` */ declare function toMapArrays Key$1, ItemValue extends keyof Item>(array: Item[], key: KeyCallback, value: ItemValue): Map, Item[ItemValue][]>; /** * Create a _Map_ from an array of items using a key and callback, grouping values into arrays * * _Available as `toMapArrays` and `toMap.arrays`_ * * @param array Array to convert * @param key Key to use for grouping * @param value Callback to get an item's value * @returns _Map_ of keyed arrays of values * * @example * ```typescript * toMapArrays( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * item => item.id, * ); // => Map { 10 => [1, 3], 20 => [2] } * ``` */ declare function toMapArrays unknown>(array: Item[], key: ItemKey, value: ValueCallback): Map[]>; /** * Create a _Map_ from an array of items using a key and value, grouping values into arrays * * _Available as `toMapArrays` and `toMap.arrays`_ * * @param array Array to convert * @param key Key to use for grouping * @param value Key to use for value * @returns _Map_ of keyed arrays of values * * @example * ```typescript * toMapArrays( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * 'id', * ); // => Map { 10 => [1, 3], 20 => [2] } * ``` */ declare function toMapArrays(array: Item[], key: ItemKey, value: ItemValue): Map; /** * Create a _Map_ from an array of items using a callback, grouping items into arrays * * _Available as `toMapArrays` and `toMap.arrays`_ * * @param array Array to convert * @param callback Callback to get an item's grouping key * @returns _Map_ of keyed arrays of items * * @example * ```typescript * toMapArrays( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * ); // => Map { 10 => [{id: 1, value: 10}, {id: 3, value: 10}], 20 => [{id: 2, value: 20}] } * ``` */ declare function toMapArrays Key$1>(array: Item[], callback: Callback): Map, Item[]>; /** * Create a _Map_ from an array of items using a key, grouping items into arrays * * _Available as `toMapArrays` and `toMap.arrays`_ * * @param array Array to convert * @param key Key to use for grouping * @returns _Map_ of keyed arrays of items * * @example * ```typescript * toMapArrays( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * ); // => Map { 10 => [{id: 1, value: 10}, {id: 3, value: 10}], 20 => [{id: 2, value: 20}] } * ``` */ declare function toMapArrays(array: Item[], key: ItemKey): Map; //#endregion //#region src/array/to-record.d.ts /** * Create a record from an array of items using callbacks * * If multiple items have the same key, the latest item will be used * * @param array Array to convert * @param key Callback to get an item's grouping key * @param value Callback to get an item's value * @returns Record of keyed values * * @example * ```typescript * toRecord( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * item => item.id, * ); // => { 10: 3, 20: 2 } * ``` */ declare function toRecord Key$1, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Record, ReturnType>; /** * Create a record from an array of items using a callback and value * * If multiple items have the same key, the latest item will be used * * @param array Array to convert * @param callback Callback to get an item's grouping key * @param value Key to use for value * @returns Record with keys * * @example * ```typescript * toRecord( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * 'id', * ); // => { 10: 3, 20: 2 } * ``` */ declare function toRecord Key$1, ItemValue extends keyof Item>(array: Item[], callback: Callback, value: ItemValue): Record, Item[ItemValue]>; /** * Create a record from an array of items using a key and callback * * If multiple items have the same key, the latest item will be used * * @param array Array to convert * @param key Key to use for grouping * @param callback Callback to get an item's value * @returns Record with keys * * @example * ```typescript * toRecord( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * item => item.id, * ); // => { 10: 3, 20: 2 } * ``` */ declare function toRecord unknown>(array: Item[], key: ItemKey, callback: Callback): Simplify, ReturnType>>; /** * Create a record from an array of items using a key and value * * If multiple items have the same key, the latest item will be used * * @param array Array to convert * @param key Key to use for grouping * @param value Key to use for value * @returns Record of keyed values * * @example * ```typescript * toRecord( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * 'id', * ); // => { 10: 3, 20: 2 } * ``` */ declare function toRecord(array: Item[], key: ItemKey, value: ItemValue): Simplify, Item[ItemValue]>>; /** * Create a record from an array of items using a callback * * If multiple items have the same key, the latest item will be used * * @param array Array to convert * @param callback Callback to get an item's grouping key * @returns Record of keyed values * * @example * ```typescript * toRecord( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * ); // => { 10: {id: 3, value: 10}, 20: {id: 2, value: 20} } * ``` */ declare function toRecord Key$1>(array: Item[], callback: Callback): Record, Item>; /** * Create a record from an array of items using a key * * If multiple items have the same key, the latest item will be used * * @param array Array to convert * @param key Key to use for grouping * @returns Record of keyed values * * @example * ```typescript * toRecord( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * ); // => { 10: {id: 3, value: 10}, 20: {id: 2, value: 20} } * ``` */ declare function toRecord(array: Item[], key: ItemKey): Simplify, Item>>; /** * Create a record from an array of items _(using indices as keys)_ * * @param array Array to convert * @returns Record of indiced values * * @example * ```typescript * toRecord( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * ); // => { 0: {id: 1, value: 10}, 1: {id: 2, value: 20}, 2: {id: 3, value: 10} } * ``` */ declare function toRecord(array: Item[]): Record; declare namespace toRecord { var arrays: typeof toRecordArrays; } /** * Create a record from an array of items using callbacks, grouping values into arrays * * _Available as `toRecordArrays` and `toRecord.arrays`_ * * @param array Array to convert * @param key Callback to get an item's grouping key * @param value Callback to get an item's value * @returns Record of keyed arrays of values * * @example * ```typescript * toRecordArrays( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * item => item.id, * ); // => { 10: [1, 3], 20: [2] } * ``` */ declare function toRecordArrays Key$1, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Record, ReturnType[]>; /** * Create a record from an array of items using a callback and value, grouping values into arrays * * _Available as `toRecordArrays` and `toRecord.arrays`_ * * @param array Array to convert * @param callback Callback to get an item's grouping key * @param value Key to use for value * @returns Record of keyed arrays of values * * @example * ```typescript * toRecordArrays( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * 'id', * ); // => { 10: [1, 3], 20: [2] } * ``` */ declare function toRecordArrays Key$1, ItemValue extends keyof Item>(array: Item[], callback: Callback, value: ItemValue): Record, Item[ItemValue][]>; /** * Create a record from an array of items using a key and callback, grouping values into arrays * * _Available as `toRecordArrays` and `toRecord.arrays`_ * * @param array Array to convert * @param key Key to use for grouping * @param callback Callback to get an item's value * @returns Record of keyed arrays of values * * @example * ```typescript * toRecordArrays( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * item => item.id, * ); // => { 10: [1, 3], 20: [2] } * ``` */ declare function toRecordArrays unknown>(array: Item[], key: ItemKey, callback: Callback): Simplify, ReturnType[]>>; /** * Create a record from an array of items using a key and value, grouping values into arrays * * _Available as `toRecordArrays` and `toRecord.arrays`_ * * @param array Array to convert * @param key Key to use for grouping * @param value Key to use for value * @returns Record of keyed arrays of values * * @example * ```typescript * toRecordArrays( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * 'id', * ); // => { 10: [1, 3], 20: [2] } * ``` */ declare function toRecordArrays(array: Item[], key: ItemKey, value: ItemValue): Simplify, Item[ItemValue][]>>; /** * Create a record from an array of items using a callback, grouping items into arrays * * _Available as `toRecordArrays` and `toRecord.arrays`_ * * @param array Array to convert * @param callback Callback to get an item's grouping key * @returns Record of keyed arrays of items * * @example * ```typescript * toRecordArrays( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * ); // => { 10: [{id: 1, value: 10}, {id: 3, value: 10}], 20: [{id: 2, value: 20}] } * ``` */ declare function toRecordArrays Key$1>(array: Item[], callback: Callback): Record, Item[]>; /** * Create a record from an array of items using a key, grouping items into arrays * * _Available as `toRecordArrays` and `toRecord.arrays`_ * * @param array Array to convert * @param key Key to use for grouping * @returns Record of keyed arrays of items * * @example * ```typescript * toRecordArrays( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * ); // => { 10: [{id: 1, value: 10}, {id: 3, value: 10}], 20: [{id: 2, value: 20}] } * ``` */ declare function toRecordArrays(array: Item[], key: ItemKey): Simplify, Item[]>>; //#endregion //#region src/function/assert.d.ts /** * Asserter for a property of a value */ type AssertProperty, Asserted extends NestedPick = NestedPick> = Asserter; /** * A function that asserts a value is of a specific type, throwing an error if it is not */ type Asserter = (value: unknown) => asserts value is Value; type NestedPick = Value extends PlainObject ? Path extends `${infer Head}.${infer Rest}` ? Head extends keyof Value ? { [Key in Head]: NestedPick } : never : Path extends keyof Value ? { [Key in Path]: Value[Key] } : never : never; /** * Asserts that a condition is true, throwing an error if it is not * * @param condition Condition to assert * @param message Error message * @param error Error constructor _(defaults to `Error`)_ */ declare function assert boolean>(condition: Condition, message: string, error?: ErrorConstructor): asserts condition; declare namespace assert { var condition: typeof assertCondition; var defined: typeof assertDefined; var instanceOf: typeof assertInstanceOf; var is: typeof assertIs; var property: typeof assertProperty; } /** * Creates an _Asserter_ that asserts a condition is true, throwing an error if it is not * * _Available as `assertCondition` and `assert.condition`_ * * @param condition Condition to assert * @param message Error message * @param error Error constructor _(defaults to `Error`)_ * @returns _Asserter_ */ declare function assertCondition(condition: (value: unknown) => boolean, message: string, error?: ErrorConstructor): Asserter; /** * Asserts that a value is defined, throwing an error if it is not * * _Available as `assertDefined` and `assert.defined`_ * * @param value Value to assert * @param message Error message * @param error Error constructor _(defaults to `Error`)_ */ declare function assertDefined(value: unknown, message?: string, error?: ErrorConstructor): asserts value is Exclude; /** * Creates an _Asserter_ that asserts a value is an instance of a constructor, throwing an error if it is not * * _Available as `assertInstanceOf` and `assert.instanceOf`_ * * @param constructor Constructor to check against * @param message Error message * @param error Error constructor _(defaults to `Error`)_ * @returns _Asserter_ */ declare function assertInstanceOf(constructor: Constructor, message: string, error?: ErrorConstructor): Asserter; /** * Creates an _Asserter_ that asserts a value is of a specific type, throwing an error if it is not * * _Available as `assertIs` and `assert.is`_ * * @param condition Type guard function to check the value * @param message Error message * @param error Error constructor _(defaults to `Error`)_ * @returns _Asserter_ */ declare function assertIs(condition: (value: unknown) => value is Value, message: string, error?: ErrorConstructor): Asserter; /** * Creates an _Asserter_ that asserts a property of a value exists and satisfies a condition, throwing an error if it does not * * _Available as `assertProperty` and `assert.property`_ * * @param path Path to the property to check, e.g., `foo.bar.baz` for a nested property * @param condition Condition to assert for the property * @param message Error message * @param error Error constructor _(defaults to `Error`)_ * @returns _Asserter_ */ declare function assertProperty, Asserted = NestedPick>(path: Path, condition: (value: NestedValue) => boolean, message: string, error?: ErrorConstructor): Asserter; //#endregion //#region src/internal/function/misc.d.ts /** * A function that does nothing, which can be useful, I guess… */ declare function noop(): void; //#endregion //#region src/function/memoize.d.ts /** * A _Memoized_ function instance, caching and retrieving results based on the its parameters _(or a custom cache key)_ */ declare class Memoized { #private; /** * Maximum cache size * * @returns Maximum cache size _(or `Number.NaN` if the instance has been destroyed)_ */ get maximum(): number; /** * Current cache size * * @returns Current cache size _(or `Number.NaN` if the instance has been destroyed)_ */ get size(): number; constructor(callback: Callback, options: Options); /** * Clear the cache */ clear(): void; /** * Delete a result from the cache * * @param key Key to delete * @returns `true` if the key existed and was removed, otherwise `false` */ delete(key: unknown): boolean; /** * Destroy the instance * * _(When a Memoized instance is destroyed, its cache and callback are removed, and calls to `run` will throw an error)_ */ destroy(): void; /** * Get a result from the cache * * @param key Key to get * @returns Cached result or `undefined` if it does not exist */ get(key: unknown): ReturnType | undefined; /** * Does the result exist? * * @param key Key to check * @returns `true` if the result exists, otherwise `false` */ has(key: unknown): boolean; /** * Run the callback with the provided parameters * * @param parameters Parameters to pass to the callback * @returns Cached or computed _(then cached)_ result */ run(...parameters: Parameters): ReturnType; } /** * Options for a _Memoized_ function */ type MemoizedOptions = { /** * Callback for getting a cache key for the provided parameters */ cacheKey?: (...parameters: Parameters) => unknown; /** * Size of the cache */ cacheSize?: number; }; type Options = { cacheKey?: GenericCallback; cacheSize: number; }; /** * Memoize a function, caching and retrieving results based on the first parameter * * @param callback Callback to memoize * @param options Memoization options * @returns _Memoized_ instance */ declare function memoize(callback: Callback, options?: MemoizedOptions): Memoized; //#endregion //#region src/function/limit.d.ts /** * Debounce a function, ensuring it is only called after `time` milliseconds have passed * * - When called, successful _(finished)_ results will resolve and errors will reject * - On subsequent calls, existing calls will be canceled _(rejected)_, the timer reset, and will wait another `time` milliseconds before the new call is made _(and so on...)_ * * _Available as `asyncDebounce` and `debounce.async`_ * * @param callback Callback to debounce * @param time Time in milliseconds to wait before calling the callback _(defaults to `0`; e.g., as soon as possible)_ * @returns Debounced callback handler with a `cancel` method */ declare function asyncDebounce(callback: Callback, time?: number): AsyncCancelableCallback; /** * Throttle a function, ensuring it is only called once every `time` milliseconds * * - When called, successful _(finished)_ results will resolve and errors will reject * - On subsequent calls, existing calls will be canceled _(rejected)_ and will wait until the next valid time to call the callback again _(and so on...)_ * * _Available as `asyncThrottle` and `throttle.async`_ * * @param callback Callback to throttle * @param time Time in milliseconds to wait before calling the callback again _(defaults to `0`; e.g., as soon as possible)_ * @returns Throttled callback handler with a `cancel` method */ declare function asyncThrottle(callback: Callback, time?: number): AsyncCancelableCallback; /** * Debounce a function, ensuring it is only called after `time` milliseconds have passed * * On subsequent calls, the timer is reset and will wait another `time` milliseconds _(and so on...)_ * * @param callback Callback to debounce * @param time Time in milliseconds to wait before calling the callback _(defaults to `0`; e.g., as soon as possible)_ * @returns Debounced callback handler with a `cancel` method */ declare function debounce(callback: Callback, time?: number): CancelableCallback; declare namespace debounce { var async: typeof asyncDebounce; } /** * Throttle a function, ensuring it is only called once every `time` milliseconds * * @param callback Callback to throttle * @param time Time in milliseconds to wait before calling the callback again _(defaults to `0`; e.g., as soon as possible)_ * @returns Throttled callback handler with a `cancel` method */ declare function throttle(callback: Callback, time?: number): CancelableCallback; declare namespace throttle { var async: typeof asyncThrottle; } //#endregion //#region src/function/once.d.ts /** * Create an asynchronous function that can only be called once, rejecting or resolving the same result on subsequent calls * * _Available as `asyncOnce` and `once.async`_ * * @param callback Callback to use once * @returns _Once_ callback */ declare function asyncOnce(callback: Callback): OnceAsyncCallback; /** * Create a function that can only be called once, returning the same value on subsequent calls * * @param callback Callback to use once * @returns _Once_ callback */ declare function once(callback: Callback): OnceCallback; declare namespace once { var async: typeof asyncOnce; } //#endregion //#region src/function/retry.d.ts /** * An error thrown when a retry fails */ declare class RetryError extends Error { readonly original: unknown; constructor(message: string, original: unknown); } type RetryOptions = { delay?: number; times?: number; when?: (error: unknown) => boolean; }; /** * Retry a callback a specified number of times, with a delay between attempts * * _Available as `asyncRetry` and `retry.async`_ * * @param callback Callback to retry * @param options Retry options * @returns Callback result */ declare function asyncRetry(callback: Callback, options?: RetryOptions): Promise>>; /** * Retry a callback a specified number of times, with a delay between attempts * * _Available as `asyncRetry` and `retry.async`_ * * @param callback Callback to retry * @param options Retry options * @returns Callback result */ declare function asyncRetry(callback: Callback, options?: RetryOptions): Promise>; /** * Retry a callback a specified number of times * * @param callback Callback to retry * @param options Retry options * @returns Callback result */ declare function retry(callback: Callback, options?: Omit): ReturnType; declare namespace retry { var async: typeof asyncRetry; } //#endregion //#region src/result/models.d.ts /** * An unknown result */ type AnyResult = Err | ExtendedErr | Ok; /** * An error result */ type Err = { ok: false; error: Error; }; /** * An extended error result */ type ExtendedErr = Err & { original: Error; }; /** * An extended, unknown result */ type ExtendedResult = ExtendedErr | Ok; /** * A successful result */ type Ok = { ok: true; value: Value; }; /** * An unknown result */ type Result = Err | Ok; /** * Match callbacks for a result */ type ResultMatch = { /** * Callback for error result * * @param error Error value * @param original Original error, if available * @returns Value to return */ error: (error: E, original?: Error) => Returned; /** * Callback for ok result * * @param value Ok value * @returns Value to return */ ok: (value: Value) => Returned; }; /** * Unwrap a result value */ type UnwrapResult> = Original extends Ok ? Value : never; /** * Unwrap any value */ type UnwrapValue = Original extends GenericCallback ? ReturnType extends Result ? UnwrapResult> : ReturnType : Original extends Result ? UnwrapResult : Original extends Promise ? Awaited : Original; //#endregion //#region src/function/work.d.ts /** * A synchronous _Flow_, a function that pipe a value through a series of functions */ type Flow = (...args: Parameters) => UnwrapValue; /** * An asynchronous _Flow_, a function that pipes a value through a series of functions */ type FlowPromise = (...args: Parameters) => Promise>; /** * Create an asynchronous _Flow_, a function that pipes values through a function * * _Available as `asyncFlow` and `flow.async`_ * * @returns _Flow_ function */ declare function asyncFlow(fn: Fn): FlowPromise>; /** * Create an asynchronous _Flow_, a function that pipes values through a series of functions * * _Available as `asyncFlow` and `flow.async`_ * * @returns _Flow_ function */ declare function asyncFlow(first: First, second: (value: Awaited>>) => Second): FlowPromise; /** * Create an asynchronous _Flow_, a function that pipes values through a series of functions * * _Available as `asyncFlow` and `flow.async`_ * * @returns _Flow_ function */ declare function asyncFlow(first: First, second: (value: Awaited>>) => Second, third: (value: Awaited>) => Third): FlowPromise; /** * Create an asynchronous _Flow_, a function that pipes values through a series of functions * * _Available as `asyncFlow` and `flow.async`_ * * @returns _Flow_ function */ declare function asyncFlow(first: First, second: (value: Awaited>>) => Second, third: (value: Awaited>) => Third, fourth: (value: Awaited>) => Fourth): FlowPromise; /** * Create an asynchronous _Flow_, a function that pipes values through a series of functions * * _Available as `asyncFlow` and `flow.async`_ * * @returns _Flow_ function */ declare function asyncFlow(first: First, second: (value: Awaited>>) => Second, third: (value: Awaited>) => Third, fourth: (value: Awaited>) => Fourth, fifth: (value: Awaited>) => Fifth): FlowPromise; /** * Create an asynchronous _Flow_, a function that pipes values through a series of functions * * _Available as `asyncFlow` and `flow.async`_ * * @returns _Flow_ function */ declare function asyncFlow(first: First, second: (value: Awaited>>) => Second, third: (value: Awaited>) => Third, fourth: (value: Awaited>) => Fourth, fifth: (value: Awaited>) => Fifth, sixth: (value: Awaited>) => Sixth): FlowPromise; /** * Create an asynchronous _Flow_, a function that pipes values through a series of functions * * _Available as `asyncFlow` and `flow.async`_ * * @returns _Flow_ function */ declare function asyncFlow(first: First, second: (value: Awaited>>) => Second, third: (value: Awaited>) => Third, fourth: (value: Awaited>) => Fourth, fifth: (value: Awaited>) => Fifth, sixth: (value: Awaited>) => Sixth, seventh: (value: Awaited>) => Seventh): FlowPromise; /** * Create an asynchronous _Flow_, a function that pipes values through a series of functions * * _Available as `asyncFlow` and `flow.async`_ * * @returns _Flow_ function */ declare function asyncFlow(first: First, second: (value: Awaited>>) => Second, third: (value: Awaited>) => Third, fourth: (value: Awaited>) => Fourth, fifth: (value: Awaited>) => Fifth, sixth: (value: Awaited>) => Sixth, seventh: (value: Awaited>) => Seventh, eighth: (value: Awaited>) => Eighth): FlowPromise; /** * Create an asynchronous _Flow_, a function that pipes values through a series of functions * * _Available as `asyncFlow` and `flow.async`_ * * @returns _Flow_ function */ declare function asyncFlow(first: First, second: (value: Awaited>>) => Second, third: (value: Awaited>) => Third, fourth: (value: Awaited>) => Fourth, fifth: (value: Awaited>) => Fifth, sixth: (value: Awaited>) => Sixth, seventh: (value: Awaited>) => Seventh, eighth: (value: Awaited>) => Eighth, ninth: (value: Awaited>) => Ninth): FlowPromise; /** * Create an asynchronous _Flow_, a function that pipes values through a series of functions * * _Available as `asyncFlow` and `flow.async`_ * * @returns _Flow_ function */ declare function asyncFlow(first: First, second: (value: Awaited>>) => Second, third: (value: Awaited>) => Third, fourth: (value: Awaited>) => Fourth, fifth: (value: Awaited>) => Fifth, sixth: (value: Awaited>) => Sixth, seventh: (value: Awaited>) => Seventh, eighth: (value: Awaited>) => Eighth, ninth: (value: Awaited>) => Ninth, tenth: (value: Awaited>) => Tenth): FlowPromise; /** * Create an asynchronous _Flow_, a function that pipes values through a series of functions * * _Available as `asyncFlow` and `flow.async`_ * * @returns _Flow_ function */ declare function asyncFlow(fn: Fn, ...fns: Array<(value: Awaited>>) => unknown>): FlowPromise>; /** * Create an asynchronous _Flow_, a function that pipes values through a series of functions * * _Available as `asyncFlow` and `flow.async`_ * * @returns _Flow_ function */ declare function asyncFlow(...fns: GenericCallback[]): (...args: unknown[]) => Promise; /** * Create a _Flow_, a function that pipes values through a function * * @returns _Flow_ function */ declare function flow(fn: Fn): Flow>; /** * Create a _Flow_, a function that pipes values through a series of functions * * @returns _Flow_ function */ declare function flow(first: First, second: (value: UnwrapValue>) => Second): Flow; /** * Create a _Flow_, a function that pipes values through a series of functions * * @returns _Flow_ function */ declare function flow(first: First, second: (value: UnwrapValue>) => Second, third: (value: UnwrapValue) => Third): Flow; /** * Create a _Flow_, a function that pipes values through a series of functions * * @returns _Flow_ function */ declare function flow(first: First, second: (value: UnwrapValue>) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth): Flow; /** * Create a _Flow_, a function that pipes values through a series of functions * * @returns _Flow_ function */ declare function flow(first: First, second: (value: UnwrapValue>) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth): Flow; /** * Create a _Flow_, a function that pipes values through a series of functions * * @returns _Flow_ function */ declare function flow(first: First, second: (value: UnwrapValue>) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth): Flow; /** * Create a _Flow_, a function that pipes values through a series of functions * * @returns _Flow_ function */ declare function flow(first: First, second: (value: UnwrapValue>) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh): Flow; /** * Create a _Flow_, a function that pipes values through a series of functions * * @returns _Flow_ function */ declare function flow(first: First, second: (value: UnwrapValue>) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh, eighth: (value: UnwrapValue) => Eighth): Flow; /** * Create a _Flow_, a function that pipes values through a series of functions * * @returns _Flow_ function */ declare function flow(first: First, second: (value: UnwrapValue>) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh, eighth: (value: UnwrapValue) => Eighth, ninth: (value: UnwrapValue) => Ninth): Flow; /** * Create a _Flow_, a function that pipes values through a series of functions * * @returns _Flow_ function */ declare function flow(first: First, second: (value: UnwrapValue>) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh, eighth: (value: UnwrapValue) => Eighth, ninth: (value: UnwrapValue) => Ninth, tenth: (value: UnwrapValue) => Tenth): Flow; /** * Create a _Flow_, a function that pipes values through a series of functions * * @returns _Flow_ function */ declare function flow(first: First, ...fns: Array<(value: UnwrapValue>) => unknown>): Flow>; /** * Create a _Flow_, a function that pipes values through a series of functions * * @returns _Flow_ function */ declare function flow(...fns: GenericCallback[]): (...args: unknown[]) => unknown; declare namespace flow { var async: typeof asyncFlow; } /** * Pipe a value through a function * * _Available as `asyncPipe` and `pipe.async`_ * * @param value Initial value * @returns _Piped_ result */ declare function asyncPipe(value: Initial, pipe: (value: UnwrapValue) => Piped): Promise>; /** * Pipe a value through a series of functions * * _Available as `asyncPipe` and `pipe.async`_ * * @param value Initial value * @returns _Piped_ result */ declare function asyncPipe(value: Initial, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second): Promise>; /** * Pipe a value through a series of functions * * _Available as `asyncPipe` and `pipe.async`_ * * @param value Initial value * @returns _Piped_ result */ declare function asyncPipe(value: Initial, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third): Promise>; /** * Pipe a value through a series of functions * * _Available as `asyncPipe` and `pipe.async`_ * * @param value Initial value * @returns _Piped_ result */ declare function asyncPipe(value: Initial, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth): Promise>; /** * Pipe a value through a series of functions * * _Available as `asyncPipe` and `pipe.async`_ * * @param value Initial value * @returns _Piped_ result */ declare function asyncPipe(value: Initial, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth): Promise>; /** * Pipe a value through a series of functions * * _Available as `asyncPipe` and `pipe.async`_ * * @param value Initial value * @returns _Piped_ result */ declare function asyncPipe(value: Initial, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth): Promise>; /** * Pipe a value through a series of functions * * _Available as `asyncPipe` and `pipe.async`_ * * @param value Initial value * @returns _Piped_ result */ declare function asyncPipe(value: Initial, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh): Promise>; /** * Pipe a value through a series of functions * * _Available as `asyncPipe` and `pipe.async`_ * * @param value Initial value * @returns _Piped_ result */ declare function asyncPipe(value: Initial, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh, eighth: (value: UnwrapValue) => Eighth): Promise>; /** * Pipe a value through a series of functions * * _Available as `asyncPipe` and `pipe.async`_ * * @param value Initial value * @returns _Piped_ result */ declare function asyncPipe(value: Initial, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh, eighth: (value: UnwrapValue) => Eighth, ninth: (value: UnwrapValue) => Ninth): Promise>; /** * Pipe a value through a series of functions * * _Available as `asyncPipe` and `pipe.async`_ * * @param value Initial value * @returns _Piped_ result */ declare function asyncPipe(value: Initial, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh, eighth: (value: UnwrapValue) => Eighth, ninth: (value: UnwrapValue) => Ninth, tenth: (value: UnwrapValue) => Tenth): Promise>; /** * Pipe a value through a series of functions * * _Available as `asyncPipe` and `pipe.async`_ * * @param value Initial value * @returns _Piped_ result */ declare function asyncPipe(value: Value, ...pipes: Array<(value: Value) => Value>): Promise>; /** * Pipe a value through a series of functions * * _Available as `asyncPipe` and `pipe.async`_ * * @param value Initial value * @returns _Piped_ result */ declare function asyncPipe(value: unknown, ...pipes: Array<(value: unknown) => unknown>): Promise; /** * Pipe a value through a function * * @param value Initial value * @returns _Piped_ result */ declare function pipe(value: Initial, pipe: (value: UnwrapValue) => Piped): UnwrapValue; /** * Pipe a value through a series of functions * * @param value Initial value * @returns _Piped_ result */ declare function pipe(value: Initial, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second): UnwrapValue; /** * Pipe a value through a series of functions * * @param value Initial value * @returns _Piped_ result */ declare function pipe(value: Initial, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third): UnwrapValue; /** * Pipe a value through a series of functions * * @param value Initial value * @returns _Piped_ result */ declare function pipe(value: Initial, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth): UnwrapValue; /** * Pipe a value through a series of functions * * @param value Initial value * @returns _Piped_ result */ declare function pipe(value: Initial, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth): UnwrapValue; /** * Pipe a value through a series of functions * * @param value Initial value * @returns _Piped_ result */ declare function pipe(value: Initial, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth): UnwrapValue; /** * Pipe a value through a series of functions * * @param value Initial value * @returns _Piped_ result */ declare function pipe(value: Initial, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh): UnwrapValue; /** * Pipe a value through a series of functions * * @param value Initial value * @returns _Piped_ result */ declare function pipe(value: Initial, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh, eighth: (value: UnwrapValue) => Eighth): UnwrapValue; /** * Pipe a value through a series of functions * * @param value Initial value * @returns _Piped_ result */ declare function pipe(value: Initial, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh, eighth: (value: UnwrapValue) => Eighth, ninth: (value: UnwrapValue) => Ninth): UnwrapValue; /** * Pipe a value through a series of functions * * @param value Initial value * @returns _Piped_ result */ declare function pipe(value: Initial, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh, eighth: (value: UnwrapValue) => Eighth, ninth: (value: UnwrapValue) => Ninth, tenth: (value: UnwrapValue) => Tenth): UnwrapValue; /** * Pipe a value through a series of functions * * @param value Initial value * @returns _Piped_ result */ declare function pipe(value: Value, ...pipes: Array<(value: Value) => Value>): UnwrapValue; /** * Pipe a value through a series of functions * * @param value Initial value * @returns _Piped_ result */ declare function pipe(value: unknown, ...pipes: Array<(value: unknown) => unknown>): unknown; declare namespace pipe { var async: typeof asyncPipe; } //#endregion //#region src/herald.d.ts declare class Events> { #private; constructor(herald: Herald); /** * Subscribe to an event with a callback * * @param event Event name * @param callback Callback function * @returns Unsubscriber function */ subscribe(event: Event, callback: Map[Event]): Unsubscriber; /** * Unsubscribe from an event with a callback _(or all callbacks, if no callback is provided)_ * * @param event Event name * @param callback Callback function * @returns Unsubscriber function */ unsubscribe(event: Event, callback?: Map[Event]): void; } /** * A _Herald_ is an announcer for named events, allowing emission, subscription, and unsubscription of events */ declare class Herald> { #private; /** * Events interface for subscribing to and unsubscribing from events */ readonly events: Events; constructor(names: (keyof Map)[]); /** * Remove all event subscribers */ clear(): void; /** * Emit an event with parameters * * @param event Event name * @param parameters Event parameters */ emit(event: Event, ...parameters: Parameters): void; /** * Subscribe to an event with a callback * * @param event Event name * @param callback Callback function * @returns Unsubscriber function */ subscribe(event: Event, callback: Map[Event]): Unsubscriber; /** * Unsubscribe from an event with a callback _(or all callbacks, if no callback is provided)_ * * @param event Event name * @param callback Callback function */ unsubscribe(event: Event, callback?: Map[Event]): void; } type Unsubscriber = () => void; /** * Create a _Herald_ for announcing named events * * @param names Event names * @returns _Herald_ instance */ declare function herald>(names: (keyof Events)[]): Herald; //#endregion //#region src/internal/string.d.ts /** * Get the string value from any value * * @param value Original value * @returns String representation of the value * * @example * ```typescript * getString(null) // => '' * getString('foo') // => 'foo' * getString(123) // => '123' * getString(true) // => 'true' * getString([1, 2, 3]) // => '1,2,3' * getString({a: 1}) // => '{"a":1}' * getString(() => 123) // => '123' * ``` */ declare function getString(value: unknown): string; declare function ignoreKey(key: string): boolean; declare function interpolate(strings: TemplateStringsArray, values: unknown[]): string; /** * Join an array of values into a string _(while ignoring empty values)_ * * _(`null`, `undefined`, and any values that become whitespace-only strings are considered empty)_ * * @param array Array of values * @param delimiter Delimiter to use between values * @returns Joined string */ declare function join(array: unknown[], delimiter?: string): string; declare function tryDecode(value: string): string; declare function tryEncode(value: boolean | number | string): unknown; /** * Split a string into words _(and other readable parts)_ * * @param value Original string * @returns Array of words found in the string */ declare function words(value: string): string[]; //#endregion //#region src/internal/value/compare.d.ts type Comparator = (first: Value, second: Value) => number; /** * Compare two values _(for sorting purposes)_ * * @param first First value * @param second Second value * @returns `0` if equal; `-1` first comes before second; `1` first comes after second */ declare function compare(first: unknown, second: unknown): number; declare namespace compare { var handlers: { deregister(constructor: Constructor): void; handle(first: unknown, second: unknown, ...parameters: unknown[]): number; register(constructor: Constructor, handler?: string | GenericCallback): void; }; var deregister: typeof deregisterComparator; var register: typeof registerComparator; } /** * Deregister a custom comparison handler for a class * * _Available as `deregisterComparator` and `compare.deregister`_ * * @param constructor Class constructor */ declare function deregisterComparator(constructor: Constructor): void; /** * Register a custom comparison handler for a class * * _Available as `registerComparator` and `compare.register`_ * * @param constructor Class constructor * @param handler Method name or comparison function _(defaults to `compare`)_ */ declare function registerComparator(constructor: Constructor, handler?: string | Comparator): void; //#endregion //#region src/internal/value/equal.d.ts /** * Options for value equality comparison */ type EqualOptions = { /** * When `true`, strings are compared case-insensitively */ ignoreCase?: boolean; /** * Keys _(or key expressions)_ to ignore when comparing objects */ ignoreKeys?: string | RegExp | Array; /** * Should `null` and `undefined` be considered equal? */ relaxedNullish?: boolean; }; /** * An equalizer function for comparing values for equality, with predefined options * * Can be used to compare values, and register or deregister equality comparison handlers for specific classes */ type Equalizer = { /** * Are two strings equal? * * @param first First string * @param second Second string * @param ignoreCase If `true`, comparison will be case-insensitive * @returns `true` if the strings are equal, otherwise `false` */ (first: string, second: string, ignoreCase?: boolean): boolean; /** * Are two values equal? * * @param first First value * @param second Second value * @returns `true` if the values are equal, otherwise `false` */ (first: unknown, second: unknown): boolean; /** * Deregister a equality comparison handler for a specific class * * @param constructor Class constructor */ deregister: (constructor: Constructor) => void; /** * Register a equality comparison function for a specific class * * @param constructor Class constructor * @param handler Comparison function */ register: (constructor: Constructor, handler: (first: Instance, second: Instance) => boolean) => void; }; /** * Deregister a equality comparison handler for a specific class * * _Available as `deregisterEqualizer` and `equal.deregister`_ * * @param constructor Class constructor */ declare function deregisterEqualizer(constructor: Constructor): void; /** * Are two strings equal? * * @param first First string * @param second Second string * @param ignoreCase If `true`, comparison will be case-insensitive * @returns `true` if the strings are equal, otherwise `false` */ declare function equal(first: string, second: string, ignoreCase?: boolean): boolean; /** * Are two values equal? * * @param first First value * @param second Second value * @param options Comparison options * @returns `true` if the values are equal, otherwise `false` */ declare function equal(first: unknown, second: unknown, options?: EqualOptions): boolean; declare namespace equal { var handlers: { deregister(constructor: Constructor): void; handle(first: unknown, second: unknown, ...parameters: unknown[]): boolean; register(constructor: Constructor, handler?: string | GenericCallback): void; }; var deregister: typeof deregisterEqualizer; var initialize: typeof initializeEqualizer; var register: typeof registerEqualizer; } /** * Create an equalizer with predefined options * * _Available as `initializeEqualizer` and `equal.initialize`_ * * @param options Comparison options * @returns Equalizer function */ declare function initializeEqualizer(options?: EqualOptions): Equalizer; /** * Register a equality comparison function for a specific class * * _Available as `registerEqualizer` and `equal.register`_ * * @param constructor Class constructor * @param handler Comparison function */ declare function registerEqualizer(constructor: Constructor, handler: (first: Instance, second: Instance) => boolean): void; //#endregion //#region src/internal/value/get.d.ts /** * Get the value from an object using a known path * * @param data Object to get value from * @param path Path for value * @returns Found value, or `undefined` * * @example * ```typescript * const data = {foo: {bar: {baz: 42}}}; * * getValue(data, 'foo'); // => {bar: {baz: 42}} * getValue(data, 'foo.bar'); // => {baz: 42} * getValue(data, 'foo.bar.baz'); // => 42 * getValue(data, 'foo.nope'); // => undefined * ``` */ declare function getValue>(data: Data, path: Path): NestedValue; /** * Get the value from an object using an unknown path * * @param data Object to get value from * @param path Path for value * @param ignoreCase If `true`, path matching is case-insensitive * @returns Found value, or `undefined` * * @example * ```typescript * const data = {foo: {bar: {baz: 42}}}; * * getValue(data, 'foo'); // => {bar: {baz: 42}} * getValue(data, 'foo.bar'); // => {baz: 42} * getValue(data, 'Foo.Bar.Baz', true); // => 42 * getValue(data, 'foo.nope'); // => undefined * ``` */ declare function getValue(data: Data, path: string, ignoreCase?: boolean): unknown; //#endregion //#region src/internal/value/has.d.ts /** * Check if a property is defined in an object * * @param data Object to check in * @param path Path for property, e.g., `foo.bar.baz` * @returns `true` if the property exists, `false` otherwise * * @example * ```typescript * const data = {foo: {bar: {baz: 42}}}; * * hasValue(data, 'foo'); // => true * hasValue(data, 'foo.bar'); // => true * hasValue(data, 'foo.bar.baz'); // => true * hasValue(data, 'foo.nope'); // => false * ``` */ declare function hasValue>(data: Data, path: Path): boolean; /** * Check if a property is defined in an object * * @param data Object to check in * @param path Path for property, e.g., `foo.bar.baz` * @param ignoreCase If `true`, the path matching is case-insensitive * @returns `true` if the property exists, `false` otherwise * * @example * ```typescript * const data = {foo: {bar: {baz: 42}}}; * * hasValue(data, 'foo'); // => true * hasValue(data, 'foo.bar'); // => true * hasValue(data, 'Foo.Bar.Baz', true); // => true * hasValue(data, 'foo.nope'); // => false * ``` */ declare function hasValue(data: Data, path: string, ignoreCase?: boolean): boolean; declare namespace hasValue { var get: typeof hasValueResult; } /** * Check if a property is defined in an object, and get its value if it is * * _Available as `hasValueResult` and `hasValue.get`_ * * @param data Object to check in * @param path Path for property, e.g., `foo.bar.baz` * @param ignoreCase If `true`, the path matching is case-insensitive * @returns Result object * * @example * ```typescript * const data = {foo: {bar: {baz: 42}}}; * * hasValueResult(data, 'foo'); // => {ok: true, value: {bar: {baz: 42}}} * hasValueResult(data, 'foo.bar'); // => {ok: true, value: {baz: 42}} * hasValueResult(data, 'foo.bar.baz'); // => {ok: true, value: 42} * hasValueResult(data, 'foo.nope'); // => {ok: false, error: 'Expected property to exist in object'} * ``` */ declare function hasValueResult>(data: Data, path: Path): Result>, string>; /** * Check if a property is defined in an object, and get its value if it is * * _Available as `hasValueResult` and `hasValue.get`_ * * @param data Object to check in * @param path Path for property, e.g., `foo.bar.baz` * @param ignoreCase If `true`, the path matching is case-insensitive * @returns Result object * * @example * ```typescript * const data = {foo: {bar: {baz: 42}}}; * * hasValueResult(data, 'foo'); // => {ok: true, value: {bar: {baz: 42}}} * hasValueResult(data, 'foo.bar'); // => {ok: true, value: {baz: 42}} * hasValueResult(data, 'Foo.Bar.Baz', true); // => {ok: true, value: 42} * hasValueResult(data, 'foo.nope'); // => {ok: false, error: 'Expected property to exist in object'} * ``` */ declare function hasValueResult(data: Data, path: string, ignoreCase?: boolean): Result; //#endregion //#region src/internal/value/set.d.ts /** * Update the value in an object using a known path * * @param data Object to set value in * @param path Path for value, e.g., `foo.bar.baz` * @param updater Function to update the current value * @returns Updated object * * @example * ```typescript * const data = {foo: {bar: {baz: 42}}}; * * setValue(data, 'foo.bar.baz', (current) => current + 1); // => {foo: {bar: {baz: 43}}} * ``` */ declare function setValue>(data: Data, path: Path, updater: (current: NestedValue) => NestedValue): Data; /** * Set the value in an object using a known path * * @param data Object to set value in * @param path Path for value, e.g., `foo.bar.baz` * @param value Value to set * @returns Updated object * * @example * ```typescript * const data = {foo: {bar: {baz: 42}}}; * * setValue(data, 'foo.bar.baz', 99); // => {foo: {bar: {baz: 99}}} * ``` */ declare function setValue>(data: Data, path: Path, value: NestedValue): Data; /** * Set the value in an object using an unknown path * * @param data Object to set value in * @param path Path for value, e.g., `foo.bar.baz` * @param value Value to set * @param ignoreCase If `true`, the path matching is case-insensitive * @returns Updated object * * @example * ```typescript * const data = {foo: {bar: {baz: 42}}}; * * setValue(data, 'Foo.Bar.Baz', 99, true); // => {foo: {bar: {baz: 99}}} * ``` */ declare function setValue(data: Data, path: string, value: unknown, ignoreCase?: boolean): Data; //#endregion //#region src/string/case.d.ts /** * Convert a string to camel case _(thisIsCamelCase)_ * * @param value String to convert * @returns Camel-cased string */ declare function camelCase(value: string): string; /** * Capitalize the first letter of a string _(and lowercase the rest)_ * * @param value String to capitalize * @returns Capitalized string */ declare function capitalize(value: string): string; /** * Convert a string to kebab case _(this-is-kebab-case)_ * * @param value String to convert * @returns Kebab-cased string */ declare function kebabCase(value: string): string; /** * Convert a string to lower case * * @param value String to convert * @returns Lower-cased string */ declare function lowerCase(value: string): string; /** * Convert a string to pascal case _(ThisIsPascalCase)_ * * @param value String to convert * @returns Pascal-cased string */ declare function pascalCase(value: string): string; /** * Convert a string to snake case _(this_is_snake_case)_ * * @param value String to convert * @returns Snake-cased string */ declare function snakeCase(value: string): string; /** * Convert a string to title case _(Capitalizing Every Word)_ * * @param value String to convert * @returns Title-cased string */ declare function titleCase(value: string): string; /** * Convert a string to upper case * * @param value String to convert * @returns Upper-cased string */ declare function upperCase(value: string): string; //#endregion //#region src/string/fuzzy.d.ts /** * Fuzzy searcher for an array of items */ declare class Fuzzy { #private; /** * Get items currently being searched through * * @returns Original items */ get items(): Item[]; /** * Set new items to search through * * @param items New items to search through */ set items(items: Item[]); /** * Get strings currently being searched through _(the stringified version of `items`)_ * * @returns Stringified items */ get strings(): string[]; constructor(state: FuzzyState); /** * Search for items matching the given value * * @param value Value to search for * @param options Search options * @returns Search results, with exact matches _(ordered)_ and similar matches _(ordered by relevance)_ */ search(value: string, options?: FuzzyOptions): FuzzyResult; /** * Search for items matching the given value * * @param value Value to search for * @param limit Maximum number of combined items to return in `exact` and `similar` * @returns Search results, with exact matches _(ordered)_ and similar matches _(ordered by relevance)_ */ search(value: string, limit: number): FuzzyResult; } type FuzzyConfiguration = { /** * Handler to stringify items * * - May be a function that takes an item and returns a string, or if items are plain objects, a key of the item to use to grab a string value from * - Defaults to `getString` */ handler?: (item: Item) => string; } & (Item extends PlainObject ? { /** * Key to use to stringify items * * _Prioritized over `handler`_ */ key?: keyof Item; } : {}) & FuzzyOptions; type FuzzyOptions = { /** * Maximum number of combined items to return in `exact` and `similar` _(defaults to all matches)_ */ limit?: number; /** * Maximum score difference between the best and worst similar matches included in results * * - Higher values cast a wider net * - Defaults to `5` */ tolerance?: number; }; /** * Search results from a fuzzy search, with exact and similar matches */ type FuzzyResult = { /** * Ordered items that exactly match the search value */ exact: Item[]; /** * Ordered items that are similar to the search value, ranked by relevance */ similar: Item[]; }; /** * Options for fuzzy searching */ type FuzzySearchOptions = FuzzyOptions; type FuzzyState = { handler: (item: Item) => string; items: Item[]; limit?: number; strings: string[]; tolerance: number; }; /** * Create a fuzzy searcher for an array of items * * @param items Items to search through * @param key Key to use to stringify items * @returns Fuzzy searcher */ declare function fuzzy(items: Item[], key?: ItemKey): Fuzzy; /** * Create a fuzzy searcher for an array of items * * @param items Items to search through * @param handler Handler to stringify items * @returns Fuzzy searcher */ declare function fuzzy(items: Item[], handler?: (item: Item) => string): Fuzzy; /** * Create a fuzzy searcher for an array of items * * @param items Items to search through * @param configuration Fuzzy configuration * @returns Fuzzy searcher */ declare function fuzzy(items: Item[], configuration?: FuzzyConfiguration): Fuzzy; declare namespace fuzzy { var match: typeof fuzzyMatch; } /** * Does the needle match the haystack in a fuzzy way? * * @param haystack Haystack to search through * @param needle Needle to search for * @returns `true` if the needle matches the haystack in a fuzzy way, `false` otherwise */ declare function fuzzyMatch(haystack: string, needle: string): boolean; //#endregion //#region src/string/index.d.ts /** * Dedent a string template, removing common leading whitespace from each line * * @returns Dedented string */ declare function dedent(strings: TemplateStringsArray, ...values: unknown[]): string; /** * Dedent a string, removing common leading whitespace from each line * * @param value String to dedent * @returns Dedented string */ declare function dedent(value: string): string; /** * Get a new UUID string _(version 4)_ for use in _HTML_ * * @param html Use _HTML_-friendly format * @returns UUID string */ declare function getUuid(html: true): string; /** * Get a new UUID string _(version 4)_ * * @returns UUID string */ declare function getUuid(): string; /** * Parse a JSON string into its proper value _(or `undefined` if it fails)_ * * @param value JSON string to parse * @param reviver Reviver function to transform the parsed values * @returns Parsed value or `undefined` if parsing fails */ declare function parse(value: string, reviver?: (this: unknown, key: string, value: unknown) => unknown): unknown; /** * Trim a string _(removing whitespace from both ends)_ * * @param value String to trim * @returns Trimmed string */ declare function trim(value: string): string; /** * Truncate a string to a specified length * * @param value String to truncate * @param length Maximum length of the string after truncation * @param suffix Suffix to append to the truncated string * @returns Truncated string */ declare function truncate(value: string, length: number, suffix?: string): string; //#endregion //#region src/string/match.d.ts /** * Check if a string ends with a specified substring * * @param haystack String to look in * @param needle String to look for * @param ignoreCase Ignore case when matching? _(defaults to `false`)_ * @returns `true` if the string ends with the given substring, otherwise `false` */ declare function endsWith(haystack: string, needle: string, ignoreCase?: boolean): boolean; /** * Check if a string includes a specified substring * * @param haystack String to look in * @param needle String to look for * @param ignoreCase Ignore case when matching? _(defaults to `false`)_ * @returns `true` if the string includes the given substring, otherwise `false` */ declare function includes(haystack: string, needle: string, ignoreCase?: boolean): boolean; /** * Check if a string starts with a specified substring * * @param haystack String to look in * @param needle String to look for * @param ignoreCase Ignore case when matching? _(defaults to `false`)_ * @returns `true` if the string starts with the given substring, otherwise `false` */ declare function startsWith(haystack: string, needle: string, ignoreCase?: boolean): boolean; //#endregion //#region src/string/normalize.d.ts /** * Options for normalizing a string */ type NormalizeOptions = { /** * Remove diacritical marks from the string? _(defaults to `true`)_ */ deburr?: boolean; /** * Convert the string to lower case? _(defaults to `true`)_ */ lowerCase?: boolean; /** * Remove special characters from the string? _(defaults to `false`)_ * * _(Punctuation and symbol characters are considered special)_ */ special?: boolean; /** * Trim the string? _(defaults to `true`)_ */ trim?: boolean; /** * Shorten consecutive whitespace characters to a single space? _(defaults to `true`)_ */ whitespace?: boolean; }; /** * String normalizer function */ type Normalizer = { /** * Normalize a string * * @param value String to normalize * @returns Normalized string */ (value: string): string; }; /** * Deburr a string, removing diacritical marks * * @param value String to deburr * @returns Deburred string */ declare function deburr(value: string): string; /** * Initialize a string normalizer * * _Available as `initializeNormalizer` and `normalize.initialize`_ * * @param options Normalization options * @returns Normalizer function */ declare function initializeNormalizer(options?: NormalizeOptions): Normalizer; /** * Normalize a string * * _By default, the string will be trimmed, deburred, and then lowercased_ * * @param value String to normalize * @param options Normalization options * @returns Normalized string */ declare function normalize(value: string, options?: NormalizeOptions): string; declare namespace normalize { var initialize: typeof initializeNormalizer; } //#endregion //#region src/string/template.d.ts /** * Renderer for a string template with variables * * @param variables Variables to use * @param options Templating options * @returns Templated string */ type Renderer = (variables?: PlainObject, options?: Partial) => string; /** * Options for templating strings */ type TemplateOptions = { /** * Ignore case when searching for variables? */ ignoreCase?: boolean; /** * Custom pattern for outputting variables */ pattern?: RegExp; }; type Templater = { /** * Render a string from a template with variables * * @returns Templated string */ (strings: TemplateStringsArray, ...values: unknown[]): TemplaterRenderer; /** * Render a string from a template with variables * * @param value Template string * @param variables Variables to use * @returns Templated string */ (value: string, variables?: PlainObject): string; }; /** * Render a template string with variables */ type TemplaterRenderer = (variables?: PlainObject) => string; /** * Create a _Templater_ with predefined options * * _Available as `initializeTemplater` and `template.initialize`_ * * @param options Templating options * @returns _Templater_ function */ declare function initializeTemplater(options?: Partial): Templater; /** * Get a _Renderer_ for a string template * * @returns _Renderer_ function */ declare function template(strings: TemplateStringsArray, ...values: unknown[]): Renderer; /** * Render a string from a template with variables * * @param value Template string * @param variables Variables to use * @param options Templating options * @returns Templated string */ declare function template(value: string, variables?: PlainObject, options?: Partial): string; declare namespace template { var initialize: typeof initializeTemplater; } //#endregion //#region src/value/clone.d.ts /** * Clone any kind of value _(shallowly)_ * * @param value Value to clone * @param flat Clone only the value itself, without cloning nested values * @returns Cloned value */ declare function clone(value: Value, flat: true): Value; /** * Clone any kind of value _(deeply, if needed)_ * * @param value Value to clone * @returns Cloned value */ declare function clone(value: Value): Value; declare namespace clone { var handlers: { deregister(constructor: Constructor): void; handle(value: unknown, ...parameters: unknown[]): any; register(constructor: Constructor, handler?: string | GenericCallback): void; }; var deregister: typeof deregisterCloner; var register: typeof registerCloner; } /** * Copy any kind of value * * - Clones the value shallowly, without cloning nested values * - To copy a value deeply, use `clone` instead * * @param value Value to copy * @returns Copied value */ declare function copy(value: Value): Value; /** * Deregister a clone handler for a specific class * * _Available as `deregisterCloner` and `template.deregister`_ * * @param constructor Class constructor */ declare function deregisterCloner(constructor: Constructor): void; /** * Register a clone handler for a specific class * * _Available as `registerCloner` and `template.register`_ * * @param constructor Class constructor * @param handler Method name or clone function _(defaults to method name `clone`)_ */ declare function registerCloner(constructor: Constructor, handler?: string | ((value: Instance) => Instance)): void; //#endregion //#region src/value/collection.d.ts /** * Does the value exist for a key in a _Map_? * * @param map _Map_ to check in * @param value Value to check for * @returns `true` if the value exists, otherwise `false` */ declare function inMap(map: Map, value: Value): boolean; /** * Does the value exist for a key in a _Map_? * * @param map _Map_ to check in * @param value Value to check for * @param key To return the key for the value * @returns The key for the value if it exists, otherwise `undefined` */ declare function inMap(map: Map, value: Value, key: true): Key; /** * Does the value exist in a _Set_? * * @param set _Set_ to check in * @param value Value to check for * @returns `true` if the value exists, otherwise `false` */ declare function inSet(set: Set, value: Value): boolean; //#endregion //#region src/value/diff.d.ts /** * Options for value comparison */ type DiffOptions = { /** * Should `null` and `undefined` be considered equal and ignored in results? */ relaxedNullish?: boolean; }; /** * The result of a comparison beteen two values */ type DiffResult = { /** * The original values that were compared */ original: DiffValue; /** * The type of difference between the two values */ type: DiffType; /** * The differences between the two values * * - Keys are in dot notation * - Values are objects with `from` and `to` properties */ values: Record; }; type DiffType = 'full' | 'none' | 'partial'; /** * The difference between two values */ type DiffValue = { /** * The value from the first value */ from: First; /** * The value from the second value */ to: Second; }; /** * Find the differences between two values * * @param first First value * @param second Second value * @param options Comparison options * @returns Difference result */ declare function diff(first: First, second: Second, options?: DiffOptions): DiffResult; //#endregion //#region src/value/freeze.d.ts /** * A frozen value with readonly properties _(going as deep as possible)_ */ type Frozen = Value extends unknown[] ? Readonly : Value extends PlainObject ? { readonly [Key in keyof Value]: Frozen } : Value extends Map ? ReadonlyMap> : Value extends Set ? ReadonlySet> : Readonly; /** * Freeze an array and its indiced values, but not any nested values * * _Available as `flatFreeze` and `freeze.flat`_ * * @param array Array to freeze * @returns Frozen array */ declare function flatFreeze(array: Item[]): ReadonlyArray; /** * Freeze a map and its values, but not any nested values * * _Available as `flatFreeze` and `freeze.flat`_ * * @param map Map to freeze * @returns Frozen map */ declare function flatFreeze(map: Map): ReadonlyMap; /** * Freeze an object and its properties, but not any nested values * * _Available as `flatFreeze` and `freeze.flat`_ * * @param object Object to freeze * @returns Frozen object */ declare function flatFreeze(object: Value): Readonly; /** * Freeze a set and its values, but not any nested values * * _Available as `flatFreeze` and `freeze.flat`_ * * @param set Set to freeze * @returns Frozen set */ declare function flatFreeze(set: Set): ReadonlySet; /** * Freeze any value, if possible * * _(Only arrays, maps, plain objects, and sets are freezable)_ * * _Available as `flatFreeze` and `freeze.flat`_ * * @param value Value to freeze * @returns Frozen value */ declare function flatFreeze(value: Value): Value; /** * Freeze an array and its values _(but not any nested values)_, preventing modifications * * @param array Array to freeze * @param flat Freeze _only_ the array, not any nested values * @returns Frozen array */ declare function freeze(array: Item[], flat: true): ReadonlyArray; /** * Freeze a map and its values _(but not any nested values)_, preventing modifications * * @param map Map to freeze * @param flat Freeze _only_ the map, not any nested values * @returns Frozen map */ declare function freeze(map: Map, flat: true): ReadonlyMap; /** * Freeze an object and its properties _(but not any nested values)_, preventing modifications * * @param object Object to freeze * @param flat Freeze _only_ the object, not any nested values * @returns Frozen object */ declare function freeze(object: Value, flat: true): Readonly; /** * Freeze a set and its values _(but not any nested values)_, preventing modifications * * @param set Set to freeze * @param flat Freeze _only_ the set, not any nested values * @returns Frozen set */ declare function freeze(set: Set, flat: true): ReadonlySet; /** * Freeze an array and its values recursively, preventing modifications * * _(If you only want to freeze the array itself, but not any nested values, use `freeze(array, true)`, `freeze.flat(array)`, or `flatFreeze(array)` instead)_ * * @param array Array to freeze * @returns Frozen array */ declare function freeze(array: Item[]): Frozen; /** * Freeze a map and its values recursively, preventing modifications * * _(If you only want to freeze the map itself, but not any nested values, use `freeze(map, true)`, `freeze.flat(map)`, or `flatFreeze(map)` instead)_ * * @param map Map to freeze * @returns Frozen map */ declare function freeze(map: Map): Frozen>; /** * Freeze an object and all its properties recursively * * _(If you only want to freeze the object itself, but not any nested values, use `freeze(object, true)`, `freeze.flat(object)`, or `flatFreeze(object)` instead)_ * * @param object Object to freeze * @returns Frozen object */ declare function freeze(object: Value): Frozen; /** * Freeze a set and its values recursively * * _(If you only want to freeze the set itself, but not any nested values, use `freeze(set, true)`, `freeze.flat(set)`, or `flatFreeze(set)` instead)_ * * @param set Set to freeze * @returns Frozen set */ declare function freeze(set: Set): Frozen>; /** * Freeze any value, if possible * * _(Only arrays, maps, plain objects, and sets are freezable)_ * * @param value Value to freeze * @returns Frozen value */ declare function freeze(value: Value): Value; declare namespace freeze { var flat: typeof flatFreeze; var is: typeof isFrozen; } /** * Is the value frozen? * * @param value Value to check * @returns `true` if the value is frozen, otherwise `false` */ declare function isFrozen(value: unknown): boolean; //#endregion //#region src/value/omit.d.ts /** * Create a new object without the specified keys * * @param value Original object * @param keys Keys to omit * @returns Partial object without the specified keys */ declare function omit(value: Value, keys: ValueKey[]): Omit; //#endregion //#region src/value/pick.d.ts /** * Create a new object with only the specified keys * * @param value Original object * @param keys Keys to use * @returns Partial object with only the specified keys */ declare function pick(value: Value, keys: ValueKey[]): Pick; //#endregion //#region src/value/shake.d.ts /** * A shaken object, without any `undefined` values */ type Shaken = { [Key in keyof Value]: Value[Key] extends undefined ? never : Value[Key] }; /** * Shake an object, removing all keys with `undefined` values * * @param value Object to shake * @returns Shaken object */ declare function shake(value: Value): Shaken; //#endregion //#region src/value/smush.d.ts /** * A smushed object, with all nested objects flattened into a single level, using dot notation keys */ type Smushed = Simplify<{ [NestedKey in NestedKeys]: NestedValue> }>; /** * Smush an object into a flat object that uses dot notation keys * * @param value Object to smush * @returns Smushed object with dot notation keys */ declare function smush(value: Value): Smushed; //#endregion //#region src/value/unsmush.d.ts /** * Thanks, type-fest! */ type KeysOfUnion = keyof UnionToIntersection : never>; /** * An unsmushed object, with all dot notation keys turned into nested keys */ type Unsmushed = Simplify]: Value[UnionKey] }, `${string}.${string}`>>; /** * Unsmush a smushed object _(turning dot notation keys into nested keys)_ * * @param value Object to unsmush * @returns Unsmushed object with nested keys */ declare function unsmush(value: Value): Unsmushed; //#endregion //#region src/value/merge.d.ts /** * Options for assigning values */ type AssignOptions = Omit; /** * An assigner function for assigning values from one or more objects to the first one */ type Assigner = { /** * Assign values from one or more objects to the first one * * @param to Value to assign to * @param from Values to assign * @returns Assigned value */ (to: To, from: [...From]): To & UnionToIntersection; }; /** * Options for merging values */ type MergeOptions = { /** * Assign values to the first array or object instead of creating a new one? */ assignValues?: boolean; /** * Key _(or key epxressions)_ for values that should be replaced * * ```ts * merge([{items: [1, 2, 3]}, {items: [99]}]); // => {items: [99]} * ``` */ replaceableObjects?: string | RegExp | Array; /** * Skip nullable values when merging objects? * * ```ts * merge({a: 1, b: 2}, {b: null, c: 3}, {d: null}); // => {a: 1, b: 2, c: 3} * ``` */ skipNullableAny?: boolean; /** * Skip nullable values when merging arrays? * * ```ts * merge([1, 2, 3], [null, null, 99]); // => [1, 2, 99] * ``` */ skipNullableInArrays?: boolean; }; /** * A merger function for merging multiple arrays or objects into a single one */ type Merger = { /** * Merge multiple arrays or objects into a single one * * @param values Values to merge * @returns Merged value */ (values: NestedPartial[]): UnionToIntersection; }; /** * Assign values from one or more objects to the first one * * @param to Value to assign to * @param from Values to assign * @param options Assigning options * @returns Assigned value */ declare function assign(to: To, from: [...From], options?: AssignOptions): To & UnionToIntersection; declare namespace assign { var initialize: typeof initializeAssigner; } /** * Create an assigner with predefined options * * _Available as `initializeAssigner` and `assign.initialize`_ * * @param options Assigning options * @returns Assigner function */ declare function initializeAssigner(options?: AssignOptions): Assigner; /** * Create a merger with predefined options * * _Available as `initializeMerger` and `merge.initialize`_ * * @param options Merging options * @returns Merger function */ declare function initializeMerger(options?: MergeOptions): Merger; /** * Merge multiple arrays or objects into a single one * * @param values Values to merge * @param options Merging options * @returns Merged value */ declare function merge(values: [...Values], options?: MergeOptions): UnionToIntersection; declare namespace merge { var initialize: typeof initializeMerger; } //#endregion //#region src/value/transform.d.ts /** * A callback transform an object's properties */ type TransformCallback = (key: Key, value: Value[Key]) => Value[Key]; /** * A collection of keyed callbacks to transform an object's properties */ type TransformCallbacks = Partial<{ [Key in keyof Value]: (value: Value[Key]) => Value[Key] }>; /** * A transformer function for an object, with predefined callbacks for transforming its properties */ type Transformer = { (value: Value): Value; }; /** * Initialize a transformer for an object with a transformer function * * _Available as `initializeTransformer` and `transform.initialize`_ * * @param transform Transformer function * @returns Transformer */ declare function initializeTransformer(transform: TransformCallback): Transformer; /** * Initialize a transformer for an object with transformer functions * * _Available as `initializeTransformer` and `transform.initialize`_ * * @param transformers Keyed transformer functions * @returns Transformer */ declare function initializeTransformer(transformers: TransformCallbacks): Transformer; /** * Transform and objects properties using a transformer function * * @param value Object to transform * @param transform Transformer function * @returns Transformed object */ declare function transform(value: Value, transform: TransformCallback): Value; /** * Transform and objects properties using a transformer object * * @param value Object to transform * @param transformers Keyed transformer functions * @returns Transformed object */ declare function transform(value: Value, transformers: TransformCallbacks): Value; declare namespace transform { var initialize: typeof initializeTransformer; } //#endregion //#region src/beacon.d.ts /** * A beacon is a lighthouse, holding an observable value that can be subscribed to and emitted from */ declare class Beacon { #private; /** * Is the beacon active? */ get active(): boolean; /** * The observable that can be subscribed to */ get observable(): Observable; /** * The current value */ get value(): Value; constructor(value: Value, options?: BeaconOptions); /** * Destroy the beacon */ destroy(): void; /** * Emit a new value * * @param value Value to set and emit * @param finish Finish the beacon after emitting? _(defaults to `false`)_ */ emit(value: Value, finish?: boolean): void; /** * Emit an error * * @param value Error to emit * @param finish Finish the beacon after emitting? _(defaults to `false`)_ */ error(value: Error, finish?: boolean): void; /** * Finish the beacon */ finish(): void; } /** * Options for Beacon */ type BeaconOptions = { /** * Method for comparing values for equality * * @param first First value * @param second Second value * @returns `true` if the values are equal, otherwise `false` * @default Object.is */ equal?: (first: Value, second: Value) => boolean; }; /** * An observable holds a value and allows observers to subscribe to changes in that value */ declare class Observable { #private; constructor(instance: Beacon, observers: Map, Observer>); /** * Destroy the observable */ destroy(): void; /** * Subscribe to value changes * * @param onNext Callback for when the observable receives a new value * @param onError Callback for when the observable receives an error * @param onComplete Callback for when the observable is completed * @returns Subscription to the observable */ subscribe(onNext: (value: Value) => void, onError?: (error: Error) => void, onComplete?: () => void): Subscription; /** * Subscribe to value changes * * @param observer Observer for changes * @returns Subscription to the observable */ subscribe(observer: Observer): Subscription; } type ObservableState = { beacon: Beacon; closed: boolean; observers: Map, Observer>; }; /** * An observer receives notifications from an observable */ type Observer = { /** * Callback for when the observable is completed */ complete?: () => void; /** * Callback for when the observable receives an error */ error?: (error: Error) => void; /** * Callback for when the observable receives a new value */ next?: (value: Value) => void; }; /** * A subscription represents an active subscription to an observable, holding its state and allowing it to be destroyed or unsubscribed from */ declare class Subscription { #private; constructor(state: ObservableState); /** * Is the subscription closed? */ get closed(): boolean; /** * Destroy the subscription */ destroy(): void; /** * Unsubscribe from its observable */ unsubscribe(): void; } /** * Create a new beacon * * @param value Initial value * @param options Beacon options * @returns Beacon instance */ declare function beacon(value: Value, options?: BeaconOptions): Beacon; //#endregion //#region src/color/models.d.ts type ColorWithAlpha = { /** * Alpha channel _(opacity)_ of the color _(in percentage; 0-100)_ */ alpha: number; }; /** * An _HSL_ color with an alpha channel _(opacity)_ */ type HSLAColor = HSLColor & ColorWithAlpha; /** * An _HSL_ color */ type HSLColor = { /** * Hue of the color _(in degrees; 0-360)_ */ hue: number; /** * Lightness of the color _(in percentage; 0-100)_ */ lightness: number; /** * Saturation of the color _(in percentage; 0-100)_ */ saturation: number; }; /** * An _RGB_ color with an alpha channel _(opacity)_ */ type RGBAColor = RGBColor & ColorWithAlpha; /** * An _RGB_ color */ type RGBColor = { /** * Blue channel of the color _(in hexadecimal; 0-255)_ */ blue: number; /** * Green channel of the color _(in hexadecimal; 0-255)_ */ green: number; /** * Red channel of the color _(in hexadecimal; 0-255)_ */ red: number; }; //#endregion //#region src/color/instance.d.ts /** * A color that is represented in multiple color formats */ declare class Color { #private; /** * A property to identify this as a Color instance, used for type checking * * @internal */ private readonly $color; /** * Get the alpha channel _(opacity)_ of the color * * @returns Current alpha channel value between `0` and `1` */ get alpha(): number; /** * Set the alpha channel _(opacity)_ of the color, as: * * - A number between `0` and `1`, where `0` is fully transparent and `1` is fully opaque * - A number between `0` and `100`, where `0` is fully transparent and `100` is fully opaque * * @param value New alpha channel value */ set alpha(value: number); /** * Get the color as a hex color string * * _Hex color string is returned with no `#`-prefix or alpha channel (opacity)_ * * @returns Current color as a hex color string */ get hex(): string; /** * Set the color from a hex color string * * - `#`-prefix is optional * - Alpha channel _(opacity)_ will be ignored * * @param value New hex color string */ set hex(value: string); /** * Get the color as a hex color with an alpha channel _(opacity)_ * * _Hex color string is returned with alpha channel (opacity), but without `#`-prefix_ * * @returns Current color as a hex color string */ get hexa(): string; /** * Set the color from a hex color string with an alpha channel _(opacity)_ * * - `#`-prefix is optional * - Alpha channel _(opacity)_ will be respected * * @param value New hex color string */ set hexa(value: string); /** * Get the color as an _HSL_ color * * @returns Current color as an _HSL_ color */ get hsl(): HSLColor; /** * Set colors from an _HSL_ color * * @param value New _HSL_ color */ set hsl(value: HSLColor); /** * Get the color as an _HSLA_ color * * @returns Current color as an _HSLA_ color */ get hsla(): HSLAColor; /** * Set colors and alpha from an _HSLA_ color * * @param value New _HSLA_ color */ set hsla(value: HSLAColor); /** * Get the color as an _RGB_ color * * @returns Current color as an _RGB_ color */ get rgb(): RGBColor; /** * Set colors from an _RGB_ color * * @param value New _RGB_ color */ set rgb(value: RGBColor); /** * Get the color as an _RGBA_ color * * @returns Current color as an _RGBA_ color */ get rgba(): RGBAColor; /** * Set colors and alpha from an _RGBA_ color * * @param value New _RGBA_ color */ set rgba(value: RGBAColor); constructor(value: unknown); /** * Get the color as a hex string * * @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_ * @returns Hex color string */ toHexString(alpha?: boolean): string; /** * Get the color as an _HSL(A)_ string * * @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_ * @returns _HSL(A)_ color string */ toHslString(alpha?: boolean): string; /** * Get the color as an _RGB(A)_ string * * @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_ * @returns _RGB(A)_ color string */ toRgbString(alpha?: boolean): string; /** * Get the color as a hex color string * * @returns Hex color string */ toString(): string; } //#endregion //#region src/color/misc/get.d.ts /** * Get a foreground color _(usually text)_ based on a background color's luminance * * - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects * - If the value cannot be parsed, a white foreground color will be returned * * @param value Original value * @returns Foreground color */ declare function getForegroundColor(value: unknown): Color; /** * Get the hex color _(with alpha channel, i.e., opacity)_ from any kind of value * * - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects * - If the value cannot be parsed, a black hex color with an alpha channel of `0` will be returned * * @param value Original value * @returns Hex color string */ declare function getHexaColor(value: unknown): string; /** * Get the hex color from any kind of value * * - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects * - If the value cannot be parsed, a black hex color will be returned * * @param value Original value * @returns Hex color string */ declare function getHexColor(value: unknown): string; /** * Get the _HSLA_ color from any kind of value * * - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects * - If the value cannot be parsed, a black _HSLA_ color with an alpha channel _(opacity)_ of `0` will be returned * * @param value Original value * @returns _HSLA_ color */ declare function getHslaColor(value: unknown): HSLAColor; /** * Get the _HSL_ color from any kind of value * * - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects * - If the value cannot be parsed, a black _HSL_ color will be returned * * @param value Original value * @returns _HSL_ color */ declare function getHslColor(value: unknown): HSLColor; /** * Get the _RGBA_ color from any kind of value * * - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects * - If the value cannot be parsed, a black _RGBA_ color with an alpha channel _(opacity)_ of `0` will be returned * * @param value Original value * @returns _RGBA_ color */ declare function getRgbaColor(value: unknown): RGBAColor; /** * Get the _RGB_ color from any kind of value * * - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects * - If the value cannot be parsed, a black _RGB_ color will be returned * * @param value Original value * @returns _RGB_ color */ declare function getRgbColor(value: unknown): RGBColor; //#endregion //#region src/color/misc/is.d.ts /** * Is the value a _Color_? * * @param value Value to check * @returns `true` if the value is a _Color_, otherwise `false` */ declare function isColor(value: unknown): value is Color; /** * Is the value a hex color? * * @param value Value to check * @param alpha Allow alpha channel _(opacity)_? _(defaults to `true`)_ * @returns `true` if the value is a hex color, otherwise `false` * * @example * ```typescript * isHexColor('ff0000'); // => true * isHexColor('#ff0000'); // => true * * isHexColor('#ff000050'); // => true * isHexColor('#ff000050', false); // => false * ``` */ declare function isHexColor(value: unknown, alpha?: boolean): value is string; /** * Is the value an _HSLA_ color? * * @param value Value to check * @returns `true` if the value is an _HSLA_ color, otherwise `false` */ declare function isHslaColor(value: unknown): value is HSLAColor; /** * Is the value an _HSL_ color? * * @param value Value to check * @returns `true` if the value is an _HSL_ color, otherwise `false` */ declare function isHslColor(value: unknown): value is HSLColor; declare function isHslLike(value: unknown): value is Record; /** * Is the value an _RGBA_ color? * * @param value Value to check * @returns `true` if the value is an _RGBA_ color, otherwise `false` */ declare function isRgbaColor(value: unknown): value is RGBAColor; /** * Is the value an _RGB_ color? * * @param value Value to check * @returns `true` if the value is an _RGB_ color, otherwise `false` */ declare function isRgbColor(value: unknown): value is RGBColor; declare function isRgbLike(value: unknown): value is Record; //#endregion //#region src/color/space/hex.d.ts /** * Get the normalized hex color from a value * * _If the value is unable to be parsed or normalized, a hex color of `000000` will be returned, with the alpha channel _(opacity)_ value `0` included, if specified_ * * @param value Value to normalize * @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_ * @returns Normalized hex color */ declare function getNormalizedHex(value: unknown, alpha?: boolean): string; declare function hexToHsl(value: string): HSLColor; declare function hexToHsla(value: string): HSLAColor; /** * Convert a hex color to an _RGB_ color * * _If the value is unable to be converted, a black RGB color will be returned_ * * @param value Original value * @returns _RGB_ color */ declare function hexToRgb(value: string): RGBColor; /** * Convert a hex color to an _RGBA_ color * * _If the value is unable to be converted, a black RGBA color with an alpha channel (opacity) of `0` will be returned_ * * @param value Original value * @returns _RGBA_ color */ declare function hexToRgba(value: string): RGBAColor; //#endregion //#region src/color/space/hsl.d.ts declare function hslToHex(hsl: HSLAColor | HSLColor, alpha?: boolean): string; /** * Convert an _HSL(A)_ color to an _RGB_ color * * _If the value is unable to be converted, a black RGB color will be returned_ * * _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61_ * * @param hsl HSL(A) color * @returns RGB color */ declare function hslToRgb(hsl: HSLAColor | HSLColor): RGBColor; /** * Convert an _HSL(A)_ color to an _RGBA_ color * * _If the value is unable to be converted, a black RGBA color with an alpha channel (opactiy) of `0` will be returned_ * * _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61_ * * @param hsl HSL(A) color * @returns RGBA color */ declare function hslToRgba(hsl: HSLAColor | HSLColor): RGBAColor; //#endregion //#region src/color/space/rgb.d.ts /** * Convert an _RGB(A)_ color to a hex color _(with optional alpha channel, i.e., opacity)_ * * _If the value is unable to be converted, a black hex color will be returned_ * * @param rgb _RGB(A)_ color * @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_ * @returns Hex color string */ declare function rgbToHex(rgb: RGBAColor | RGBColor, alpha?: boolean): string; /** * Convert an _RGB(A)_ color to an _HSL_ color * * _If the value is unable to be converted, a black HSL color will be returned_ * * _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26_ * * @param rgb _RGB(A)_ color * @returns _HSL_ color */ declare function rgbToHsl(rgb: RGBAColor | RGBColor): HSLColor; /** * Convert an _RGB(A)_ color to an _HSLA_ color * * _If the value is unable to be converted, a black _HSLA_ color with an alpha channel (opacity) of `0` will be returned_ * * _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26_ * * @param rgb _RGB(A)_ color * @returns _HSLA_ color */ declare function rgbToHsla(rgb: RGBAColor | RGBColor): HSLAColor; //#endregion //#region src/color/index.d.ts /** * Get a _Color_ from any kind of value * * - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects * - If the value is unable to be parsed, a black _Color_ will be returned * * @param value Original value * @returns _Color_ instance */ declare function getColor(value: unknown): Color; //#endregion //#region src/internal/is.d.ts /** * Is the value an array or a plain object? * * @param value Value to check * @returns `true` if the value is an array or a plain object, otherwise `false` */ declare function isArrayOrPlainObject(value: unknown): value is ArrayOrPlainObject; /** * Is the value a constructor function? * * @param value Value to check * @returns `true` if the value is a constructor function, otherwise `false` */ declare function isConstructor(value: unknown): value is Constructor; /** * Is the value an instance of the constructor? * * @param constructor Class constructor * @param value Value to check * @returns `true` if the value is an instance of the constructor, otherwise `false` */ declare function isInstanceOf(constructor: Constructor, value: unknown): value is Instance; /** * Is the value a _Key_? * * @param value Value to check * @returns `true` if the value is a _Key_ _(`number` or `string`)_, otherwise `false` */ declare function isKey(value: unknown): value is Key$1; /** * Is the value not an array or a plain object? * * @param value Value to check * @returns `true` if the value is not an array or a plain object, otherwise `false` */ declare function isNonArrayOrPlainObject(value: Value): value is Exclude; /** * Is the value not a constructor function? * * @param value Value to check * @returns `true` if the value is not a constructor function, otherwise `false` */ declare function isNonConstructor(value: Value): value is Exclude; /** * Is the value not an instance of the constructor? * * @param constructor Class constructor * @param value Value to check * @returns `true` if the value is not an instance of the constructor, otherwise `false` */ declare function isNonInstanceOf(constructor: Constructor, value: Value): value is Exclude; /** * Is the value not a _Key_? * * @param value Value to check * @returns `true` if the value is not a _Key_ _(`number` or `string`)_, otherwise `false` */ declare function isNonKey(value: Value): value is Exclude; /** * Is the value not a number? * * @param value Value to check * @returns `true` if the value is not a `number`, otherwise `false` */ declare function isNonNumber(value: Value): value is Exclude; /** * Is the value not a plain object? * * @param value Value to check * @returns `true` if the value is not a plain object, otherwise `false` */ declare function isNonPlainObject(value: Value): value is Exclude; /** * Is the value not a primitive value? * * @param value Value to check * @returns `true` if the value is not a primitive value, otherwise `false` */ declare function isNonPrimitive(value: Value): value is Exclude; /** * Is the value not a typed array? * * @param value Value to check * @returns `true` if the value is not a typed array, otherwise `false` */ declare function isNonTypedArray(value: Value): value is Exclude; /** * Is the value a number? * * @param value Value to check * @returns `true` if the value is a `number`, otherwise `false` */ declare function isNumber(value: unknown): value is number; /** * Is the value a plain object? * * @param value Value to check * @returns `true` if the value is a plain object, otherwise `false` */ declare function isPlainObject(value: unknown): value is PlainObject; /** * Is the value a primitive value? * * @param value Value to check * @returns `true` if the value is a primitive value, otherwise `false` */ declare function isPrimitive(value: unknown): value is Primitive; /** * Is the value a typed array? * * @param value Value to check * @returns `true` if the value is a typed array, otherwise `false` */ declare function isTypedArray(value: unknown): value is TypedArray; //#endregion //#region src/is.d.ts /** * Is the value empty, or only containing `null` or `undefined` values? * * @param value Value to check * @returns `true` if the value is considered empty, otherwise `false` */ declare function isEmpty(value: unknown): boolean; /** * Is the value not empty, or holding non-empty values? * * @param value Value to check * @returns `true` if the value is not considered empty, otherwise `false` */ declare function isNonEmpty(value: unknown): boolean; /** * Is the value not `undefined` or `null`? * * @param value Value to check * @returns `true` if the value is not `undefined` or `null`, otherwise `false` */ declare function isNonNullable(value: Value): value is Exclude; /** * Is the value not `undefined`, `null`, or stringified as an empty _(no whitespace)_ string? * * @param value Value to check * @returns `true` if the value is not `undefined`, `null`, or matches an empty string, otherwise `false` */ declare function isNonNullableOrEmpty(value: Value): value is Exclude; /** * Is the value not `undefined`, `null`, or stringified as a whitespace-only string? * * @param value Value to check * @returns `true` if the value is not `undefined`, `null`, or matches a whitespace-only string, otherwise `false` */ declare function isNonNullableOrWhitespace(value: Value): value is Exclude; /** * Is the value not a number or a number-like string? * * @param value Value to check * @returns `true` if the value is not a number or a number-like string, otherwise `false` */ declare function isNonNumerical(value: Value): value is Exclude; /** * Is the value not an object _(or function)_? * * @param value Value to check * @returns `true` if the value is not an object, otherwise `false` */ declare function isNonObject(value: Value): value is Exclude; /** * Is the value `undefined` or `null`? * * @param value Value to check * @returns `true` if the value is `undefined` or `null`, otherwise `false` */ declare function isNullable(value: unknown): value is undefined | null; /** * Is the value `undefined`, `null`, or stringified as an empty _(no whitespace)_ string? * * @param value Value to check * @returns `true` if the value is nullable or matches an empty string, otherwise `false` */ declare function isNullableOrEmpty(value: unknown): value is undefined | null | ''; /** * Is the value `undefined`, `null`, or stringified as a whitespace-only string? * * @param value Value to check * @returns `true` if the value is nullable or matches a whitespace-only string, otherwise `false` */ declare function isNullableOrWhitespace(value: unknown): value is undefined | null | ''; /** * Is the value a number or a number-like string? * * @param value Value to check * @returns `true` if the value is a number or a number-like string, otherwise `false` */ declare function isNumerical(value: unknown): value is number | `${number}`; /** * Is the value an object _(or function)_? * * @param value Value to check * @returns `true` if the value matches, otherwise `false` */ declare function isObject(value: unknown): value is object; //#endregion //#region src/logger.d.ts type LoggerInstance = { /** * Log any number of values at the "debug" log level */ get debug(): typeof console.debug; /** * Log the value and shows all its properties */ get dir(): typeof console.dir; /** * Is logging to the console enabled? _(defaults to `true`)_ */ get enabled(): boolean; /** * Enable or disable logging to the console */ set enabled(value: boolean); /** * Log any number of values at the "error" log level */ get error(): typeof console.error; /** * Log any number of values at the "info" log level */ get info(): typeof console.info; /** * Log any number of values at the "log" log level */ get log(): typeof console.log; /** * Log data as a table, with optional properties to use as columns */ get table(): typeof console.table; /** * Log any number of values together with a trace from where it was called */ get trace(): typeof console.trace; /** * Log any number of values at the "warn" log level */ get warn(): typeof console.warn; /** * Start a timed logger with a label * * @param label Label for the logger * @returns _TimedLogger_ instance */ time(label: string): TimedLogger; }; /** * A named timer that can be used to log durations to the console */ declare class TimedLogger { #private; /** * Is the timer active? _(i.e. has it been started and not stopped, and is logging enabled?)_ */ get active(): boolean; /** * Log the current duration of the timer _(ignored if logging is disabled)_ */ get log(): () => void; /** * Stop the timer and logs the total duration * * _(Will always log the total duration, even if logging is disabled)_ */ get stop(): () => void; constructor(label: string); } /** * A logger that can be used to log messages to the console * * _(Logging can be enabled or disabled by setting the `enabled` property)_ */ declare const Logger: LoggerInstance; //#endregion //#region src/internal/math/aggregate.d.ts /** * Get the maximum value from a list of items * * @example * ```typescript * max( * [{id: 1, value: 10}, {id: 2, value: 20}], * item => item.value, * ); // => 20 * * max([], item => item.value); // => Number.NaN * ``` * * @param items List of items * @param callback Callback to get an item's value * @returns Maximum value, or `Number.NaN` if no maximum can be found */ declare function max(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): number; /** * Get the maximum value from a list of items * * @example * ```typescript * max( * [{id: 1, value: 10}, {id: 2, value: 20}], * 'value', * ); // => 20 * * max([], 'value'); // => Number.NaN * ``` * * @param items List of items * @param key Key to use for value * @returns Maximum value, or `Number.NaN` if no maximum can be found */ declare function max>(items: Item[], key: ItemKey): number; /** * Get the maximum value from a list of numbers * * @example * ```typescript * max([10, 20]); // => 20 * max([]); // => Number.NaN * ``` * * @param values List of numbers * @returns Maximum value, or `Number.NaN` if no maximum can be found */ declare function max(values: number[]): number; //#endregion //#region src/math.d.ts /** * Get the average value from a list of items * * @param items List of items * @param callback Callback to get an item's value * @returns Average value, or `Number.NaN` if no average can be calculated */ declare function average(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): number; /** * Get the average value from a list of items * * @param items List of items * @param key Key to use for value * @returns Average value, or `Number.NaN` if no average can be calculated */ declare function average(items: Item[], key: keyof NumericalValues): number; /** * Get the average value from a list of numbers * * @param numbers List of numbers * @returns Average value, or `Number.NaN` if no average can be calculated */ declare function average(numbers: number[]): number; /** * Round a number up * * @param value Number to round up * @param decimals Number of decimal places to round to _(defaults to `0`)_ * @returns Rounded number, or `Number.NaN` if the value if unable to be rounded */ declare function ceil(value: number, decimals?: number): number; /** * Count the number of items in an array that match a specific value * * @param array Array to count for * @param callback Callback to get an item's value * @param value Value to match and count * @returns Number of items that match the condition, or `Number.NaN` if no count can be calculated */ declare function count(array: Item[], callback: (item: Item, index: number, array: Item[]) => unknown, value: unknown): number; /** * Count the number of items in an array that have a specific value * * @param array Array to count for * @param key Key to use for value * @param value Value to match and count * @returns Number of items with the specified key value, or `Number.NaN` if no count can be calculated */ declare function count(array: Item[], key: ItemKey, value: Item[ItemKey]): number; /** * Count the number of items in an array * * @param values Array to count for * @returns Number of items, or `Number.NaN` if no count can be calculated */ declare function count(values: unknown[]): number; /** * Round a number down * * @param value Number to round down * @param decimals Number of decimal places to round to _(defaults to `0`)_ * @returns Rounded number, or `Number.NaN` if the value if unable to be rounded */ declare function floor(value: number, decimals?: number): number; /** * Get the median value from a list of items * * @param array List of items * @param callback Callback to get an item's value * @returns Median value, or `Number.NaN` if no median can be calculated */ declare function median(array: Item[], callback: (item: Item, index: number, array: Item[]) => number): number; /** * Get the median value from a list of items * * @param array List of items * @param key Key to use for value * @returns Median value, or `Number.NaN` if no median can be calculated */ declare function median(array: Item[], key: keyof NumericalValues): number; /** * Get the median value from a list of numbers * * @param array List of numbers * @returns Median value, or `Number.NaN` if no median can be calculated */ declare function median(array: number[]): number; /** * Get the minimum value from a list of items * * @param items List of items * @param callback Callback to get an item's value * @returns Minimum value, or `Number.NaN` if no minimum can be found */ declare function min(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): number; /** * Get the minimum value from a list of items * * @param items List of items * @param key Key to use for value * @returns Minimum value, or `Number.NaN` if no minimum can be found */ declare function min(items: Item[], key: keyof NumericalValues): number; /** * Get the minimum value from a list of numbers * * @param values List of numbers * @returns Minimum value, or `Number.NaN` if no minimum can be found */ declare function min(values: number[]): number; /** * Round a number * * @param value Number to round * @param decimals Number of decimal places to round to _(defaults to `0`)_ * @returns Rounded number, or `Number.NaN` if the value if unable to be rounded */ declare function round(value: number, decimals?: number): number; /** * Get the sum of a list of items * * @param items List of items * @param callback Callback to get an item's value * @returns Sum of the values, or `Number.NaN` if no sum can be calculated */ declare function sum(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): number; /** * Get the sum of a list of items * * @param items List of items * @param key Key to use for value * @returns Sum of the values, or `Number.NaN` if no sum can be calculated */ declare function sum(items: Item[], key: keyof NumericalValues): number; /** * Get the sum of a list of numbers * * @param values List of numbers * @returns Sum of the numbers, or `Number.NaN` if no sum can be calculated */ declare function sum(values: number[]): number; //#endregion //#region src/internal/number.d.ts /** * Is the number between a minimum and maximum value? * * @param value Value to check * @param minimum Minimum value * @param maximum Maximum value * @returns `true` if the value is between the minimum and maximum, otherwise `false` */ declare function between(value: number, minimum: number, maximum: number): boolean; /** * Clamp a number between a minimum and maximum value * * @param value Value to clamp * @param minimum Minimum value * @param maximum Maximum value * @param loop If `true`, the value will loop around when smaller than the minimum or larger than the maximum _(defaults to `false`)_ * @returns Clamped value * * @example * ```typescript * clamp(10, 0, 5); // => 5 * clamp(10, 0, 5, true); // => 0 * ``` */ declare function clamp(value: number, minimum: number, maximum: number, loop?: boolean): number; /** * Get the number value from an unknown value * * _(Based on Lodash)_ * * @param value Original value * @returns Original value as a number, or `Number.NaN` if the value is unable to be parsed */ declare function getNumber(value: unknown): number; //#endregion //#region src/promise/models.d.ts /** * A _Promise_ that can be canceled */ declare class CancelablePromise extends Promise { #private; constructor(executor: (resolve: (value: Value) => void, reject: (reason: unknown) => void) => void); /** * Cancel the _Promise_, rejecting it with an optional reason * * @param reason Optional reason for canceling the _Promise_ */ cancel(reason?: unknown): void; } /** * A _Promise_ that was fulfilled */ type FulfilledPromise = { /** * Status of the _Promise_ */ status: typeof PROMISE_TYPE_FULFILLED; /** * Value of the _Promise_ */ value: Awaited; }; type PromiseData = { last: number; result: unknown[]; }; type PromiseHandlers = { resolve: (value: unknown[]) => void; reject: (reason: unknown) => void; }; /** * Options for a _Promise_-handling function */ type PromiseOptions = { /** * AbortSignal for aborting the _Promise_; when aborted, the _Promise_ will reject with the reason of the signal */ signal?: AbortSignal; /** * How long to wait for _(in milliseconds; defaults to `0`)_ */ time?: number; }; type PromiseParameters = { abort: () => void; complete: boolean; data: PromiseData; handlers: PromiseHandlers; index: number; signal?: AbortSignal; value?: unknown; }; /** * _Promise_ handling strategy * * - `complete`: wait for all _Promises_ to settle, then return the results, as an array of fulfilled and/or rejected results * - `first`: rejects on the first rejected _Promise_, and returns an array of values */ type PromiseStrategy = 'complete' | 'first'; /** * An error thrown when a promise times out */ declare class PromiseTimeoutError extends Error { constructor(); } type PromisesItems = { [ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback ? ReturnType extends Promise ? Promise : never : Items[ItemsKey] extends Promise ? Promise : Promise }; /** * Options for handling multiple _Promises_ */ type PromisesOptions = { /** * AbortSignal for aborting the _Promises_; when aborted, the _Promises_ will reject with the reason of the signal */ signal?: AbortSignal; /** * Strategy for handling the _Promises_; defaults to `complete` */ strategy?: PromiseStrategy; }; type PromisesResult = { [ItemsKey in keyof Items]: Items[ItemsKey] extends Promise ? Result> : never }; type PromisesUnwrapped = { [ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback ? ReturnType extends Promise ? Awaited : never : Items[ItemsKey] extends Promise ? Awaited : never }; type PromisesValue = FulfilledPromise | RejectedPromise; type PromisesValues = { [ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback ? ReturnType extends Promise ? PromisesValue> : never : Items[ItemsKey] extends Promise ? PromisesValue> : never }; /** * A _Promise_ that was rejected */ type RejectedPromise = { /** * Status of the _Promise_ */ status: typeof PROMISE_TYPE_REJECTED; /** * Reason for the rejection */ reason: unknown; }; declare const PROMISE_ABORT_EVENT = "abort"; declare const PROMISE_ABORT_OPTIONS: { once: boolean; }; declare const PROMISE_ERROR_NAME = "PromiseTimeoutError"; declare const PROMISE_MESSAGE_EXPECTATION_ATTEMPT = "Attempt expected a function or a promise"; declare const PROMISE_MESSAGE_EXPECTATION_RESULT = "toResult expected a Promise"; declare const PROMISE_MESSAGE_EXPECTATION_TIMED = "Timed function expected a Promise"; declare const PROMISE_MESSAGE_TIMEOUT = "Promise timed out"; declare const PROMISE_STRATEGY_ALL: Set; declare const PROMISE_STRATEGY_DEFAULT: PromiseStrategy; declare const PROMISE_TYPE_FULFILLED = "fulfilled"; declare const PROMISE_TYPE_REJECTED = "rejected"; //#endregion //#region src/promise/delay.d.ts /** * Create a delayed promise that resolves after a certain amount of time, or rejects if aborted * * @param options Options for the delay * @returns Delayed promise */ declare function delay(options?: PromiseOptions): Promise; /** * Create a delayed promise that resolves after a certain amount of time * * @param time How long to wait for _(in milliseconds; defaults to `0`)_ * @returns Delayed promise */ declare function delay(time?: number): Promise; //#endregion //#region src/promise/index.d.ts /** * Wrap a _Promise_ with safety handlers, with optional abort capabilities and timeout * * @param promise _Promise_ to wrap * @param options Options for the _Promise_ * @returns Wrapped _Promise_ */ declare function attemptPromise(promise: Promise, options?: PromiseOptions | AbortSignal | number): Promise; /** * Wrap a _Promise_-returning callback with safety handlers, with optional abort capabilities and timeout * * @param callback Callback to wrap * @param options Options for the _Promise_ * @returns _Promise_-wrapped callback */ declare function attemptPromise(callback: () => Promise, options?: PromiseOptions | AbortSignal | number): Promise; /** * Wrap a callback with a _Promise_ and safety handlers, with optional abort capabilities and timeout * * @param callback Callback to wrap * @param options Options for the _Promise_ * @returns _Promise_-wrapped callback */ declare function attemptPromise(callback: () => Value, options?: PromiseOptions | AbortSignal | number): Promise; /** * Handle a list of _Promises_, returning their results in an ordered array * * Depending on the strategy, the function will either reject on the first error encountered or return an array of rejected and resolved results * * @param items List of _Promises_ * @param options Options for handling the _Promises_ * @returns List of results */ declare function promises(items: [...Items], options?: Options): Promise : PromisesValues>>; /** * Handle a list of _Promises_, returning their results in an ordered array * * Depending on the strategy, the function will either reject on the first error encountered or return an array of rejected and resolved results * * @param items List of _Promises_ * @param options Options for handling the _Promises_ * @returns List of results */ declare function promises(items: Promise[], options?: Options): Promise[]>; /** * Handle a list of _Promises_, returning their results in an ordered array * * If any _Promise_ in the list is rejected, the whole function will reject * * @param items List of _Promises_ * @param strategy Strategy for handling the _Promises_; rejects on the first error encountered * @returns List of results */ declare function promises(items: [...Items], strategy: 'first'): Promise>; /** * Handle a list of _Promises_, returning their results in an ordered array * * If any _Promise_ in the list is rejected, the whole function will reject * * @param items List of _Promises_ * @param strategy Strategy for handling the _Promises_; rejects on the first error encountered * @returns List of results */ declare function promises(items: Promise[], strategy: 'first'): Promise; /** * Handle a list of _Promises_, returning their results in an ordered array of rejected and resolved results * * @param items List of _Promises_ * @param signal AbortSignal for aborting the operation _(when aborted, the _Promise_ will reject with the reason of the signal)_ * @returns List of results */ declare function promises(items: [...Items], signal?: AbortSignal): Promise>>; /** * Handle a list of _Promises_, returning their results in an ordered array of rejected and resolved results * * @param items List of _Promises_ * @param signal AbortSignal for aborting the operation _(when aborted, the _Promise_ will reject with the reason of the signal)_ * @returns List of results */ declare function promises(items: Array | (() => Promise)>, signal?: AbortSignal): Promise[]>; declare namespace promises { var result: typeof resultPromises; } /** * Handle a list of _Promises_, returning their results in an ordered array of results _({@link Result})_ * * Depending on the strategy, the function will either reject on the first error encountered or return an array of rejected and resolved results * * _Available as `resultPromises` and `promises.result`_ * * @param items List of _Promises_ * @param signal AbortSignal for aborting the operation _(when aborted, the _Promise_ will reject with the reason of the signal)_ * @returns List of results */ declare function resultPromises(items: [...Items], signal?: AbortSignal): Promise>>; /** * Handle a list of _Promises_, returning their results in an ordered array of results _({@link Result})_ * * Depending on the strategy, the function will either reject on the first error encountered or return an array of rejected and resolved results * * _Available as `resultPromises` and `promises.result`_ * * @param items List of _Promises_ * @param signal AbortSignal for aborting the operation _(when aborted, the _Promise_ will reject with the reason of the signal)_ * @returns List of results */ declare function resultPromises(items: Promise[], signal?: AbortSignal): Promise>[]>; //#endregion //#region src/internal/result.d.ts /** * Is the _Result_ an extended error? * * @param result _Result_ to check * @returns `true` if the _Result_ is an extended error, `false` otherwise */ declare function isError(result: ExtendedErr | Result, extended: true): result is ExtendedErr; /** * Is the _Result_ an error? * * @param result _Result_ to check * @returns `true` if the _Result_ is an error, `false` otherwise */ declare function isError(result: Result): result is Err; /** * Is the value an error? * * @param value Value to check * @returns `true` if the value is an error, `false` otherwise */ declare function isError(value: unknown): value is Err | ExtendedErr; /** * Is the _Result_ ok? * * @param value _Result_ to check * @returns `true` if the _Result_ is ok, `false` otherwise */ declare function isOk(value: Result): value is Ok; /** * Is the value ok? * * @param value Value to check * @returns `true` if the value is ok, `false` otherwise */ declare function isOk(value: unknown): value is Ok; /** * Is the value a _Result_? * * @param value Value to check * @returns `true` if the value is a _Result_, `false` otherwise */ declare function isResult(value: unknown): value is ExtendedErr | Result; //#endregion //#region src/result/misc.d.ts /** * Creates an extended error result * * @param value Error value * @param original Original error * @returns Error result */ declare function error(value: E, original: Error): ExtendedErr; /** * Creates an error result * * @param value Error value * @returns Error result */ declare function error(value: E): Err; declare function getError(value: E, original?: Error): Err | ExtendedErr; /** * Creates an ok result * * @param value Value * @returns Ok result */ declare function ok(value: Value): Ok; /** * Converts a result to a _Promise_ * * Resolves if ok, rejects for error * * @param callback Callback to get the result * @returns Promised result */ declare function toPromise(callback: () => AnyResult): Promise; /** * Converts a result to a _Promise_ * * Resolves if ok, rejects for error * * @param result _Result_ to convert * @returns Promised result */ declare function toPromise(result: AnyResult): Promise; /** * Gets the value of an ok result _(or a default value)_ * * @param value _Result_ to unwrap * @param defaultValue Default value * @returns Value of the _Result_ _(or the default value)_ */ declare function unwrap(value: Result, defaultValue: Value): Value; /** * Gets the value of an ok result _(or a default value)_ * * @param value _Result_ to unwrap * @param defaultValue Default value * @returns Value of the _Result_ _(or the default value)_ */ declare function unwrap(value: unknown, defaultValue: unknown): unknown; //#endregion //#region src/promise/helpers.d.ts /** * Is the value a fulfilled _Promise_ result? * * @param value Value to check * @returns `true` if the value is a fulfilled _Promise_ result, `false` otherwise */ declare function isFulfilled(value: unknown): value is FulfilledPromise; /** * Is the value a rejected _Promise_ result? * * @param value Value to check * @returns `true` if the value is a rejected _Promise_ result, `false` otherwise */ declare function isRejected(value: unknown): value is RejectedPromise; //#endregion //#region src/promise/misc.d.ts /** * Create a cancelable _Promise_ * * @param executor Executor function for the _Promise_ * @returns Cancelable _Promise_ */ declare function cancelable(executor: (resolve: (value: Value) => void, reject: (reason: unknown) => void) => void): CancelablePromise; declare function handleResult(status: string, parameters: PromiseParameters): void; declare function settlePromise(aborter: () => void, settler: (value: any) => void, value: unknown, signal?: AbortSignal): void; /** * Converts a _Promise_ to a promised result * * @param callback _Promise_ callback * @returns Promised result */ declare function toResult(callback: () => Promise): Promise>; /** * Converts a _Promise_ to a promised result * * @param promise _Promise_ to convert * @returns Promised result */ declare function toResult(promise: Promise): Promise>; //#endregion //#region src/promise/timed.d.ts declare function getTimedPromise(promise: Promise, time: number, signal?: AbortSignal): Promise; /** * Create a _Promise_ that should be settled within a certain amount of time * * @param promise _Promise_ to settle * @param options Timed options * @returns Timed _Promise_ */ declare function timed(promise: Promise, options: RequiredKeys): Promise; /** * Create a _Promise_ that should be settled within a certain amount of time * * @param promise _Promise_ to settle * @param time How long to wait for _(in milliseconds; defaults to `0`)_ * @returns Timed _Promise_ */ declare function timed(promise: Promise, time: number): Promise; //#endregion //#region src/query.d.ts /** * Convert a query string to a plain _(nested)_ object * * @param query Query string to convert * @returns Plain object representation of the query string */ declare function fromQuery(query: string): PlainObject; /** * Convert a plain _(nested)_ object to a query string * * @param parameters Plain object to convert * @returns Query string representation of the object */ declare function toQuery(parameters: PlainObject): string; //#endregion //#region src/queue.d.ts /** * A queue that can be used to manage (a)synchronous tasks with a specific key */ declare class KeyedQueue, CallbackResult> { #private; /** * Get keys of all active queues */ get active(): string[]; /** * Does the queue automatically start when the first item is added? */ get autostart(): boolean; /** * Maximum number of runners to process the queue concurrently */ get concurrency(): number; /** * Get keys of all empty queues */ get empty(): string[]; /** * Get keys of all full queues */ get full(): string[]; /** * Number of items in all queues */ get items(): Record; /** * Keys of all queues */ get keys(): string[]; /** * Maximum number of items allowed in the queue */ get maximum(): number; /** * Are all queues paused? */ get paused(): string[]; /** * Number of queues */ get queues(): number; constructor(callback: GenericAsyncCallback, options: Required); /** * Queue an item for a specific key * * @param key Key to queue the item for * @param parameters Parameters to use when item runs * @param signal Optional signal to abort the item * @returns Queued item */ add(key: string, parameters: Tail, signal?: AbortSignal): Queued; /** * Clear all items for a specific key _(or all items for all keys, if no key is provided)_ * * @param key Optional key to clear the queue for */ clear(key?: string): void; /** * Get the queue for a specific key * * @param key Key to get the queue for * @returns Queue for the key, or `undefined` if it doesn't exist */ get(key: string): Queue, CallbackResult> | undefined; /** * Pause the queue for a specific key _(or all queues, if no key is provided)_ * * @param key Optional key to pause the queue for */ pause(key?: string): void; /** * Remove a specific item for a specific key * * @param key Key to remove the item for * @param id ID of the item to remove */ remove(key: string, id: number): void; /** * Remove a queue and its items for a specific key * * _(To remove all items for a specific key, use `clear()` instead)_ * * @param key Key to remove the queue for */ remove(key: string): void; /** * Remove all queues and their items */ remove(): void; /** * Resume the queue for a specific key _(or all queues, if no key is provided)_ * * @param key Optional key to resume the queue for */ resume(key?: string): void; } /** * A queue that can be used to manage (a)synchronous tasks */ declare class Queue, CallbackResult> { #private; /** * Is the queue active? */ get active(): boolean; /** * Does the queue automatically start when the first item is added? */ get autostart(): boolean; /** * Maximum number of runners to process the queue concurrently */ get concurrency(): number; /** * Is the queue empty? */ get empty(): boolean; /** * Is the queue full? */ get full(): boolean; /** * Maximum number of items allowed in the queue */ get maximum(): number; /** * Is the queue paused? */ get paused(): boolean; /** * Number of items in the queue */ get size(): number; constructor(callback: GenericAsyncCallback, options: Required, key?: string); /** * Add an item to the queue * * @param parameters Parameters to use when item runs * @param signal Optional signal to abort the item * @returns Queued item */ add(parameters: CallbackParameters, signal?: AbortSignal): Queued; /** * Remove and reject all items in the queue */ clear(): void; /** * Pause the queue * * - Currently running items will not be stopped * - New added items will not run until the queue is resumed */ pause(): void; /** * Remove and reject a specific item in the queue * * @param id ID of queued item */ remove(id: number): void; /** * Resume the queue */ resume(): void; } /** * An error thrown by the Queue when an operation fails */ declare class QueueError extends Error { constructor(message: string); } type QueueOptions = { /** * Automatically start processing the queue when the first item is added _(defaults to `true`)_ */ autostart?: boolean; /** * Number of runners to process the queue concurrently _(defaults to `1`)_ */ concurrency?: number; /** * Maximum number of items allowed in the queue _(defaults to `0`, which means no limit)_ */ maximum?: number; }; /** * A queued item */ type Queued = { /** * ID of the queued item _(can be used to remove it from the queue)_ */ readonly id: number; /** * Queued promise */ readonly promise: Promise>; }; type QueuedResult = { /** * Has the queue finished processing all items? */ finished: boolean; /** * Result for the queued promise */ value: Value; }; type Tail = Values extends [infer _, ...infer Rest] ? Rest : never; declare function keyedQueue(callback: Callback, options?: QueueOptions): KeyedQueue, Awaited>>; /** * Create a queue for an asynchronous callback function * * @param callback Callback function for queued items * @param options Queue options * @returns Queue instance */ declare function queue Promise>(callback: Callback, options?: QueueOptions): Queue, Awaited>>; /** * Create a queue for a synchronous callback function * * @param callback Callback function for queued items * @param options Queue options * @returns Queue instance */ declare function queue(callback: Callback, options?: QueueOptions): Queue, ReturnType>; declare namespace queue { var keyed: typeof keyedQueue; } //#endregion //#region src/internal/random.d.ts /** * Get a random floating-point number * * @param minimum Minimum value * @param maximum Maximum value * @returns Random floating-point number */ declare function getRandomFloatingNumber(minimum?: number, maximum?: number): number; /** * Get a random integer * * @param minimum Minimum value * @param maximum Maximum value * @returns Random integer */ declare function getRandomInteger(minimum?: number, maximum?: number): number; //#endregion //#region src/random.d.ts /** * Get a random boolean * * @returns Random boolean */ declare function getRandomBoolean(): boolean; /** * Get a random string of characters with a specified length * * @param length Length of random string * @param selection String of characters to select from _(defaults to lowercase English alphabet)_ * @returns Random string of characters */ declare function getRandomCharacters(length: number, selection?: string): string; /** * Get a random hexadecimal color * * @param prefix Prefix the color with `#`? _(defaults to `false`)_ * @returns Random hexadecimal color string in the format `(#)RRGGBB` */ declare function getRandomColor(prefix?: boolean): string; /** * Get a random hexadecimal character * * @returns Random hexadecimal character from `0-9` and `A-F` */ declare function getRandomHex(): string; /** * Get a random item from an array * * @param array Array to get a random item from * @returns Random item from the array, or `undefined` if unable to retrieve one */ declare function getRandomItem(array: Value[]): Value | undefined; /** * Get an amount of random items from an array * * @param array Array to get random items from * @param amount Amount of items to return * @returns Array of random items */ declare function getRandomItems(array: Value[], amount: number): Value[]; /** * Get a shuffled array * * @param array Array to get random items from * @returns Shuffled version of the original array */ declare function getRandomItems(array: Value[]): Value[]; //#endregion //#region src/result/index.d.ts /** * Executes a _Promise_, catching any errors, and returns a result * * _Available as `asyncAttempt` and `attempt.async`_ * * @param promise _Promise_ to execute * @param error Error value * @returns Callback result */ declare function asyncAttempt(promise: Promise, error: E): Promise, E>>; /** * Executes a callback asynchronously, catching any errors, and returns a result * * _Available as `asyncAttempt` and `attempt.async`_ * * @param callback Callback to execute * @param error Error value * @returns Callback result */ declare function asyncAttempt(callback: () => Promise, error: E): Promise, E>>; /** * Executes a _Promise_, catching any errors, and returns a result * * _Available as `asyncAttempt` and `attempt.async`_ * * @param promise _Promise_ to execute * @returns Callback result */ declare function asyncAttempt(promise: Promise): Promise>>; /** * Executes a callback asynchronously, catching any errors, and returns a result * * _Available as `asyncAttempt` and `attempt.async`_ * * @param callback Callback to execute * @returns Callback result */ declare function asyncAttempt(callback: () => Promise): Promise>>; /** * Executes a callback, catching any errors, and returns a result * * @param callback Callback to execute * @param error Error value * @returns Callback result */ declare function attempt(callback: () => Value, error: E): ExtendedResult; /** * Executes a callback, catching any errors, and returns a result * * @param callback Callback to execute * @returns Callback result */ declare function attempt(callback: () => Value): Result; declare namespace attempt { var async: typeof asyncAttempt; } //#endregion //#region src/result/match.d.ts /** * Handles a _Result_ with match callbacks * * _Available as `asyncMatchResult` and `matchResult.async`_ * * @param result _Result_ to handle * @param handler Match callbacks * @returns Matched value-_Promise_ */ declare function asyncMatchResult(result: AnyResult | Promise> | (() => Promise>), handler: ResultMatch): Promise; /** * Handles a _Result_ with match callbacks * * _Available as `asyncMatchResult` and `matchResult.async`_ * * @param result _Result_ to handle * @param ok Ok callback * @param error Error callback * @returns Matched value-_Promise_ */ declare function asyncMatchResult(result: AnyResult | Promise> | (() => Promise>), ok: ResultMatch['ok'], error: ResultMatch['error']): Promise; /** * Handles a _Result_ with match callbacks * * @param result _Result_ to handle * @param handler Match callbacks * @returns Matched value */ declare function matchResult(result: AnyResult | (() => AnyResult), handler: ResultMatch): Returned; /** * Handles a _Result_ with match callbacks * * @param result _Result_ to handle * @param ok Ok callback * @param error Error callback * @returns Matched value */ declare function matchResult(result: AnyResult | (() => AnyResult), ok: ResultMatch['ok'], error: ResultMatch['error']): Returned; declare namespace matchResult { var async: typeof asyncMatchResult; } //#endregion //#region src/result/work/flow.d.ts /** * A synchronous _Flow_, a function that attempts to pipe values through a series of functions */ type AttemptFlow = (...args: Parameters) => Result>; /** * An asynchronous _Flow_, a function that attempts to pipe values through a series of functions */ type AttemptFlowPromise = (...args: Parameters) => Promise>>; /** * Create an asynchronous _Flow_, a function that attempts to pipe a value through a series of functions * * _Available as `attemptAsyncFlow` and `attemptFlow.async`_ * * @returns _Flow_ function */ declare function attemptAsyncFlow(fn: Fn): AttemptFlowPromise>; /** * Create an asynchronous _Flow_, a function that pipes values through a series of functions * * _Available as `attemptAsyncFlow` and `attemptFlow.async`_ * * @returns _Flow_ function */ declare function attemptAsyncFlow(first: First, second: (value: Awaited>>) => Second): AttemptFlowPromise; /** * Create an asynchronous _Flow_, a function that pipes values through a series of functions * * _Available as `attemptAsyncFlow` and `attemptFlow.async`_ * * @returns _Flow_ function */ declare function attemptAsyncFlow(first: First, second: (value: Awaited>>) => Second, third: (value: Awaited>) => Third): AttemptFlowPromise; /** * Create an asynchronous _Flow_, a function that pipes values through a series of functions * * _Available as `attemptAsyncFlow` and `attemptFlow.async`_ * * @returns _Flow_ function */ declare function attemptAsyncFlow(first: First, second: (value: Awaited>>) => Second, third: (value: Awaited>) => Third, fourth: (value: Awaited>) => Fourth): AttemptFlowPromise; /** * Create an asynchronous _Flow_, a function that pipes values through a series of functions * * _Available as `attemptAsyncFlow` and `attemptFlow.async`_ * * @returns _Flow_ function */ declare function attemptAsyncFlow(first: First, second: (value: Awaited>>) => Second, third: (value: Awaited>) => Third, fourth: (value: Awaited>) => Fourth, fifth: (value: Awaited>) => Fifth): AttemptFlowPromise; /** * Create an asynchronous _Flow_, a function that pipes values through a series of functions * * _Available as `attemptAsyncFlow` and `attemptFlow.async`_ * * @returns _Flow_ function */ declare function attemptAsyncFlow(first: First, second: (value: Awaited>>) => Second, third: (value: Awaited>) => Third, fourth: (value: Awaited>) => Fourth, fifth: (value: Awaited>) => Fifth, sixth: (value: Awaited>) => Sixth): AttemptFlowPromise; /** * Create an asynchronous _Flow_, a function that pipes values through a series of functions * * _Available as `attemptAsyncFlow` and `attemptFlow.async`_ * * @returns _Flow_ function */ declare function attemptAsyncFlow(first: First, second: (value: Awaited>>) => Second, third: (value: Awaited>) => Third, fourth: (value: Awaited>) => Fourth, fifth: (value: Awaited>) => Fifth, sixth: (value: Awaited>) => Sixth, seventh: (value: Awaited>) => Seventh): AttemptFlowPromise; /** * Create an asynchronous _Flow_, a function that pipes values through a series of functions * * _Available as `attemptAsyncFlow` and `attemptFlow.async`_ * * @returns _Flow_ function */ declare function attemptAsyncFlow(first: First, second: (value: Awaited>>) => Second, third: (value: Awaited>) => Third, fourth: (value: Awaited>) => Fourth, fifth: (value: Awaited>) => Fifth, sixth: (value: Awaited>) => Sixth, seventh: (value: Awaited>) => Seventh, eighth: (value: Awaited>) => Eighth): AttemptFlowPromise; /** * Create an asynchronous _Flow_, a function that pipes values through a series of functions * * _Available as `attemptAsyncFlow` and `attemptFlow.async`_ * * @returns _Flow_ function */ declare function attemptAsyncFlow(first: First, second: (value: Awaited>>) => Second, third: (value: Awaited>) => Third, fourth: (value: Awaited>) => Fourth, fifth: (value: Awaited>) => Fifth, sixth: (value: Awaited>) => Sixth, seventh: (value: Awaited>) => Seventh, eighth: (value: Awaited>) => Eighth, ninth: (value: Awaited>) => Ninth): AttemptFlowPromise; /** * Create an asynchronous _Flow_, a function that pipes values through a series of functions * * _Available as `attemptAsyncFlow` and `attemptFlow.async`_ * * @returns _Flow_ function */ declare function attemptAsyncFlow(first: First, second: (value: Awaited>>) => Second, third: (value: Awaited>) => Third, fourth: (value: Awaited>) => Fourth, fifth: (value: Awaited>) => Fifth, sixth: (value: Awaited>) => Sixth, seventh: (value: Awaited>) => Seventh, eighth: (value: Awaited>) => Eighth, ninth: (value: Awaited>) => Ninth, tenth: (value: Awaited>) => Tenth): AttemptFlowPromise; /** * Create an asynchronous _Flow_, a function that pipes values through a series of functions * * _Available as `attemptAsyncFlow` and `attemptFlow.async`_ * * @returns _Flow_ function */ declare function attemptAsyncFlow(fn: Fn, ...fns: Array<(value: Awaited>>) => unknown>): AttemptFlowPromise>; /** * Create an asynchronous _Flow_, a function that pipes values through a series of functions * * _Available as `attemptAsyncFlow` and `attemptFlow.async`_ * * @returns _Flow_ function */ declare function attemptAsyncFlow(...fns: GenericCallback[]): (...args: unknown[]) => Promise>; /** * Create a _Flow_, a function that attempts to pipe values through a function * * @returns _Flow_ function */ declare function attemptFlow(fn: Fn): AttemptFlow>; /** * Create a _Flow_, a function that attempts to pipe values through a series of functions * * @returns _Flow_ function */ declare function attemptFlow(first: First, second: (value: UnwrapValue>) => Second): AttemptFlow; /** * Create a _Flow_, a function that attempts to pipe values through a series of functions * * @returns _Flow_ function */ declare function attemptFlow(first: First, second: (value: UnwrapValue>) => Second, third: (value: UnwrapValue) => Third): AttemptFlow; /** * Create a _Flow_, a function that attempts to pipe values through a series of functions * * @returns _Flow_ function */ declare function attemptFlow(first: First, second: (value: UnwrapValue>) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth): AttemptFlow; /** * Create a _Flow_, a function that attempts to pipe values through a series of functions * * @returns _Flow_ function */ declare function attemptFlow(first: First, second: (value: UnwrapValue>) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth): AttemptFlow; /** * Create a _Flow_, a function that attempts to pipe values through a series of functions * * @returns _Flow_ function */ declare function attemptFlow(first: First, second: (value: UnwrapValue>) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth): AttemptFlow; /** * Create a _Flow_, a function that attempts to pipe values through a series of functions * * @returns _Flow_ function */ declare function attemptFlow(first: First, second: (value: UnwrapValue>) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh): AttemptFlow; /** * Create a _Flow_, a function that attempts to pipe values through a series of functions * * @returns _Flow_ function */ declare function attemptFlow(first: First, second: (value: UnwrapValue>) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh, eighth: (value: UnwrapValue) => Eighth): AttemptFlow; /** * Create a _Flow_, a function that attempts to pipe values through a series of functions * * @returns _Flow_ function */ declare function attemptFlow(first: First, second: (value: UnwrapValue>) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh, eighth: (value: UnwrapValue) => Eighth, ninth: (value: UnwrapValue) => Ninth): AttemptFlow; /** * Create a _Flow_, a function that attempts to pipe values through a series of functions * * @returns _Flow_ function */ declare function attemptFlow(first: First, second: (value: UnwrapValue>) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh, eighth: (value: UnwrapValue) => Eighth, ninth: (value: UnwrapValue) => Ninth, tenth: (value: UnwrapValue) => Tenth): AttemptFlow; /** * Create a _Flow_, a function that attempts to pipe values through a series of functions * * @returns _Flow_ function */ declare function attemptFlow(first: First, ...fns: Array<(value: UnwrapValue>) => unknown>): AttemptFlow>; /** * Create a _Flow_, a function that attempts to pipe values through a series of functions * * @returns _Flow_ function */ declare function attemptFlow(...fns: GenericCallback[]): (...args: unknown[]) => Result; declare namespace attemptFlow { var async: typeof attemptAsyncFlow; } //#endregion //#region src/result/work/pipe.d.ts type WrapValue = Result>; /** * Attempt to pipe a value through a function * * _Available as `attemptAsyncPipe` and `attemptPipe.async`_ * * @param initial Initial value * @returns _Piped_ result */ declare function attemptAsyncPipe(initial: GenericCallback | Initial | Promise | Result, pipe: (value: UnwrapValue) => Piped): Promise>; /** * Attempt to pipe a value through a series of functions * * _Available as `attemptAsyncPipe` and `attemptPipe.async`_ * * @param initial Initial value * @returns _Piped_ result */ declare function attemptAsyncPipe(initial: GenericCallback | Initial | Promise | Result, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second): Promise>; /** * Attempt to pipe a value through a series of functions * * _Available as `attemptAsyncPipe` and `attemptPipe.async`_ * * @param initial Initial value * @returns _Piped_ result */ declare function attemptAsyncPipe(initial: GenericCallback | Initial | Promise | Result, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third): Promise>; /** * Attempt to pipe a value through a series of functions * * _Available as `attemptAsyncPipe` and `attemptPipe.async`_ * * @param initial Initial value * @returns _Piped_ result */ declare function attemptAsyncPipe(initial: GenericCallback | Initial | Promise | Result, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth): Promise>; /** * Attempt to pipe a value through a series of functions * * _Available as `attemptAsyncPipe` and `attemptPipe.async`_ * * @param initial Initial value * @returns _Piped_ result */ declare function attemptAsyncPipe(initial: GenericCallback | Initial | Promise | Result, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth): Promise>; /** * Attempt to pipe a value through a series of functions * * _Available as `attemptAsyncPipe` and `attemptPipe.async`_ * * @param initial Initial value * @returns _Piped_ result */ declare function attemptAsyncPipe(initial: GenericCallback | Initial | Promise | Result, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth): Promise>; /** * Attempt to pipe a value through a series of functions * * _Available as `attemptAsyncPipe` and `attemptPipe.async`_ * * @param initial Initial value * @returns _Piped_ result */ declare function attemptAsyncPipe(initial: GenericCallback | Initial | Promise | Result, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh): Promise>; /** * Attempt to pipe a value through a series of functions * * _Available as `attemptAsyncPipe` and `attemptPipe.async`_ * * @param initial Initial value * @returns _Piped_ result */ declare function attemptAsyncPipe(initial: GenericCallback | Initial | Promise | Result, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh, eighth: (value: UnwrapValue) => Eighth): Promise>; /** * Attempt to pipe a value through a series of functions * * _Available as `attemptAsyncPipe` and `attemptPipe.async`_ * * @param initial Initial value * @returns _Piped_ result */ declare function attemptAsyncPipe(initial: GenericCallback | Initial | Promise | Result, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh, eighth: (value: UnwrapValue) => Eighth, ninth: (value: UnwrapValue) => Ninth): Promise>; /** * Attempt to pipe a value through a series of functions * * _Available as `attemptAsyncPipe` and `attemptPipe.async`_ * * @param initial Initial value * @returns _Piped_ result */ declare function attemptAsyncPipe(initial: GenericCallback | Initial | Promise | Result, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh, eighth: (value: UnwrapValue) => Eighth, ninth: (value: UnwrapValue) => Ninth, tenth: (value: UnwrapValue) => Tenth): Promise>; /** * Attempt to pipe a result through a series of functions * * _Available as `attemptAsyncPipe` and `attemptPipe.async`_ * * @param initial Initial result * @returns _Piped_ result */ declare function attemptAsyncPipe(initial: GenericCallback | Initial | Promise | Result, first?: (value: UnwrapValue) => unknown, ...seconds: Array<(value: unknown) => unknown>): Promise>; /** * Attempt to pipe a value through a function * * @param initial Initial value * @returns _Piped_ result */ declare function attemptPipe(initial: GenericCallback | Initial | Result, pipe: (value: UnwrapValue) => Pipe): WrapValue; /** * Attempt to pipe a value through a series of functions * * @param initial Initial value * @returns _Piped_ result */ declare function attemptPipe(initial: GenericCallback | Initial | Result, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second): WrapValue; /** * Attempt to pipe a value through a series of functions * * @param initial Initial value * @returns _Piped_ result */ declare function attemptPipe(initial: GenericCallback | Initial | Result, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third): WrapValue; /** * Attempt to pipe a value through a series of functions * * @param initial Initial value * @returns _Piped_ result */ declare function attemptPipe(initial: GenericCallback | Initial | Result, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth): WrapValue; /** * Attempt to pipe a value through a series of functions * * @param initial Initial value * @returns _Piped_ result */ declare function attemptPipe(initial: GenericCallback | Initial | Result, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth): WrapValue; /** * Attempt to pipe a value through a series of functions * * @param initial Initial value * @returns _Piped_ result */ declare function attemptPipe(initial: GenericCallback | Initial | Result, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth): WrapValue; /** * Attempt to pipe a value through a series of functions * * @param initial Initial value * @returns _Piped_ result */ declare function attemptPipe(initial: GenericCallback | Initial | Result, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh): WrapValue; /** * Attempt to pipe a value through a series of functions * * @param initial Initial value * @returns _Piped_ result */ declare function attemptPipe(initial: GenericCallback | Initial | Result, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh, eighth: (value: UnwrapValue) => Eighth): WrapValue; /** * Attempt to pipe a value through a series of functions * * @param initial Initial value * @returns _Piped_ result */ declare function attemptPipe(initial: GenericCallback | Initial | Result, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh, eighth: (value: UnwrapValue) => Eighth, ninth: (value: UnwrapValue) => Ninth): WrapValue; /** * Attempt to pipe a value through a series of functions * * @param initial Initial value * @returns _Piped_ result */ declare function attemptPipe(initial: GenericCallback | Initial | Result, first: (value: UnwrapValue) => First, second: (value: UnwrapValue) => Second, third: (value: UnwrapValue) => Third, fourth: (value: UnwrapValue) => Fourth, fifth: (value: UnwrapValue) => Fifth, sixth: (value: UnwrapValue) => Sixth, seventh: (value: UnwrapValue) => Seventh, eighth: (value: UnwrapValue) => Eighth, ninth: (value: UnwrapValue) => Ninth, tenth: (value: UnwrapValue) => Tenth): WrapValue; /** * Attempt to pipe a result through a series of functions * * @param initial Initial result * @returns _Piped_ result */ declare function attemptPipe(initial: GenericCallback | Initial | Result, first?: (value: UnwrapValue) => unknown, ...seconds: Array<(value: unknown) => unknown>): WrapValue; declare namespace attemptPipe { var async: typeof attemptAsyncPipe; } //#endregion //#region src/sized/map.d.ts /** * A _Map_ with a maximum size * * Behavior is similar to a _LRU_ cache, where the least recently used entries are removed */ declare class SizedMap extends Map { #private; /** * Is the _Map_ full? */ get full(): boolean; get maximum(): number; /** * Create a new _SizedMap_ with entries and a maximum size _(2^20)_ * * @param entries Array of key-value pairs to initialize the _SizedMap_ with * @template SizedKey Type of the keys in the _SizedMap_ * @template SizedValue Type of the values in the _SizedMap_ */ constructor(entries: [SizedKey, SizedValue][]); /** * Create a new _SizedMap_ with a maximum size _(but clamped at 2^24)_ * * @param maximum Maximum size of the _SizedMap_ * @template SizedKey Type of the keys in the _SizedMap_ * @template SizedValue Type of the values in the _SizedMap_ */ constructor(maximum: number); /** * Create a new _SizedMap_ with _(optional)_ entries and a maximum size * * @param entries Array of key-value pairs to initialize the _SizedMap_ with * @param maximum Maximum size of the _SizedMap_ _(defaults to 2^20; clamped at 2^24)_ * @template SizedKey Type of the keys in the _SizedMap_ * @template SizedValue Type of the values in the _SizedMap_ */ constructor(entries?: [SizedKey, SizedValue][], maximum?: number); /** * @inheritdoc */ get(key: SizedKey): SizedValue | undefined; /** * @inheritdoc */ set(key: SizedKey, value: SizedValue): this; } //#endregion //#region src/sized/set.d.ts /** * A _Set_ with a maximum size * * Behavior is similar to a _LRU_ cache, where the oldest values are removed */ declare class SizedSet extends Set { #private; /** * Is the _Set_ full? */ get full(): boolean; get maximum(): number; /** * Create a new _SizedSet_ with values and a maximum size _(2^20)_ * * @param values Array of values to initialize the _SizedSet_ with * @template Value Type of the values in the _SizedSet_ */ constructor(values: Value[]); /** * Create a new _SizedSet_ with a maximum size _(but clamped at 2^24)_ * * @param maximum Maximum size of the _SizedSet_ _(defaults to 2^20; clamped at 2^24)_ * @template Value Type of the values in the _SizedSet_ */ constructor(maximum: number); /** * Create a new _SizedSet_ with _(optional)_ values and a maximum size * * @param values Array of values to initialize the _SizedSet_ with * @param maximum Maximum size of the _SizedSet_ _(defaults to 2^20; clamped at 2^24)_ * @template Value Type of the values in the _SizedSet_ */ constructor(values?: Value[], maximum?: number); /** * @inheritdoc */ add(value: Value): this; /** * Get a value from the _SizedSet_, if it exists _(and optionally move it to the end)_ * * @param value Value to get from the _SizedSet_ * @param update Update the value's position in the _SizedSet_? _(defaults to `false`)_ * @returns Found value if it exists, otherwise `undefined` */ get(value: Value, update?: boolean): Value | undefined; } //#endregion export { AnyResult, ArrayComparison, ArrayComparisonSorter, ArrayKeySorter, ArrayOrPlainObject, ArrayValueSorter, AssertProperty, Asserter, AssignOptions, Assigner, AsyncCancelableCallback, AttemptFlow, AttemptFlowPromise, type Beacon, type BeaconOptions, BuiltIns, CancelableCallback, CancelablePromise, type Color, Constructor, DiffOptions, DiffResult, DiffValue, EqualOptions, Err, EventPosition, type Events, ExtendedErr, ExtendedResult, Flow, FlowPromise, Frozen, FulfilledPromise, FuzzyConfiguration, FuzzyOptions, FuzzyResult, FuzzySearchOptions, GenericAsyncCallback, GenericCallback, type HSLAColor, type HSLColor, type Herald, Key$1 as Key, type KeyedQueue, KeyedValue, Logger, type Memoized, type MemoizedOptions, MergeOptions, Merger, NestedArray, NestedKeys, NestedPartial, NestedValue, NestedValues, NormalizeOptions, Normalizer, NumericalKeys, NumericalValues, type Observable, type Observer, Ok, OnceAsyncCallback, OnceCallback, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PlainObject, Primitive, PromiseData, PromiseHandlers, PromiseOptions, PromiseParameters, PromiseStrategy, PromiseTimeoutError, PromisesItems, PromisesOptions, PromisesResult, PromisesUnwrapped, PromisesValue, PromisesValues, type Queue, type QueueError, type QueueOptions, type Queued, type QueuedResult, type RGBAColor, type RGBColor, RejectedPromise, RequiredKeys, Result, ResultMatch, RetryError, RetryOptions, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, type Shaken, Simplify, SizedMap, SizedSet, type Smushed, SortDirection, Sorter, type Subscription, TemplateOptions, type TimedLogger, ToString, Transformer, TypedArray, UnionToIntersection, type Unsmushed, Unsubscriber, UnwrapValue, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty, assign, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, copy, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, flatFreeze, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, herald, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, interpolate, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFrozen, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isSorted, isTypedArray, join, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, lowerCase, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, normalize, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, transform, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };