/** * Checks if value is `number`, acts as a typescript safeguard. * * @example * ``` * [1, 'b', 2].filter(isNumber) * > [1, 2] * ``` * @group Guard */ export declare function isNumber(value: T | number): value is number; /** * Checks if value is `boolean`, acts as a typescript safeguard. * * @example * ``` * [true, 'b', false].filter(isBoolean) * > [true, false] * ``` * @group Guard */ export declare function isBoolean(value: T | boolean): value is boolean; /** * Checks if value is `string`, acts as a typescript safeguard. * * @example * ``` * [1, 'b', false].filter(isString) * > ['b'] * ``` * @group Guard */ export declare function isString(value: T | string): value is string; /** * Checks if value is `array`, acts as a typescript safeguard. * * Preserves the readonly/mutable distinction of the narrowed type. * * @example * ``` * [[1], ['b'], false].filter(isArray) * > [[1], ['b']] * ``` * @group Guard */ export declare function isArray(value: T | Array): value is Array; export declare function isArray(value: T | ReadonlyArray): value is ReadonlyArray; /** * Checks if value is instance of `Error`, acts as a typescript safeguard. * * @example * ``` * [new Error('error'), 1, 5].filter(isError) * > [new Error('error')] * * [new Error('error'), 1, 5].filter(isNot(isError)) * > [1, 5] * ``` * @group Guard */ export declare function isError(data: T | Error): data is Error; /** * Checks if value is `undefined`, acts as a typescript safeguard. * * @example * ``` * [null, undefined, 1, 5].filter(isUndefined) * > [undefined] * * [null, undefined, 1, 5].filter(isNot(isUndefined)) * > [null, 1, 5] * ``` * @group Guard */ export declare function isUndefined(value: T | undefined): value is undefined; /** * Checks if value is `null`, acts as a typescript safeguard. * * @example * ``` * [null, undefined, 1, 5].filter(isUndefined) * > [undefined] * * [null, undefined, 1, 5].filter(isNot(isUndefined)) * > [null, 1, 5] * ``` * @group Guard */ export declare function isNull(value: T | null): value is null; /** * Checks if value is not `null` or `undefined`, acts as a typescript safeguard. * * @example * ``` * [null, undefined, 1, 5].filter(isUndefined) * > [null, undefined] * * [null, undefined, 1, 5].filter(isNot(isUndefined)) * > [1, 5] * ``` * @group Guard */ export declare function isNullOrUndefined(value: T | null | undefined): value is null | undefined; /** * Checks if the value is empty. * * Supported types and what counts as empty: * * `null` / `undefined` — empty * * `boolean` — `false` is empty * * `string` — `''` is empty * * `number` — `0` is empty (`NaN` is not) * * `Array` — empty array * * `Set` / `Map` — `.size === 0` * * Plain object — no own enumerable keys * * Anything else — not empty * * @group Guard */ export declare function isEmpty(value: T): boolean; /** * Inverse guard * * @example * ``` * [new Error('Error'), 1, 2].filter(isNot(isError)) * // [1, 2] * ``` * @param guard - guard function * @group Guard */ export declare function isNot(guard: (data: T) => data is S): (data: T) => data is Exclude; /** * Checks if value is plain object, acts as a typescript safeguard. * * @example * ``` * isPlainObject({a: 1}) * // true * * isPlainObject([1]) * // false * ``` * @group Guard */ export declare function isPlainObject>(value: unknown): value is T; /** * Checks if given value is `Error` if it's subclass and then throw it. * * @example * ``` * const value = new Error() * const value2 = assertNotError(value) * // throws error * ``` * @group Guard * @param value any value * @returns `value` if it is not an instance of `Error` * @throws `value` if it is an instance of `Error` */ export declare function assertNotError(value: Error | T): T; /** * Returns original value if it is array or wraps it to array. * * @example * ``` * ensureArray('hello') * // ['hello'] * ensureArray(['hello']) * // ['hello'] * ``` * @group Guard */ export declare function ensureArray(value: T | T[]): T[]; export declare function ensureArray(value: T | ReadonlyArray): ReadonlyArray; /** * Returns `value` if it is instance of error otherwise wraps `value` to new `Error` instance. * * @param value `Error` or other value * @returns `value` if it instance of error `Error` otherwise wraps `value` to new `Error` instance * @group Guard */ export declare function ensureError(value: unknown): Error; /** * Checks if unknown object have provided keys. * * @example * ``` * if (hasKeys(value, ['a', 'b'])) { * console.log(value.a, value.b) * } * ``` * @group Guard */ export declare function hasKeys(obj: T, keys: ReadonlyArray): obj is T extends { [K in Key]: any; } ? Extract<{ [K in Key]: any; }, T> : Extract<{ [K in Key]: unknown; }, T>; /** * Checks if value is `AsyncIterable`, acts as a typescript safeguard. * * @group Guard * @example * ``` * isAsyncIterable((async function* () { yield 5 })()) * // true * isAsyncIterable([1, 2, 3]) * // false * ``` */ export declare function isAsyncIterable(v: unknown): v is AsyncIterable; export declare function toAsyncIterable(iterable: Iterable): AsyncIterable; /** * Checks if value is `Iterable`, acts as a typescript safeguard. * * @group Guard * @example * ``` * isIterable([1, 2, 3]) * // true * isIterable((async function* () { yield 5 })()) * // false * ``` */ export declare function isIterable(v: unknown): v is Iterable; /** * Checks if value is `Promise`, acts as a typescript safeguard. * * Narrows `T | Promise` to `Promise` cleanly in normal usage; works * with `Array.prototype.filter` to extract promises from a mixed array. * * @group Guard * @example * ``` * isPromise(Promise.resolve(5)) // true * isPromise(5) // false * * function check(v: Promise | number) { * if (isPromise(v)) { * // v: Promise * } * } * * const arr: (Promise | number)[] = [...] * arr.filter(isPromise) // Promise[] * ``` */ export declare function isPromise(v: T | Promise): v is Promise; export declare function isSet(v: unknown): v is Set; export declare function isMap(v: unknown): v is Map; /** * Checks if value is a function, acts as a typescript safeguard. * * @group Guard * @example * ``` * isFunction(() => 1) // true * isFunction('abc') // false * ``` */ export declare function isFunction(v: unknown): v is (...args: any[]) => any; /** * Checks if value is a `Date` instance, acts as a typescript safeguard. * * @group Guard * @example * ``` * isDate(new Date()) // true * isDate('2024') // false * ``` */ export declare function isDate(v: unknown): v is Date; /** * Checks if value is a `RegExp`, acts as a typescript safeguard. * * @group Guard * @example * ``` * isRegExp(/abc/) // true * isRegExp('/abc/') // false * ``` */ export declare function isRegExp(v: unknown): v is RegExp; /** * Checks if value is an integer (whole, finite number). * * @group Guard * @example * ``` * isInteger(42) // true * isInteger(1.5) // false * isInteger('42') // false * ``` */ export declare function isInteger(v: unknown): v is number;