import { DeepPartial, ID } from "../types/index.mjs"; //#region src/utilities/helpers.d.ts /** * Checks if a value is a function * * @param item The value to check * @returns True if the value is a function * * @example * ```ts * isFunction(() => {}) // true * isFunction('string') // false * ``` */ declare function isFunction(item: unknown): item is Function; /** * Checks if a value is a string * * @param item The value to check * @returns True if the value is a string * * @example * ```ts * isString('hello') // true * isString(123) // false * ``` */ declare function isString(item: unknown): item is string; /** * Checks if a value is a number * * @param item The value to check * @returns True if the value is a number (including NaN) * * @example * ```ts * isNumber(123) // true * isNumber(NaN) // true * isNumber('123') // false * ``` * * @see {@link isNaN} to check for NaN specifically */ declare function isNumber(item: unknown): item is number; /** * Checks if a value is a boolean * * @param item The value to check * @returns True if the value is a boolean * * @example * ```ts * isBoolean(true) // true * isBoolean(false) // true * isBoolean(0) // false * ``` */ declare function isBoolean(item: unknown): item is boolean; /** * Checks if a value is a plain object (excludes null and arrays) * * @param item The value to check * @returns True if the value is a plain object * * @remarks * Returns false for null and arrays, even though `typeof null === 'object'` * and `typeof [] === 'object'` in JavaScript. * * `Record` is load-bearing: TypeScript does not grant interfaces * an implicit index signature, so `Record` destroys known * property types on interface-typed values and fails to subtract * `Record` members in the negative branch. * * @example * ```ts * isObject({}) // true * isObject({ a: 1 }) // true * isObject(null) // false * isObject([]) // false * ``` * * @see {@link isArray} to check for arrays * @see {@link isNull} to check for null */ declare function isObject(item: unknown): item is Record; /** * Checks if a value is a thenable (any object with a `.then` method). * Duck-typed — matches both native Promises and any Promise-like. * * @param item The value to check * @returns True if the value has a callable `then` property * * @example * ```ts * isThenable(Promise.resolve()) // true * isThenable({ then: () => {} }) // true * isThenable({}) // false * isThenable('string') // false * ``` * * @remarks Use this when duck-typing async behavior — for example, rejecting * a callback that returned a Promise-like when only synchronous returns are * supported. If you specifically want native Promise instances, use * `instanceof Promise` directly. */ declare function isThenable(item: unknown): item is { then: Function; }; /** * Checks if a value is an array * * @param item The value to check * @returns True if the value is an array * * @example * ```ts * isArray([]) // true * isArray([1, 2, 3]) // true * isArray('string') // false * ``` * * @remarks The guard keeps whichever array constituents the input already had — * element types, tuple arity and `readonly` all survive, and the `else` branch * drops exactly those constituents. Three branches, in order: * * 1. `0 extends (1 & T)` detects an `any` input and yields `T[]` (`any[]`), * matching `Array.isArray` so callback parameters stay contextually typed. * 2. Nothing array-shaped to extract (an `unknown` value, say) falls back to * `unknown[]`, reproducing the previous narrowing so mutation and assignment * to `unknown[]` keep compiling. * 3. Otherwise the array constituents of `T` pass through untouched. * * `NoInfer` widens the parameter just enough for TypeScript to accept the * first branch (a predicate must be assignable to its parameter's type) without * letting an array argument capture the inference site. */ declare function isArray(item: T | NoInfer): item is 0 extends (1 & T) ? T[] : [Extract] extends [never] ? T & unknown[] : Extract; /** * Checks if a value is a DOM Element * * @param item The value to check * @returns True if the value is a DOM Element * * @example * ```ts * isElement(document.body) // true * isElement('string') // false * isElement(null) // false * ``` */ declare function isElement(item: unknown): item is Element; /** * Resolve the deepest focused element, piercing open shadow roots. * * `document.activeElement` returns the shadow *host* when focus is inside an * open shadow root — walk down through open roots so focus/keyboard logic * resolves the real focused element (e.g. a control inside a custom element). * Returns the same value as `document.activeElement` in light DOM, and `null` * under SSR. Closed shadow roots can't be traversed. * * @example * ```ts * const active = getActiveElement() * ``` */ declare function getActiveElement(): Element | null; /** * Checks if a value is null * * @param item The value to check * @returns True if the value is null * * @example * ```ts * isNull(null) // true * isNull(undefined) // false * ``` * * @see {@link isUndefined} to check for undefined * @see {@link isNullOrUndefined} to check for either */ declare function isNull(item: unknown): item is null; /** * Checks if a value is null or undefined * * @param item The value to check * @returns True if the value is null or undefined * * @remarks * Uses loose equality (`== null`) which matches both null and undefined. * * @example * ```ts * isNullOrUndefined(null) // true * isNullOrUndefined(undefined) // true * isNullOrUndefined(0) // false * isNullOrUndefined('') // false * ``` * * @see {@link isNull} to check for null only * @see {@link isUndefined} to check for undefined only */ declare function isNullOrUndefined(item: unknown): item is null | undefined; /** * Checks if a value is undefined * * @param item The value to check * @returns True if the value is undefined * * @example * ```ts * isUndefined(undefined) // true * isUndefined(null) // false * ``` * * @see {@link isNull} to check for null * @see {@link isNullOrUndefined} to check for either */ declare function isUndefined(item: unknown): item is undefined; /** * Checks if a value is a primitive (string, number, or boolean) * * @param item The value to check * @returns True if the value is a string, number, or boolean * * @example * ```ts * isPrimitive('hello') // true * isPrimitive(123) // true * isPrimitive(true) // true * isPrimitive({}) // false * isPrimitive(null) // false * ``` */ declare function isPrimitive(item: unknown): item is string | number | boolean; /** * Checks if a value is a symbol * * @param item The value to check * @returns True if the value is a symbol * * @example * ```ts * isSymbol(Symbol('test')) // true * isSymbol('symbol') // false * ``` */ declare function isSymbol(item: unknown): item is symbol; /** * Checks if a value is NaN (Not a Number) * * @param item The value to check * @returns True if the value is NaN * * @remarks * Uses `Number.isNaN()` which only returns true for the actual NaN value, * unlike the global `isNaN()` which coerces the argument to a number first. * * @example * ```ts * isNaN(NaN) // true * isNaN(123) // false * isNaN('hello') // false (unlike global isNaN) * isNaN(undefined) // false (unlike global isNaN) * ``` * * @see {@link isNumber} to check if a value is a number type */ declare function isNaN(item: unknown): item is number; declare const UNSAFE_KEYS: Set; /** * Deeply merges source objects into a target object, returning a new object * * @param target The base object to merge into * @param sources One or more source objects to merge from * @returns A new merged object (inputs are not mutated) * * @remarks * - Creates and returns a new object — inputs are never mutated * - Nested objects are recursively merged * - Arrays are replaced, not merged * - Primitives from sources overwrite target values * * @example * ```ts * const target = { a: 1, b: { c: 2 } } * const result = mergeDeep(target, { b: { d: 3 } }) * // result is { a: 1, b: { c: 2, d: 3 } } * // target is unchanged * * // Multiple sources * mergeDeep({}, { a: 1 }, { b: 2 }) // { a: 1, b: 2 } * * // Arrays are replaced * mergeDeep({ arr: [1, 2] }, { arr: [3] }) // { arr: [3] } * ``` */ declare function mergeDeep(target: T, ...sources: DeepPartial[]): T; /** * Generates a unique ID, using Vue's useId when in component context * * @returns A unique string ID * * @remarks * - In component setup/lifecycle: Uses Vue's `useId()` for SSR-safe hydration * - Outside components: Falls back to sequential counter (`v0-0`, `v0-1`, ...) * - Vapor mode compatible * - IDs are sequential and predictable — intended for DOM `id`/ARIA wiring only. * Never use them as security tokens (CSRF tokens, session ids, capabilities). * * @example * ```ts * // In component setup - SSR safe * const id = useId() // 'v:0', 'v:1', etc. (Vue's format) * * // Outside component - counter fallback * const id = useId() // 'v0-0', 'v0-1', etc. * ``` */ declare function useId(): string; /** * Clamps a value between a minimum and maximum * * @param value The value to clamp * @param min The minimum value (default: 0) * @param max The maximum value (default: 1) * @returns The clamped value * * @example * ```ts * clamp(5, 0, 10) // 5 * clamp(-5, 0, 10) // 0 * clamp(15, 0, 10) // 10 * ``` */ declare function clamp(value: number, min?: number, max?: number): number; /** * Creates an array of sequential numbers * * @param length The length of the array to create * @param start The starting index (default: 0) * @returns An array of sequential numbers * * @example * ```ts * range(3) // [0, 1, 2] * range(3, 1) // [1, 2, 3] * range(5, 10) // [10, 11, 12, 13, 14] * range(0) // [] * ``` */ declare function range(length: number, start?: number): number[]; /** * Parses a CSS pixel length into a number * * @param value The resolved CSS length, e.g. `getComputedStyle(el).marginLeft` * @param fallback The value to return when `value` does not parse (default: 0) * @returns The parsed number, or `fallback` * * @remarks * Built for reading `getComputedStyle` output, where a length that does not * apply resolves to `''` or `'auto'` rather than to a number. An unparseable * length returns `fallback`; a length that legitimately parses to `0` returns * `0`. That distinction is why this exists — `Number.parseFloat(v) || 0` * collapses both cases onto `0`, which is only correct when the fallback is * itself `0`. * * Only the leading number is read, matching `Number.parseFloat`, so any unit * suffix is ignored. Values `getComputedStyle` never returns — percentages, * `calc()` expressions, multi-value shorthands — are out of scope. * * @example * ```ts * pxToNumber('16px') // 16 * pxToNumber('0px') // 0 * pxToNumber('-4.5px') // -4.5 * pxToNumber('auto') // 0 * pxToNumber(undefined) // 0 * * // A non-zero fallback is the case `|| 0` cannot express * pxToNumber('auto', 100) // 100 * pxToNumber('0px', 100) // 0 * ``` */ declare function pxToNumber(value: string | undefined, fallback?: number): number; /** * Resolves an iterable of IDs to their items via a getter, * filtering out any that return undefined. * * @internal */ declare function resolveIds(ids: Iterable, getter: (id: ID) => E | undefined): E[]; /** * Extracts defined index values from an iterable of items. * * @internal */ declare function resolveIndexes(items: Iterable<{ index?: number; }>): number[]; //#endregion export { UNSAFE_KEYS, clamp, getActiveElement, isArray, isBoolean, isElement, isFunction, isNaN, isNull, isNullOrUndefined, isNumber, isObject, isPrimitive, isString, isSymbol, isThenable, isUndefined, mergeDeep, pxToNumber, range, resolveIds, resolveIndexes, useId };