Overview
Type Predicate
Table of contents
- PredicateOption (interface)
- isArguments (constant)
- getTypeName (function)
- isArray (function)
- isArrayLike (function)
- isBoolean (function)
- isDate (function)
- isEmpty (function)
- isEmptyArray (function)
- isEmptyRecord (function)
- isError (function)
- isFinite (function)
- isFunction (function)
- isInteger (function)
- isIterable (function)
- isIterator (function)
- isMaybe (function)
- isNaN (function)
- isNull (function)
- isNumber (function)
- isObject (function)
- isRegExp (function)
- isSameType (function)
- isString (function)
- isSymbol (function)
- isTypeName (function)
- isUndefined (function)
- notEmpty (function)
- notEmptyArray (function)
- notEmptyRecord (function)
- notMaybe (function)
- Predicate (export)
PredicateOption (interface)
Signature
interface PredicateOption {}
isArguments (constant)
Determines whether the passed value is Argument.
Signature
export const isArguments: Refinement<unknown, unknown> = ...
Added in v0.2.0
getTypeName (function)
get type name
Signature
export const getTypeName = (value: unknown): string => ...
Example
import { getTypeName } from 'macoolka-predicate'
assert(getTypeName({}) === 'Object')
Added in v0.2.0
isArray (function)
Determines whether the passed value is Array.
Signature
export const isArray = <T>(a: unknown): a is Array<T> => ...
Example
import { isArray } from 'macoolka-predicate'
assert(isArray([]))
assert(!isArray({}))
Added in v0.2.0
isArrayLike (function)
Determines whether the passed value is ArrayLike.
Signature
export const isArrayLike = (value: any) => ...
Example
import { isArrayLike } from 'macoolka-predicate'
assert(isArrayLike([]))
assert(isArrayLike({ length: 8 }))
assert(!isArrayLike({}))
Added in v0.2.0
isBoolean (function)
Determines whether the passed value is Boolean.
Signature
export const isBoolean: Refinement<unknown, boolean> =
(a: unknown): a is boolean => ...
Example
import { isBoolean } from 'macoolka-predicate'
assert(isBoolean(true))
assert(!isBoolean(1))
Added in v0.2.0
isDate (function)
Determines whether the passed value is Date.
Signature
export const isDate: Refinement<unknown, Date> = (a: unknown): a is Date => ...
Example
import { isDate } from 'macoolka-predicate'
assert(isDate(new Date()))
assert(!isDate('a'))
Added in v0.2.0
isEmpty (function)
Determines whether the passed value is Empty.
Example
import { isEmpty } from 'macoolka-predicate'
assert(isEmpty(''))
assert(isEmpty(undefined))
assert(isEmpty(null))
assert(isEmpty({}))
assert(isEmpty([]))
assert(!isEmpty(['1']))
assert(!isEmpty({ a: 1 }))
Added in v0.2.0
isEmptyArray (function)
Determines whether the passed value is Empty Array.
Signature
export const isEmptyArray = (val: unknown): boolean => ...
Example
import { isEmptyArray } from 'macoolka-predicate'
assert(isEmptyArray([]))
assert(isEmptyArray(undefined))
assert(isEmptyArray(null))
assert(!isEmptyArray(['1']))
Added in v0.2.0
isEmptyRecord (function)
Determines whether the passed value is Empty Record.
Signature
export const isEmptyRecord = (val: unknown): boolean => ...
Example
import { isEmptyRecord } from 'macoolka-predicate'
assert(isEmptyRecord({}))
assert(isEmptyRecord(undefined))
assert(isEmptyRecord(null))
assert(!isEmptyRecord({ a: 1 }))
Added in v0.2.0
isError (function)
Determines whether the passed value is Error.
Signature
export const isError: Refinement<unknown, Error> =
(a: unknown): a is Error => ...
Example
import { isError } from 'macoolka-predicate'
assert(isError(new Error('')))
assert(!isError(''))
Added in v0.2.0
isFinite (function)
Determines whether the passed value is Finite.
Signature
export const isFinite: Predicate<unknown> = (val) => ...
Example
import { isFinite } from 'macoolka-predicate'
assert(isFinite(Number.MAX_VALUE))
assert(isFinite(Number.MIN_VALUE))
assert(isFinite('1'))
assert(!isFinite('a'))
Added in v0.2.0
isFunction (function)
Determines whether the passed value is Function.
Signature
export const isFunction: Refinement<unknown, Function> =
(a: unknown): a is Function => ...
Example
import { isFunction } from 'macoolka-predicate'
assert(isFunction(() => void 0))
assert(!isFunction(1))
Added in v0.2.0
isInteger (function)
Determines whether the passed value is Integer.
Signature
export const isInteger: Predicate<unknown> = (val: unknown) => ...
Example
import { isInteger } from 'macoolka-predicate'
assert(isInteger(1))
assert(!isInteger(1.1))
Added in v0.2.0
isIterable (function)
Determines whether the passed value is Iterable.
Signature
export const isIterable: Refinement<unknown, Iterable<unknown>> =
(a: unknown): a is Iterable<unknown> => ...
Example
import { isIterable } from 'macoolka-predicate'
assert(isIterable([]))
assert(!isIterable({}))
Added in v0.2.0
isIterator (function)
Determines whether the passed value is Iterator.
Signature
export const isIterator: Refinement<any, Iterator<unknown>> =
<T>(a: any): a is Iterator<T> => ...
Example
import { isIterator } from 'macoolka-predicate'
assert(isIterator({ next: () => void 0 }))
assert(!isIterator({}))
Added in v0.2.0
isMaybe (function)
Determines whether the passed value is null or undefined.
Example
import { isMaybe } from 'macoolka-predicate'
import * as assert from 'assert'
assert(isMaybe(undefined))
assert(isMaybe(null))
assert(!isMaybe(''))
Added in v0.2.0
isNaN (function)
Determines whether the passed value is NaN.
Signature
export const isNaN = (val: unknown) => ...
Example
import { isNaN } from 'macoolka-predicate'
assert(isNaN('a'))
assert(!isNaN(1))
Added in v0.2.0
isNull (function)
Determines whether the passed value is null.
Signature
export const isNull = <T>(val: T | null): val is null => ...
Example
import { isNull } from 'macoolka-predicate'
import * as assert from 'assert'
assert(isNull(null))
assert(!isNull(undefined))
Added in v0.2.0
isNumber (function)
Determines whether the passed value is number.
Signature
export const isNumber: Refinement<unknown, number> = (a: unknown): a is number => ...
Example
import { isObject } from 'macoolka-predicate'
assert(isNumber(1))
assert(!isNumber('1'))
Added in v0.2.0
isObject (function)
Determines whether the passed value is a object.
Signature
export const isObject = (a: unknown): a is object => ...
Example
import { isObject } from 'macoolka-predicate'
assert(isObject({}))
assert(isObject({ a: 1 }))
assert(!isObject(2))
Added in v0.2.0
isRegExp (function)
Determines whether the passed value is a RegExp.
Signature
export const isRegExp: Refinement<unknown, RegExp> = (a): a is RegExp => ...
Example
import { isRegExp } from 'macoolka-predicate'
assert(isRegExp(/^a/))
assert(!isRegExp(1))
Added in v0.2.0
isSameType (function)
Determines whether the passed value is same type
Signature
export const isSameType = (a: unknown, b: unknown) => ...
Example
import { isString } from 'macoolka-predicate'
assert(isSameType('a', '3'))
assert(isSameType({ a: 1 }, { b: 2 }))
assert(!isSameType('a', { b: 2 }))
assert(!isSameType(1, false))
Added in v0.2.0
isString (function)
Determines whether the passed value is a string
Signature
export const isString: Refinement<unknown, string> = (a: unknown): a is string => ...
Example
import { isString } from 'macoolka-predicate'
assert(isString('a'))
assert(!isString(1))
Added in v0.2.0
isSymbol (function)
Determines whether the passed value is symbol.
Signature
export const isSymbol: Refinement<unknown, symbol> =
(a: unknown): a is symbol => ...
Example
import { isSymbol } from 'macoolka-predicate'
const a = Symbol('A')
assert(isSymbol(a))
assert(!isSymbol('b'))
Added in v0.2.0
isTypeName (function)
Determines whether the passed value is given typen name.
Signature
export const isTypeName = <T>(strTypeName: string): Refinement<unknown, T> =>
(a: unknown): a is T => ...
Example
import { isTypeName } from 'macoolka-predicate'
assert(isTypeName('Object')({}))
Added in v0.2.0
isUndefined (function)
Determines whether the passed value is a undefined .
Signature
export const isUndefined: Refinement<unknown, undefined> = (val): val is undefined => ...
Example
import { isUndefined } from 'macoolka-predicate'
import * as assert from 'assert'
assert(isUndefined(undefined))
assert(!isUndefined(null))
Added in v0.2.0
notEmpty (function)
Determines whether the passed value is non Empty.
Example
import { notEmpty } from 'macoolka-predicate'
assert(!notEmpty(''))
assert(!notEmpty(undefined))
assert(!notEmpty(null))
assert(!notEmpty({}))
assert(!notEmpty([]))
assert(notEmpty(['1']))
assert(notEmpty({ a: 1 }))
Added in v0.2.0
notEmptyArray (function)
Determines whether the passed value is Non Empty Array.
Signature
export const notEmptyArray = <T>(val: unknown): val is NonEmptyArray<T> => ...
Example
import { notEmptyArray } from 'macoolka-predicate'
assert(!notEmptyArray([]))
assert(!notEmptyArray(undefined))
assert(!notEmptyArray(null))
assert(notEmptyArray(['1']))
Added in v0.2.0
notEmptyRecord (function)
Determines whether the passed value is Non Empty Record.
Signature
export const notEmptyRecord = <T>(val: Maybe<T>): val is AtLeastOne<T> => ...
Example
import { notEmptyRecord } from 'macoolka-predicate'
assert(!notEmptyRecord({}))
assert(!notEmptyRecord(undefined))
assert(!notEmptyRecord(null))
assert(notEmptyRecord({ a: 1 }))
Added in v0.2.0
notMaybe (function)
Determines whether the passed value is not null or undefined.
Example
import { notMaybe } from 'macoolka-predicate'
import * as assert from 'assert'
assert(!notMaybe(undefined))
assert(!notMaybe(null))
assert(notMaybe(''))
Added in v0.2.0
Predicate (export)
Signature
any