UNPKG

nhb-toolbox

Version:

A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.

110 lines (109 loc) 4.67 kB
import type { GenericObject } from '../object/types'; import type { AsyncFunction, GenericFn, Maybe, ValidArray } from '../types/index'; /** * * Type guard to check if a value is an array. * @param value - The value to check. * @returns `true` if the value is an array, otherwise `false`. */ export declare function isArray<T>(value: unknown): value is Array<T>; /** * * Type guard to check if a value is an array with length. * @param value - The value to check. * @returns `true` if the value is an array with length, otherwise `false`. */ export declare function isValidArray<T>(value: unknown): value is Array<T>; /** * * Type guard to check if a value is an object (excluding null). * @param value - The value to check. * @returns `true` if the value is an object, otherwise `false`. */ export declare function isObject(value: unknown): value is GenericObject; /** * * Type guard to check if a value is an object (excluding null) and has keys in it. * @param value - The value to check. * @returns `true` if the value is an object with valid keys, otherwise `false`. */ export declare function isNotEmptyObject(value: unknown): value is GenericObject; /** * * Type guard to check if a value is an object with specific keys. * @param value - The value to check. * @param keys - The list of keys the object should contain. * @returns `true` if the value is an object with the specified keys, otherwise `false`. */ export declare function isObjectWithKeys<Key extends string>(value: unknown, keys: ValidArray<Key>): value is { [K in Key]: unknown; }; /** * * Type guard to check if a value is an empty object. * @param value - The value to check. * @returns `true` if the value is an empty object, otherwise `false`. */ export declare function isEmptyObject<T extends GenericObject>(value: T): boolean; /** * * Type guard to check if a value is a function. * @param value - The value to check. * @returns `true` if the value is a function, otherwise `false`. */ export declare function isFunction(value: unknown): value is GenericFn; /** * * Determines whether the provided property descriptor represents a method. * * @param descriptor - The property descriptor to check. * @returns `true` if the descriptor is defined and its value is a function; otherwise, `false`. */ export declare const isMethodDescriptor: (descriptor: Maybe<PropertyDescriptor>) => boolean; /** * * Type guard to check 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 function isDate(value: unknown): value is Date; /** * * Type guard to check if a value is an array of a specific type. * @param value - The value to check. * @param typeCheck - The type guard function to check each item of the array. * @returns `true` if the value is an array of the specified type, otherwise `false`. */ export declare function isArrayOfType<T>(value: unknown, typeCheck: (item: unknown) => item is T): value is T[]; /** * * Type guard to check if a value is a Promise. * @param value - The value to check. * @returns `true` if the value is a Promise, otherwise `false`. */ export declare function isPromise<T>(value: unknown): value is Promise<T>; /** * * Type guard to check if a value is a Set. * @param value - The value to check. * @returns `true` if the value is a Set, otherwise `false`. */ export declare function isSet<T>(value: unknown): value is Set<T>; /** * * Type guard to check if a value is a Map. * @param value - The value to check. * @returns `true` if the value is a Map, otherwise `false`. */ export declare function isMap<K, V>(value: unknown): value is Map<K, V>; /** * * Type guard to check if a value is a RegExp. * @param value - The value to check. * @returns `true` if the value is a RegExp, otherwise `false`. */ export declare function isRegExp(value: unknown): value is RegExp; /** * * Type guard to check if a value is an Error object. * @param value - The value to check. * @returns `true` if the value is an Error object, otherwise `false`. */ export declare function isError(value: unknown): value is Error; /** * * Type guard to check if a string is valid JSON. * @param value - The value to check. * @returns `true` if the value is valid JSON, otherwise `false`. */ export declare function isJSON(value: unknown): value is string; /** * * Type guard to check if a function returns a Promise. * @param fn - The function to check. * @returns `true` if the function returns a Promise, otherwise `false`. */ export declare function isReturningPromise<T>(fn: unknown): fn is AsyncFunction<T>;