@naturalcycles/js-lib
Version:
Standard library for universal (browser + Node.js) javascript
47 lines (46 loc) • 1.66 kB
TypeScript
import type { AnyObject, FalsyValue, NullishValue, Primitive } from './types.js';
type Nullish<T> = T extends NullishValue ? T : never;
type Truthy<T> = T extends FalsyValue ? never : T;
type Falsy<T> = T extends FalsyValue ? T : never;
export declare const _isNull: <T>(v: T) => v is T extends null ? T : never;
export declare const _isUndefined: <T>(v: T) => v is T extends undefined ? T : never;
export declare const _isNullish: <T>(v: T) => v is Nullish<T>;
export declare const _isNotNullish: <T>(v: T) => v is NonNullable<T>;
/**
* Same as Boolean, but with correct type output.
* Related:
* https://github.com/microsoft/TypeScript/issues/16655
* https://www.karltarvas.com/2021/03/11/typescript-array-filter-boolean.html
*
* @example
*
* [1, 2, undefined].filter(_isTruthy)
* // => [1, 2]
*/
export declare const _isTruthy: <T>(v: T) => v is Truthy<T>;
export declare const _isFalsy: <T>(v: T) => v is Falsy<T>;
/**
* Returns true if item is Object, not null and not Array.
*
* Currently treats RegEx as Object too, e.g _isObject(/some/) === true
*/
export declare function _isObject(obj: any): obj is AnyObject;
export declare function _isPrimitive(v: any): v is Primitive;
export declare function _isEmptyObject(obj: AnyObject): boolean;
export declare function _isNotEmptyObject(obj: AnyObject): boolean;
/**
* Object is considered empty if it's one of:
* undefined
* null
* '' (empty string)
* [] (empty array)
* {} (empty object)
* new Map() (empty Map)
* new Set() (empty Set)
*/
export declare function _isEmpty(obj: any): boolean;
/**
* @see _isEmpty
*/
export declare function _isNotEmpty(obj: any): boolean;
export {};