Guards
Various TypeScript guards.
isArray
function isArray<A>(value: A | ReadonlyArray<unknown>): value is GuardArray<A>
G.isArray([1, 2, 3]) // → true
pipe(['hello', 'world'], G.isArray) // → true
isBoolean
function isBoolean<A>(value: A | boolean): value is GuardValue<A, boolean>
G.isBoolean(false) // → true
pipe(true, G.isBoolean) // → true
isDate
function isDate<A>(value: A): value is Extract<A, Date>
G.isDate(new Date()) // → true
pipe(new Date(), G.isDate) // → true
isError
function isError<A>(value: A | Error): value is GuardValue<A, Error>
G.isError(new Error('oops!')) // → true
pipe(new Error('oops!'), G.isError) // → true
isFunction
function isFunction<A>(value: A | Function): value is GuardValue<A, Function>
G.isFunction(F.ignore) // → true
pipe(F.ignore, G.isFunction) // → true
isNot
function isNot<A, B extends A>(value: A, predicateFn: (value: A) => value is B): value is Exclude<A, B>
function isNot<A, B extends A>(predicateFn: (value: A) => value is B): (value: A) => value is Exclude<A, B>
function isNot<A>(value: A, predicateFn: (value: A) => any): boolean
function isNot<A>(predicateFn: (value: A) => any): (value: A) => boolean
// ⬇️ const isNotString = G.isNot(G.isString)
isNotString(0) // → true
pipe('ts-belt', G.isNot(G.isString)) // → false
isNotNullable
function isNotNullable<A>(value: A): value is NonNullable<A>
G.isNotNullable('ts-belt') // → true
G.isNotNullable(null) // → false
pipe(0, G.isNotNullable) // → true
pipe(undefined, G.isNotNullable) // → false
isNull
function isNull<A>(value: A | null | undefined): value is null
G.isNull(null) // → true
pipe(null, G.isNull) // → true
isNullable
function isNullable<A>(value: A): value is Extract<A, null | undefined>
G.isNullable(null) // → true
pipe(undefined, G.isNullable) // → true
isNumber
function isNumber<A>(value: A | number): value is GuardValue<A, number>
G.isNumber(3) // → true
pipe(3, G.isNumber) // → true
isObject
function isObject<A>(value: A | object): value is GuardObject<A>
G.isObject({}) // → true
pipe({}, G.isObject) // → true
isPromise
function isPromise<A>(value: A | Promise<unknown>): value is GuardPromise<A>
G.isPromise(Promise.resolve(1)) // → true
pipe(Promise.resolve(1), G.isPromise) // → true
isString
function isString<A>(value: A | string): value is GuardValue<A, string>
G.isString('ts') // → true
pipe('belt', G.isString) // → true
isUndefined
function isUndefined<A>(value: A | null | undefined): value is undefined
G.isUndefined(undefined) // → true
pipe(undefined, G.isUndefined) // → true