Isntnt is a collection of composable JavaScript runtime type predicates with TypeScript type guard declarations. Supports generics including union and intersection types.
Generics
above
const isAboveZero = above(0)
and
const isBetween0And21 = and(above(0), below(21))
array
const isAnyArray = array(isAny)
at
const isAnyAtFoo = at('foo', isAny)
below
const isBelow21 = below(21)
either
const isFooOrBar = either('foo', 'bar')
has
const hasFoo = has('foo')
instance
const isInstanceofString = instance(String)
literal
const is42 = literal(42)
max
const isMax255 = max(255)
min
const isMin18 = min(18)
noneable
const isNoneableString = noneable(isString)
nullable
const isNullableString = nullable(isString)
object
const isEnum = object(isNumber)
optional
const isOptionalString = optional(isString)
or
const isStringOrNumber = or(isString, isNumber)
record
const isEnum = record(isString, isNumber)
Note: record
is limited to string
and symbol
type keys.
shape
const isPosition = shape({ x: isNumber, y: isNumber })
test
const isSlug = test(/^[\w-]+$/)
tuple
const isEntry = tuple(isNumber, isNumber)
Predicates
isAny
isAny(value)
isArray
isArray(value)
isArrayLike
isArrayLike(value)
isBigInt
isBigInt(value)
isBoolean
isBoolean(value)
isDate
isDate(value)
isDictionary
isDictionary(value)
isFalse
isFalse(value)
isFunction
isFunction(value)
isInt
isInt(value)
isInt8
isInt8(value)
isInt16
isInt16(value)
isInt32
isInt32(value)
isLength
isLength(value)
isMap
isMap(value)
isNegative
isNegative(value)
isNever
isNever(value)
isNone
isNone(value)
isNull
isNull(value)
isNumber
isNumber(value)
isObject
isObject(value)
isObjectLike
isObjectLike(value)
isPlainObject
isPlainObject({})
isPositive
isPositive(value)
isPrimitive
isPrimitive(value)
isRegExp
isRegExp(value)
isSerializable
isSerializable(value)
isSerializableArray
isSerializableArray(value)
isSerializableNumber
isSerializableNumber(value)
isSerializableObject
isSerializableObject(value)
isSerializablePrimitive
isSerializablePrimitive(value)
isSet
isSet(value)
isSome
isSome(value)
isString
isString(value)
isSymbol
isSymbol(value)
isTrue
isTrue(value)
isUint
isUint(value)
isUint8
isUint8(value)
isUint16
isUint16(value)
isUint32
isUint32(value)
isUndefined
isUndefined(value)
isWeakMap
isWeakMap(value)
isWithLength
isWithLength(value)
Types
Intersect
Intersect<A | B>
None
None
Predicate
Predicate<T>
Primitive
Primitive
Serializable
Serializable
SerializableArray
SerializableArray
SerializableObject
SerializableObject
SerializablePrimitive
SerializableObject
Some
Some
Static
Static<Predicate<T>>