import { FalsyValues, AnyFunction, AnyObject } from 'yummies/types'; /** * ---header-docs-section--- * # yummies/type-guard * * ## Description * * Runtime **type guards** and narrowers for primitives, DOM nodes, `NaN`, and common app values. * Each helper is implemented once with consistent `typeof` / `Object.prototype.toString` logic so * `unknown` from JSON, events, or third-party scripts becomes safe typed branches without ad-hoc * checks scattered through the codebase. * * ## Usage * * ```ts * import { typeGuard } from "yummies/type-guard"; * ``` */ /** * Checks that a value is neither `null` nor `undefined`. * * @template T Value type without nullish branches. * @param value Value to test. * @returns `true` when the value is defined. * * @example * ```ts * isDefined(0); // true * ``` * * @example * ```ts * isDefined(null); // false * ``` */ declare const isDefined: (value: T | undefined | null) => value is T; /** * Checks whether a value is truthy (`!!value`). * * @param value Value to test. * @returns `true` when `!!value` is true. * * @example * ```ts * isTruthy(1); // true * ``` * * @example * ```ts * isTruthy(0); // false * ``` */ declare const isTruthy: (value: T) => value is Exclude; /** * Checks whether a value is falsy (`!Boolean(value)`). * * @param value Value to test. * @returns `true` when `Boolean(value)` is false. * * @example * ```ts * isFalsy(null); // true * ``` * * @example * ```ts * isFalsy("x"); // false * ``` */ declare const isFalsy: (value: T) => value is Extract; /** * Checks whether a value is exactly `null`. * * @param value Value to test. * @returns `true` when the value is `null`. * * @example * ```ts * isNull(null); // true * ``` * * @example * ```ts * isNull(undefined); // false * ``` */ declare const isNull: (value: unknown) => value is null; /** * Checks whether a value is exactly `undefined`. * * @param value Value to test. * @returns `true` when the value is `undefined`. * * @example * ```ts * isUndefined(undefined); // true * ``` * * @example * ```ts * isUndefined('value'); // false * ``` */ declare const isUndefined: (value: unknown) => value is undefined; /** * Checks whether a value is a plain object. * * @param value Value to test. * @returns `true` when the value matches `[object Object]`. * * @example * ```ts * isObject({ id: 1 }); // true * ``` * * @example * ```ts * isObject([]); // false * ``` */ declare const isObject: (value: unknown) => value is AnyObject; /** * Checks whether a value is object-like: non-null and `typeof value === 'object'`. * * This includes plain objects, arrays, `Date`, `RegExp`, boxed primitives, and other built-ins * whose `typeof` is `"object"`. It is broader than `isObject`, which only matches plain objects. * * @template T Input value type. * @param value Value to test. * @returns `true` when the value is a non-null object. * * @example * ```ts * isObjectLike({ a: 1 }); // true * ``` * * @example * ```ts * isObjectLike([]); // true * ``` * * @example * ```ts * isObjectLike(new Date()); // true * ``` * * @example * ```ts * isObjectLike(null); // false * ``` * * @example * ```ts * isObjectLike(() => {}); // false * ``` */ declare const isObjectLike: (value: unknown) => value is T extends never ? Extract : T; /** * Checks whether a value is an array. * * @param value Value to test. * @returns `true` when the value is an array. * * @example * ```ts * isArray([1, 2, 3]); // true * ``` * * @example * ```ts * isArray({ length: 1 }); // false * ``` */ declare const isArray: (value: unknown) => value is unknown[]; /** * Checks whether a value is a string object or primitive string. * * @param value Value to test. * @returns `true` when the value is a string. * * @example * ```ts * isString('hello'); // true * ``` * * @example * ```ts * isString(123); // false * ``` */ declare const isString: (value: unknown) => value is string; /** * Checks whether a value is a finite number. * * Unlike `isNaN` and `isInfinite`, this guard only matches regular numeric values. * * @param value Value to test. * @returns `true` when the value is a non-NaN finite number. * * @example * ```ts * isNumber(123); // true * ``` * * @example * ```ts * isNumber(Number.NaN); // false * ``` */ declare const isNumber: (value: unknown) => value is number; /** * Checks whether a value is a boolean. * * @param value Value to test. * @returns `true` when the value is a boolean. * * @example * ```ts * isBoolean(true); // true * ``` * * @example * ```ts * isBoolean('true'); // false * ``` */ declare const isBoolean: (value: unknown) => value is boolean; /** * Checks whether a value is a synchronous or asynchronous function. * * @param value Value to test. * @returns `true` when the value is a function. * * @example * ```ts * isFunction(() => {}); // true * ``` * * @example * ```ts * isFunction(async () => {}); // true * ``` */ declare const isFunction: (value: unknown) => value is AnyFunction; /** * Checks whether a value is a regular expression. * * @param value Value to test. * @returns `true` when the value is a `RegExp`. * * @example * ```ts * isRegExp(/foo/); // true * ``` * * @example * ```ts * isRegExp('foo'); // false * ``` */ declare const isRegExp: (value: unknown) => value is RegExp; /** * Checks whether a value looks like a DOM element or document node. * * @param value Value to test. * @returns `true` when the value has an element-like node type. * * @example * ```ts * isElement(document.body); // true * ``` * * @example * ```ts * isElement({ nodeType: 3 }); // false * ``` */ declare const isElement: (value: unknown) => value is HTMLElement; /** * Checks whether a value is `NaN`. * * @param value Value to test. * @returns `true` when the value is `NaN`. * * @example * ```ts * isNaN(Number.NaN); // true * ``` * * @example * ```ts * isNaN(5); // false * ``` */ declare const isNaN: (value: unknown) => boolean; /** * Checks whether a value is positive or negative infinity. * * @param value Value to test. * @returns `true` when the value is not finite. * * @example * ```ts * isInfinite(Infinity); // true * ``` * * @example * ```ts * isInfinite(10); // false * ``` */ declare const isInfinite: (value: unknown) => boolean; /** * Checks whether a value is a symbol. * * @param value Value to test. * @returns `true` when the value is a symbol. * * @example * ```ts * isSymbol(Symbol('id')); // true * ``` * * @example * ```ts * isSymbol('id'); // false * ``` */ declare const isSymbol: (value: unknown) => value is symbol; declare const _exports_isArray: typeof isArray; declare const _exports_isBoolean: typeof isBoolean; declare const _exports_isDefined: typeof isDefined; declare const _exports_isElement: typeof isElement; declare const _exports_isFalsy: typeof isFalsy; declare const _exports_isFunction: typeof isFunction; declare const _exports_isInfinite: typeof isInfinite; declare const _exports_isNaN: typeof isNaN; declare const _exports_isNull: typeof isNull; declare const _exports_isNumber: typeof isNumber; declare const _exports_isObject: typeof isObject; declare const _exports_isObjectLike: typeof isObjectLike; declare const _exports_isRegExp: typeof isRegExp; declare const _exports_isString: typeof isString; declare const _exports_isSymbol: typeof isSymbol; declare const _exports_isTruthy: typeof isTruthy; declare const _exports_isUndefined: typeof isUndefined; declare namespace _exports { export { _exports_isArray as isArray, _exports_isBoolean as isBoolean, _exports_isDefined as isDefined, _exports_isElement as isElement, _exports_isFalsy as isFalsy, _exports_isFunction as isFunction, _exports_isInfinite as isInfinite, _exports_isNaN as isNaN, _exports_isNull as isNull, _exports_isNumber as isNumber, _exports_isObject as isObject, _exports_isObjectLike as isObjectLike, _exports_isRegExp as isRegExp, _exports_isString as isString, _exports_isSymbol as isSymbol, _exports_isTruthy as isTruthy, _exports_isUndefined as isUndefined, }; } export { _exports as typeGuard };