/** * 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. * * @example * ``` * [[1], ['b'], false].filter(isArray) * > [[1], ['b']] * ``` * @group Guard */ export declare function isArray(value: T | Array | ReadonlyArray): value is Array; /** * 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 an empty. * * Supports following types: * * Object - `false` if object is empty * * Array - `false` if array is empty * * Boolean - `false` if boolean is `false` * * Number - `false` if string is `''` * * Number - `false` if number is `0` * * @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>;