ts-predicate
Version:
TypeScript predicates and assertions library
181 lines (180 loc) • 5.58 kB
TypeScript
import type { ArrayConstraints, ObjectWithNullableProperty, ObjectWithProperty, PopulatedArray, StringConstraints } from "./Types.js";
/**
* TypeGuard
*
* @class
*/
declare class TypeGuard {
/**
* IsPrimitive
*
* @description Predicate that check if a value is primitive. JS primitive values are boolean | number | string | null | undefined.
* @public
* @static
* @param {unknown} value the value
* @return {boolean} a boolean
*/
static IsPrimitive(value: unknown): value is boolean | number | string | null | undefined;
/**
* IsDefined
*
* @description Predicate that check if a value is defined. A value defined is not undefined | null | NaN.
* @public
* @static
* @param {unknown} value the value
* @return {boolean} a boolean
*/
static IsDefined<Type>(value: Type): value is NonNullable<Type>;
/**
* IsBoolean
*
* @description Predicate that check if a value is a boolean.
* @public
* @static
* @param {unknown} value the value
* @return {boolean} a boolean
*/
static IsBoolean(value: unknown): value is boolean;
/**
* IsNumber
*
* @description Predicate that check if a value is a number.
* @public
* @static
* @param {unknown} value the value
* @return {boolean} a boolean
*/
static IsNumber(value: unknown): value is number;
/**
* IsInteger
*
* @description Predicate that check if a value is an integer.
* @public
* @static
* @param {unknown} value the value
* @return {boolean} a boolean
*/
static IsInteger(value: unknown): value is number;
/**
* IsFiniteNumber
*
* @description Predicate that check if a value is a finite number.
* @public
* @static
* @param {unknown} value the value
* @return {boolean} a boolean
*/
static IsFiniteNumber(value: unknown): value is number;
/**
* IsString
*
* @description Predicate that check if a value is a string.
* @public
* @static
* @param {unknown} value the value
* @param {object} [constraints] some additional check
* @param {number} [constraints.minLength] minimal length
* @param {number} [constraints.maxLength] maximum length
* @return {boolean} a boolean
*/
static IsString(value: unknown, constraints?: StringConstraints): value is string;
/**
* IsFilledString
*
* @description Predicate that check if a value is a non empty string.
* @public
* @static
* @param {unknown} value the value
* @return {boolean} a boolean
*/
static IsFilledString(value: unknown): value is string;
/**
* IsString
*
* @description Predicate that check if a value is a string.
* @public
* @static
* @param {unknown} value the value
* @param {object} [constraints] some additional check
* @param {number} [constraints.minLength] minimal length
* @param {void} [constraints.itemGuard] another predicate
* @return {boolean} a boolean
*/
static IsArray<Type>(value: unknown, constraints?: ArrayConstraints<Type>): value is Array<Type>;
/**
* IsPopulatedArray
*
* @description Predicate that check if a value is a non empty array.
* @public
* @static
* @param {unknown} value the value
* @param {object} [constraints] some additional check
* @param {number} [constraints.minLength] minimal length
* @param {void} [constraints.itemGuard] another predicate
* @return {boolean} a boolean
*/
static IsPopulatedArray<Type>(value: unknown, constraints?: ArrayConstraints<Type>): value is PopulatedArray<Type>;
/**
* IsFunction
*
* @description Predicate that check if a value is a function.
* @public
* @static
* @param {unknown} value the value
* @return {boolean} a boolean
*/
static IsFunction(value: unknown): value is Function;
/**
* IsFunction
*
* @description Predicate that check if a value is callable.
* @public
* @static
* @param {unknown} value the value
* @return {boolean} a boolean
*/
static IsCallable(value: unknown): value is Function;
/**
* IsRecord
*
* @description Predicate that check if a value is a record.
* @public
* @static
* @param {unknown} value the value
* @return {boolean} a boolean
*/
static IsRecord<KeyType extends number | string | symbol = string>(value: unknown): value is Record<KeyType, unknown>;
/**
* IsObject
*
* @description Predicate that check if a value is an object.
* @public
* @static
* @param {unknown} value the value
* @return {boolean} a boolean
*/
static IsObject(value: unknown): value is object;
/**
* HasNullableProperty
*
* @description Predicate that check if an object has a nullable property.
* @public
* @static
* @param {object} value the object
* @param {string} property the property
* @return {boolean} a boolean
*/
static HasNullableProperty<O extends object, K extends string>(value: O, property: K): value is ObjectWithNullableProperty<O, K>;
/**
* HasProperty
*
* @description Predicate that check if an object has a defined property.
* @public
* @static
* @param {object} value the object
* @param {string} property the property
* @return {boolean} a boolean
*/
static HasProperty<O extends object, K extends string>(value: O, property: K): value is ObjectWithProperty<O, K>;
}
export { TypeGuard };