UNPKG

@react-hive/honey-utils

Version:

A lightweight TypeScript utility library providing a collection of helper functions for common programming tasks

206 lines (205 loc) 5.63 kB
export declare function assert(condition: any, message: string): asserts condition; /** * Checks if a value is null. * * @param value - The value to check. * * @returns `true` if the value is null; otherwise, `false`. */ export declare const isNull: (value: unknown) => value is null; /** * Checks if a value is null or undefined. * * @param value - The value to check. * * @returns `true` if the value is `null` or `undefined`, otherwise `false`. */ export declare const isNil: (value: unknown) => value is null | undefined; /** * Checks if a value is neither `null` nor `undefined`. * * @param value - The value to check. * * @returns `true` if the value is defined (not `null` or `undefined`); otherwise, `false`. */ export declare const isDefined: <T>(value: T) => value is NonNullable<T>; /** * Checks if a value is undefined. * * @param value - The value to check. * * @returns `true` if the value is undefined; otherwise, `false`. */ export declare const isUndefined: (value: unknown) => value is undefined; /** * Checks if a value is a number. * * @param value - The value to check. * * @returns `true` if the value is a number; otherwise, `false`. */ export declare const isNumber: (value: unknown) => value is number; /** * Checks if a value is a boolean. * * @param value - The value to check. * * @returns `true` if the value is a boolean; otherwise, `false`. */ export declare const isBool: (value: unknown) => value is boolean; /** * Checks if a value is an object. * * @param value - The value to check. * * @returns `true` if the value is an object; otherwise, `false`. */ export declare const isObject: (value: unknown) => value is object; /** * Checks if a value is an empty object (no own enumerable properties). * * @param value - The value to check. * * @returns `true` if the value is an empty object; otherwise, `false`. */ export declare const isEmptyObject: (value: unknown) => value is Record<string, never>; /** * Checks if a value is a Date object. * * @param value - The value to check. * * @returns `true` if the value is a Date object; otherwise, `false`. */ export declare const isDate: (value: unknown) => value is Date; /** * Checks if a value is a `Blob`. * * @param value - The value to check. * * @returns `true` if the value is a Blob object; otherwise, `false`. */ export declare const isBlob: (value: unknown) => value is Blob; /** * Checks if a value is an `Error` object. * * @param value - The value to check. * * @returns `true` if the value is an Error instance; otherwise, `false`. */ export declare const isError: (value: unknown) => value is Error; /** * Checks if a value is a valid Date object (not Invalid Date). * * @param value - The value to check. * * @returns `true` if the value is a valid Date object; otherwise, `false`. */ export declare const isValidDate: (value: unknown) => value is Date; /** * Checks if a value is a RegExp object. * * @param value - The value to check. * * @returns `true` if the value is a RegExp object; otherwise, `false`. */ export declare const isRegExp: (value: unknown) => value is RegExp; /** * Checks if a value is a Map. * * @param value - The value to check. * * @returns `true` if the value is a Map; otherwise, `false`. */ export declare const isMap: (value: unknown) => value is Map<unknown, unknown>; /** * Checks if a value is a Set. * * @param value - The value to check. * * @returns `true` if the value is a Set; otherwise, `false`. */ export declare const isSet: (value: unknown) => value is Set<unknown>; /** * Checks if a value is a Symbol. * * @param value - The value to check. * * @returns `true` if the value is a Symbol; otherwise, `false`. */ export declare const isSymbol: (value: unknown) => value is symbol; /** * Checks if a value is a finite number. * * A finite number is a number that is not `NaN`, `Infinity`, or `-Infinity`. * * @param value - The value to check. * * @returns `true` if the value is a finite number; otherwise, `false`. * * @example * ```ts * isFiniteNumber(10); // true * isFiniteNumber(3.14); // true * isFiniteNumber(-5); // true * ``` * * @example * ```ts * isFiniteNumber(NaN); // false * isFiniteNumber(Infinity); // false * isFiniteNumber(-Infinity); // false * ``` * * @example * ```ts * isFiniteNumber('10'); // false * isFiniteNumber(null); // false * isFiniteNumber(undefined); // false * ``` */ export declare const isFiniteNumber: (value: unknown) => value is number; /** * Checks if a value is an integer. * * @param value - The value to check. * * @returns `true` if the value is an integer; otherwise, `false`. */ export declare const isInteger: (value: unknown) => value is number; /** * Checks if a value is a decimal number (finite and non-integer). * * A decimal number is a finite number that has a fractional part (i.e. not an integer). * * @param value - The value to check. * * @returns `true` if the value is a decimal number; otherwise, `false`. * * @example * ```ts * isDecimal(1.5); // true * isDecimal(-0.25); // true * isDecimal(0.1); // true * ``` * * @example * ```ts * isDecimal(1); // false * isDecimal(0); // false * isDecimal(-10); // false * ``` * * @example * ```ts * isDecimal(NaN); // false * isDecimal(Infinity); // false * ``` * * @example * ```ts * isDecimal('1.5'); // false * isDecimal(null); // false * isDecimal(undefined); // false * ``` */ export declare const isDecimal: (value: unknown) => value is number;