UNPKG

typedash

Version:

modern, type-safe collection of utility functions

107 lines (103 loc) 2.93 kB
import { IsEqual, EmptyObject as EmptyObject$1 } from 'type-fest'; import { M as Maybe } from './Maybe-D6dwMjD9.cjs'; /** * Represents an empty object, either with or without properties. */ type EmptyObject<T extends object = never> = IsEqual<T, never> extends true ? EmptyObject$1 : KeyedEmptyObject<T>; /** * Represents an empty object with keys from another object. * @example * ```ts * type A = KeyedEmptyObject<{ a: string; b: number }>; * // type A = { a?: never; b?: never } * ``` */ type KeyedEmptyObject<T extends object> = { [K in keyof T]?: never; }; /** * Returns whether the input value is empty. * @param value The value to check. * @returns Whether the input value is empty. * @example * ```ts * isEmpty('') // true * isEmpty('abc') // false * ``` */ declare function isEmpty(value: string): value is ''; /** * Returns whether the input value is empty. * @param value The value to check. * @returns Whether the input value is empty. * @example * ```ts * isEmpty(0) // true * isEmpty(1) // false * ``` */ declare function isEmpty(value: number): value is number; /** * Returns whether the input value is empty. * @param value The value to check. * @returns Whether the input value is empty. * @example * ```ts * isEmpty(new Map()) // true * isEmpty(new Map([['a', 1]])) // false * * isEmpty(new Set()) // true * isEmpty(new Set([1])) // false * ``` */ declare function isEmpty(value: Maybe<ReadonlyMap<unknown, unknown> | ReadonlySet<unknown>>): boolean; /** * Returns whether the input value is empty. * @param value The value to check. * @returns Whether the input value is empty. * @example * ```ts * isEmpty([]) // true * isEmpty([1]) // false * ``` */ declare function isEmpty<T extends readonly unknown[] | EmptyArray>(value: Maybe<T>): value is Maybe<T & EmptyArray>; /** * Returns whether the input value is empty. * @param value The value to check. * @returns Whether the input value is empty. * @example * ```ts * isEmpty({}) // true * isEmpty({ a: 1 }) // false * ``` */ declare function isEmpty<T extends object>(value: Maybe<EmptyObject<T> | T>): value is T & Record<string, never>; /** * Returns whether the input value is empty. * @param value The value to check. * @returns Whether the input value is empty. * @example * ```ts * isEmpty(null) // true * isEmpty(undefined) // true * isEmpty(0) // true * isEmpty('') // true * isEmpty([]) // true * isEmpty({}) // true * isEmpty(new Map()) // true * isEmpty(new Set()) // true * isEmpty(false) // true * * isEmpty(true) // false * isEmpty(1) // false * isEmpty('abc') // false * isEmpty([1]) // false * isEmpty({ a: 1 }) // false * isEmpty(new Map([['a', 1]])) // false * isEmpty(new Set([1])) // false * ``` */ declare function isEmpty<T>(value: Maybe<T>): boolean; type EmptyArray = []; export { type EmptyObject as E, type KeyedEmptyObject as K, isEmpty as i };