UNPKG

@hgargg-0710/one

Version:

A tiny npm library purposed for providing beautiful solutions to frequent miniature (one-line/one-expression) tasks for various JS datatypes.

81 lines (80 loc) 2.36 kB
/** * Type for signifying one-variable type predicates */ export type TypePredicate<Type = any> = (x?: any) => x is Type; /** * A type of all the items `x`, such that `!x` is truthy */ export type Falsy = false | 0 | "" | null | undefined; /** * Returns whether a given `x` is a number primitive */ export declare const isNumber: (x: any) => x is number; /** * Returns whether `x` is a function */ export declare const isFunction: (x: any) => x is Function; /** * Returns whether `x` is a string primitive */ export declare const isString: (x: any) => x is string; /** * Returns whether `x` is a boolean primitive */ export declare const isBoolean: (x: any) => x is boolean; /** * Returns whether `x` is a symbol primitive */ export declare const isSymbol: (x: any) => x is symbol; /** * Returns whether `x` is an object */ export declare const isObject: <Type extends object = object>(x: any) => x is Type; /** * Returns whether `x` is `null` */ export declare const isNull: (x: any) => x is null; /** * Returns whether `x` is `undefined` */ export declare const isUndefined: (x: any) => x is undefined; /** * Returns whether `x == null` */ export declare const isNullary: (x: any) => x is undefined | null; /** * Returns `typeof x` */ export declare const typeOf: (x: any) => "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"; /** * Returns whether `x` is an `Array` */ export declare const isArray: <Type = any>(x: any) => x is Type[]; /** * Returns whether `x` is a `Set` */ export declare const isSet: <Type = any>(x: any) => x is Set<Type>; /** * Returns whether `x` is a `Map` */ export declare const isMap: <KType = any, VType = any>(x: any) => x is Map<KType, VType>; /** * Returns a bool indicating whether it is possible to call `Number(x)` without: * * 1. getting `NaN` * 2. getting an error (this happens if `x` is a symbol) * 3. `x` being an empty string */ export declare function isNumberConvertible(x: any): boolean; /** * Returns whether `x` is a truthy value */ export declare const isTruthy: (x: any) => boolean; /** * Checks whether the given `x` is `Falsy` */ export declare const isFalsy: (x: any) => x is Falsy; /** * Returns either `x` if it's a non-`null` object, or `false`, if it isn't */ export declare const isStruct: (x: any) => false | object;