guardz
Version:
A simple and lightweight TypeScript type guard library for runtime type validation.
29 lines (28 loc) • 855 B
TypeScript
import type { TypeGuardFn } from './isType';
/**
* Checks if a value is null or undefined (nil).
*
* @param value - The value to check
* @param config - Optional configuration for error handling
* @returns True if the value is null or undefined, false otherwise
*
* @example
* ```typescript
* import { isNil } from 'guardz';
*
* console.log(isNil(null)); // true
* console.log(isNil(undefined)); // true
* console.log(isNil("")); // false
* console.log(isNil(0)); // false
* console.log(isNil(false)); // false
* console.log(isNil({})); // false
*
* // Useful for checking if a value needs initialization
* const data: unknown = getUserInput();
* if (isNil(data)) {
* // data is now typed as null | undefined
* console.log("Value is null or undefined");
* }
* ```
*/
export declare const isNil: TypeGuardFn<null | undefined>;