typedash
Version:
modern, type-safe collection of utility functions
107 lines (106 loc) • 3.07 kB
TypeScript
import { t as Maybe } from "./Maybe-pvX1mStM.js";
import { EmptyObject, IsEqual } from "type-fest";
//#region src/types/EmptyObject.d.ts
/**
* Represents an empty object, either with or without properties.
*/
type EmptyObject$1<T extends object = never> = IsEqual<T, never> extends true ? EmptyObject : 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 };
//#endregion
//#region src/functions/isEmpty/isEmpty.d.ts
/**
* 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$1<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 = [];
//#endregion
export { IsEqual as i, EmptyObject$1 as n, KeyedEmptyObject as r, isEmpty as t };
//# sourceMappingURL=isEmpty-Dxj_j2q7.d.ts.map