export { debounce, throttle } from '/Users/enzoinnocenzi/Code/projects/utils/node_modules/.pnpm/@types+throttle-debounce@5.0.2/node_modules/@types/throttle-debounce/index.d.ts'; type Awaitable = T | PromiseLike; type AwaitableFn = Fn>; type Nullable = T | null | undefined; type Arrayable = T | Array; type Fn = () => T; type Constructor = new (...args: any[]) => T; type ElementOf = T extends (infer E)[] ? E : never; /** * Defines an intersection type of all union items. * * @param U Union of any types that will be intersected. * @returns U items intersected * @see https://stackoverflow.com/a/50375286/9259330 */ type UnionToIntersection = (U extends unknown ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never; /** * Infers the arguments type of a function */ type ArgumentsType = T extends ((...args: infer A) => any) ? A : never; type MergeInsertions = T extends object ? { [K in keyof T]: MergeInsertions; } : T; type DeepMerge = MergeInsertions<{ [K in keyof F | keyof S]: K extends keyof S & keyof F ? DeepMerge : K extends keyof S ? S[K] : K extends keyof F ? F[K] : never; }>; interface Vector2 { x: number; y: number; } interface Vector3 { x: number; y: number; z: number; } /** * Converts an `Arrayable` to an `Array`. * * @category Array */ declare function toArray(array?: Nullable>): Array; /** * Converts an `Arrayable` to `Array` and flattens it. * * @category Array */ declare function flattenArrayable(array?: Nullable>>): Array; /** * Merges multiple `Arrayable`. * * @category Array */ declare function mergeArrayable(...args: Nullable>[]): Array; type PartitionFilter = (i: T, idx: number, arr: readonly T[]) => any; /** * Divides an array into two parts by a filter function. * * @category Array * @example const [odd, even] = partition([1, 2, 3, 4], (i) => i % 2 != 0) */ declare function partition(array: readonly T[], f1: PartitionFilter): [T[], T[]]; declare function partition(array: readonly T[], f1: PartitionFilter, f2: PartitionFilter): [T[], T[], T[]]; declare function partition(array: readonly T[], f1: PartitionFilter, f2: PartitionFilter, f3: PartitionFilter): [T[], T[], T[], T[]]; declare function partition(array: readonly T[], f1: PartitionFilter, f2: PartitionFilter, f3: PartitionFilter, f4: PartitionFilter): [T[], T[], T[], T[], T[]]; declare function partition(array: readonly T[], f1: PartitionFilter, f2: PartitionFilter, f3: PartitionFilter, f4: PartitionFilter, f5: PartitionFilter): [T[], T[], T[], T[], T[], T[]]; declare function partition(array: readonly T[], f1: PartitionFilter, f2: PartitionFilter, f3: PartitionFilter, f4: PartitionFilter, f5: PartitionFilter, f6: PartitionFilter): [T[], T[], T[], T[], T[], T[], T[]]; /** * Returns a copy of an array without duplicates. * * @category Array */ declare function uniq(array: readonly T[]): T[]; /** * Returns a copy of an array without duplicates using the given equality function. * * @category Array */ declare function uniqueBy(array: readonly T[], equalFn: (a: any, b: any) => boolean): T[]; /** * Gets the last item of an array. * * @category Array */ declare function last(array: readonly []): undefined; declare function last(array: readonly T[]): T; /** * Removes an item from an array. * * @category Array */ declare function remove(array: T[], value: T): boolean; /** * Gets the nth item of an array. * * @category Array */ declare function at(array: readonly [], index: number): undefined; declare function at(array: readonly T[], index: number): T; /** * Generates a range array of numbers. `stop` is exclusive. * * @category Array */ declare function range(stop: number): number[]; declare function range(start: number, stop: number, step?: number): number[]; /** * Moves an element in an array. * * @category Array * @param arr * @param from * @param to */ declare function move(arr: T[], from: number, to: number): T[]; /** * Clamps a number to the index range of an array. * * @category Array */ declare function clampArrayRange(n: number, arr: readonly unknown[]): number; /** * Gets random item(s) from an array. * * @param arr * @param quantity - quantity of random items which will be returned */ declare function sample(arr: T[], quantity: number): T[]; /** * Shuffles an array. This function mutates the array. * * @category Array */ declare function shuffle(array: T[]): T[]; /** * Expands a single-dimensional object that uses "dot" notation into a multi-dimensional object. */ declare function undot(input: T): any; /** * Flattens a multi-dimensional object into a single-level object that uses "dot" notation to indicate depth:. */ declare function dot>(input?: T): Record; /** * Joins an array of strings with a separator, using a different separator for the last item. */ declare function join(array: T[], options?: { separator?: string; lastSeparator?: string; }): string; declare function assert(condition: boolean, message: string): asserts condition; declare function getTypeAsString(v: any): string; declare function getTypeName(v: any): string; declare function noop(): void; declare function isDeepEqual(value1: any, value2: any): boolean; /** * Utility type to extract the variant of a discriminated union. * * @template T - The union type. * @template K - The discriminator key. * @template V - The discriminator value. */ type VariantOf = T extends Record ? T : never; /** * Represents a handler for a case in a switch-case structure. * * @template T - The type of the value being matched. * @template R - The return type of the handler function. * @property {T} match - A value or a function to match against the input. * @property {(val: T) => R} handler - A function that processes the matched value and returns a result. */ type CaseHandler = { match: T; handler: (val: T) => R; } | { match: (val: T) => boolean; handler: (val: T) => R; }; /** * Interface for building a switch-case structure with fluent API. * * @template T - The type of the value being matched. * @template R - The return type of the handler functions. * @template Remaining - The remaining keys that can be matched. */ interface SwitchCaseBuilder { /** * Adds a case to the switch-case structure. * * @template K - The type of the key being matched. * @param {K} match - A value to match or a function to evaluate the match. * @param {R | (() => R)} handler - A result or a function that returns a result for the matched case. * @returns {SwitchCaseBuilder>} - The updated builder with the new case added. */ case: ((match: K, handler: R | (() => R)) => SwitchCaseBuilder>) & ((match: (val: T) => boolean, handler: R | ((val: T) => R)) => SwitchCaseBuilder); /** * Adds a default handler for unmatched cases. * * @param {(val: T) => R} handler - A function to handle unmatched cases. * @returns {SwitchCaseBuilder} - The updated builder with the default handler added. */ default: (handler: (val: T) => R) => SwitchCaseBuilder; /** * Ensures all cases are handled and returns the result. * * @returns {Remaining extends never ? R : never} - The result of the matched case or an error if cases are missing. */ exhaustive: () => Remaining extends never ? R : never; /** * Executes the switch-case structure and returns the result. * * @returns {R} - The result of the matched case or the default handler. */ run: () => R; } /** * Interface for building a discriminated union switch-case structure with fluent API. * * @template T - The type of the value being matched. * @template K - The discriminator key. * @template R - The return type of the handler functions. * @template Remaining - The remaining discriminator values that can be matched. */ interface DiscriminatedUnionSwitchCaseBuilder { /** * Adds a case for a specific discriminator value. * * @template V - The discriminator value. * @param {V} value - The discriminator value to match. * @param {(val: VariantOf) => R} handler - Handler for this case. * @returns {DiscriminatedUnionSwitchCaseBuilder>} */ case: (value: V, handler: (val: VariantOf) => R) => DiscriminatedUnionSwitchCaseBuilder>; /** * Adds a default handler for unmatched cases. * * @param {(val: T) => R} handler - Handler for unmatched cases. * @returns {DiscriminatedUnionSwitchCaseBuilder} */ default: (handler: (val: T) => R) => DiscriminatedUnionSwitchCaseBuilder; /** * Executes the switch-case structure and returns the result. * * @returns {R} - The result of the matched case or the default handler. */ run: () => R; } declare function switchCase(value: T, cases: { [K in T]: R | (() => R); }, defaultHandler?: (val: T) => R): R; declare function switchCase(value: T, discriminator: K, cases: { [P in V]: R | ((val: T & { [Q in K]: P; }) => R); }, defaultHandler?: (val: T) => R): R; declare function switchCase(value: T, cases: Record>, defaultHandler?: (val: T) => R): R; declare function switchCase(value: T, cases: Array<{ match: (val: T) => boolean; handler: R | ((val: T) => R); }>, defaultHandler?: (val: T) => R): R; declare function switchCase(value: T): SwitchCaseBuilder; declare function switchCase(value: T): SwitchCaseBuilder; declare function switchCase(value: T, discriminator: K): DiscriminatedUnionSwitchCaseBuilder; /** * Call every function in an array. * * @category Functions */ declare function batchInvoke(functions: Nullable[]): void; /** * Calls the given function. * * @category Functions */ declare function invoke(fn: undefined): undefined; declare function invoke(fn: Fn): T; /** * Calls the given function. * * @category Functions */ declare function asyncInvoke(fn: AwaitableFn): Promise; /** * Returns the given value, or the result of the callback if the value is a function. * * @category Functions */ declare function value(value: undefined): undefined; declare function value(value: T | Fn): T; /** * Passes the value through the callback, and returns the value. * * @category Functions * @example * ``` * function createUser(name: string): User { * return tap(new User, user => { * user.name = name * }) * } * ``` */ declare function tap(value: undefined, callback: (value: undefined) => void): undefined; declare function tap(value: T, callback: (value: T) => void): T; /** * Asynchronously tries the specified promise. * * @example * ``` * const [result, error] = await tryAsync(fetch(url)) */ declare function tryAsync(fn: AwaitableFn): Promise<[T, null] | [null, Error]>; /** * Memoizes a value. * * @example * ``` * const result = memoize(() => expensiveFn()) * result.value // computed * result.value // memoized */ declare function memoize(getter: () => T): { value: T; }; /** * Filters out nullish values. * * @category Guards * @example array.filter(notNullish) */ declare function notNullish(v: T | null | undefined): v is NonNullable; /** * Filters our `null` values. * * @category Guards * @example array.filter(noNull) */ declare function noNull(v: T | null): v is Exclude; /** * Filters out `undefined` values. * * @category Guards * @example array.filter(notUndefined) */ declare function notUndefined(v: T): v is Exclude; /** * Filters out truthy values. * * @category Guards * @example array.filter(isTruthy) */ declare function isTruthy(v: T): v is NonNullable; declare const isDef: (val?: T) => val is T; declare const isBoolean: (val: any) => val is boolean; declare const isFunction: (val: any) => val is T; declare const isNumber: (val: any) => val is number; declare const isString: (val: unknown) => val is string; declare const isObject: (val: any) => val is object; declare const isUndefined: (val: any) => val is undefined; declare const isNull: (val: any) => val is null; declare const isRegExp: (val: any) => val is RegExp; declare const isDate: (val: any) => val is Date; declare const isWindow: (val: any) => boolean; declare const isBrowser: boolean; /** * Clamps the given number between `min` and `max`. * * @category Math */ declare function clamp(n: number, min: number, max: number): number; /** * Returns the sum of all numbers in the given array. * * @category Math */ declare function sum(...args: number[] | number[][]): number; /** * Linearly interpolates between `min` and `max` based on `t` * * @category Math * @param t The interpolation value clamped between 0 and 1 * @example * ``` * const value = lerp(0, 2, 0.5) // value will be 1 * ``` */ declare function lerp(min: number, max: number, t: number): number; /** * Returns the magnitude of a vector with components `a` and `b`. * * @category Math */ declare function magnitude(a: number, b: number): number; /** * Linearly remaps a clamped value from its source range [`inMin`, `inMax`] to the destination range [`outMin`, `outMax`] * * @category Math * @example * ``` * const value = remap(0.5, 0, 1, 200, 400) // value will be 300 * ``` */ declare function remap(n: number, inMin: number, inMax: number, outMin: number, outMax: number): number; /** * Gradually changes a value towards a desired goal over time. * From: https://github.com/Unity-Technologies/UnityCsReference/blob/02d565cf3dd0f6b15069ba976064c75dc2705b08/Runtime/Export/Math/Mathf.cs#L301-L329 * * @param velocity Reference to current velocity * @param smoothTime Larger number = more smoothing * @param deltaTime In seconds */ declare function smoothDamp(current: number, target: number, velocity: number, smoothTime: number, maxSpeed: number, deltaTime: number): { smoothed: number; velocity: number; }; /** * Maps key/value pairs for an object, and constructs a new one. * * * @category Object * * Transform: * @example * ``` * objectMap({ a: 1, b: 2 }, (k, v) => [k.toString().toUpperCase(), v.toString()]) * // { A: '1', B: '2' } * ``` * * Swap key/value: * @example * ``` * objectMap({ a: 1, b: 2 }, (k, v) => [v, k]) * // { 1: 'a', 2: 'b' } * ``` * * Filter keys: * @example * ``` * objectMap({ a: 1, b: 2 }, (k, v) => k === 'a' ? undefined : [k, v]) * // { b: 2 } * ``` */ declare function objectMap(obj: Record, fn: (key: K, value: V) => [NK, NV] | undefined): Record; /** * Type guard for any key, `k`. * Marks `k` as a key of `T` if `k` is in `obj`. * * @category Object * @param obj object to query for key `k` * @param k key to check existence in `obj` */ declare function isKeyOf(obj: T, k: keyof any): k is keyof T; /** * Strictly-typed `Object.keys`. * * @category Object */ declare function objectKeys(obj: T): Array<`${keyof T & (string | number | boolean | null | undefined)}`>; /** * Strictly-typed `Object.entries`. * * @category Object */ declare function objectEntries(obj: T): Array<[keyof T, T[keyof T]]>; /** * Deeply merges multiple objects. * * The first argument is the target object, the rest are the sources. * The target object will be mutated and returned. * * @category Object */ declare function deepMerge(target: T, ...sources: S[]): DeepMerge; /** * Deeply merges multiple objects, including their arrays. * * Differs from `deepMerge` in that it merges arrays instead of overriding them. * * The first argument is the target object, the rest are the sources. * The target object will be mutated and returned. * * @category Object */ declare function deepMergeWithArray(target: T, ...sources: S[]): DeepMerge; /** * Creates a new object with only the specified keys. * * @category Object */ declare function objectPick(obj: O, keys: T[], omitUndefined?: boolean): Pick; /** * Creates a new object without the specified keys. * * @category Object */ declare function objectOmit(obj: O, keys: T[], omitUndefined?: boolean): Omit; /** * Clears undefined fields from an object. It mutates the object. * * @category Object */ declare function clearUndefined(obj: T): T; /** * Determines whether an object has a property with the specified name. * * @see https://eslint.org/docs/rules/no-prototype-builtins * @category Object */ declare function hasOwnProperty(obj: T, v: PropertyKey): boolean; interface POptions { /** * How many promises are resolved at the same time. */ concurrency?: number | undefined; } declare class PInstance extends Promise[]> { items: Iterable; options?: POptions | undefined; private promises; get promise(): Promise[]>; constructor(items?: Iterable, options?: POptions | undefined); add(...args: (T | Promise)[]): void; map(fn: (value: Awaited, index: number) => U): PInstance>; filter(fn: (value: Awaited, index: number) => boolean | Promise): PInstance>; forEach(fn: (value: Awaited, index: number) => void): Promise; reduce(fn: (previousValue: U, currentValue: Awaited, currentIndex: number, array: Awaited[]) => U, initialValue: U): Promise; clear(): void; then(fn?: () => PromiseLike): Promise; catch(fn?: (err: unknown) => PromiseLike): Promise; finally(fn?: () => void): Promise[]>; } /** * Utility for managing multiple promises. * * @see https://github.com/antfu/utils/tree/main/docs/p.md * @category Promise * @example * ``` * import { p } from '@innocenzi/utils' * * const items = [1, 2, 3, 4, 5] * * await p(items) * .map(async i => await multiply(i, 3)) * .filter(async i => await isEven(i)) * // [6, 12] * ``` */ declare function p(items?: Iterable, options?: POptions): PInstance; interface SingletonPromiseReturn { (): Promise; /** * Resets the current staled promise. * Await it to have proper shutdown. */ reset: () => Promise; } /** * Creates a singleton promise function. * * @category Promise * @example * ``` * const fn = createSingletonPromise(async () => { * await doSomething() * }) * * await fn * fn.reset() * ``` */ declare function createSingletonPromise(fn: () => Promise): SingletonPromiseReturn; /** * Waits for the given amount of milliseconds. * * @category Promise */ declare function sleep(ms: number, callback?: Fn): Promise; /** * Creates a deferred promise. * * @category Promise * @example * ``` * const lock = createPromiseLock() * * lock.run(async () => { * await doSomething() * }) * * // in anther context: * await lock.wait() // it will wait all tasking finished * ``` */ declare function createDefferedPromise(): { run(fn: () => Promise): Promise; wait(): Promise; isWaiting(): boolean; clear(): void; }; /** * Promise with `resolve` and `reject` methods of itself */ interface ControlledPromise extends Promise { resolve: (value: T | PromiseLike) => void; reject: (reason?: any) => void; } /** * Returns a Promise with `resolve` and `reject` methods. * * @category Promise * @example * ``` * const promise = createControlledPromise() * * await promise * * // in anther context: * promise.resolve(data) * ``` */ declare function createControlledPromise(): ControlledPromise; /** * Replaces backslashes with forward slashes. * * @category String */ declare function toForwardSlashes(str: string): string; /** * Replaces forward slashes with backslashes. * * @category String */ declare function toBackSlashes(str: string): string; /** * Ensures the given string starts with the given prefix. * * @category String */ declare function ensureStartsWith(prefix: string, str: string): string; /** * Returns everything before the given value. * * @category String */ declare function before(str: string, separator: string | number): string; /** * Returns everything before the last occurrence of the given value. * * @category String */ declare function beforeLast(str: string, separator: string | number): string; /** * Returns everything after the given value. * * @category String */ declare function after(str: string, separator: string | number): string; /** * Returns everything after the last occurrence of the given value. * * @category String */ declare function afterLast(str: string, separator: string | number): string; /** * Gets the portion of a string between two given values. */ declare function between(str: string, start: string | number, end: string | number): string; /** * Gets the smallest possible portion of a string between two given values. */ declare function betweenShrink(str: string, start: string | number, end: string | number): string; /** * Replaces the first occurrence of a given value in a string. * * @category String */ declare function replaceFirst(search: string | number, replace: string | number, str: string): string; /** * Replaces the last occurrence of a given value in a string. * * @category String */ declare function replaceLast(search: string | number, replace: string | number, str: string): string; /** * Ensures the given string ends with the given suffix. * * @category String */ declare function ensureEndsWith(suffix: string, str: string): string; /** * Removes duplicate spaces from a string. */ declare function squish(str: string): string; /** * Masks a portion of a string with a repeated character. */ declare function mask(str: string, mask: string, index: number, length?: number): string; /** * Dead simple template engine, just like Python's `.format()` * Support passing variables as either in index based or object/name based approach * While using object/name based approach, you can pass a fallback value as the third argument * * @category String * @example * ``` * const result = template( * 'Hello {0}! My name is {1}.', * 'Inès', * 'Anthony' * ) // Hello Inès! My name is Anthony. * ``` * * ``` * const result = namedTemplate( * '{greet}! My name is {name}.', * { greet: 'Hello', name: 'Anthony' } * ) // Hello! My name is Anthony. * ``` * * const result = namedTemplate( * '{greet}! My name is {name}.', * { greet: 'Hello' }, // name isn't passed hence fallback will be used for name * 'placeholder' * ) // Hello! My name is placeholder. * ``` */ declare function template(str: string, object: Record, fallback?: string | ((key: string) => string)): string; declare function template(str: string, ...args: (string | number | bigint | undefined | null)[]): string; /** * Generate a random string * @category String */ declare function randomStr(size?: number, dict?: string): string; /** * First letter uppercase, other lowercase * @category string * @example * ``` * capitalize('hello') => 'Hello' * ``` */ declare function capitalize(str: string): string; export { after, afterLast, assert, asyncInvoke, at, batchInvoke, before, beforeLast, between, betweenShrink, capitalize, clamp, clampArrayRange, clearUndefined, createControlledPromise, createDefferedPromise, createSingletonPromise, deepMerge, deepMergeWithArray, dot, ensureEndsWith, ensureStartsWith, flattenArrayable, getTypeAsString, getTypeName, hasOwnProperty, invoke, isBoolean, isBrowser, isDate, isDeepEqual, isDef, isFunction, isKeyOf, isNull, isNumber, isObject, isRegExp, isString, isTruthy, isUndefined, isWindow, join, last, lerp, magnitude, mask, switchCase as match, memoize, mergeArrayable, move, noNull, noop, notNullish, notUndefined, objectEntries, objectKeys, objectMap, objectOmit, objectPick, p, partition, randomStr, range, remap, remove, replaceFirst, replaceLast, sample, shuffle, sleep, smoothDamp, squish, sum, tap, template, toArray, toBackSlashes, toForwardSlashes, tryAsync, undot, uniq, uniqueBy, value }; export type { ArgumentsType, Arrayable, Awaitable, AwaitableFn, Constructor, ControlledPromise, DeepMerge, ElementOf, Fn, MergeInsertions, Nullable, PartitionFilter, SingletonPromiseReturn, UnionToIntersection, Vector2, Vector3 };