isntnt
A collection of composable JavaScript runtime type predicates with TypeScript type guard declarations
Last updated 2 months ago by nathanuphoff .
WTFPL · Repository · Original npm · Tarball · package.json
$ cnpm install isntnt 
SYNC missed versions from official npm registry.

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) // (value: unknown) => value is number

and

const isBetween0And21 = and(above(0), below(21)) // (value: unknown) => value is number

array

const isAnyArray = array(isAny) // (value: unknown) => value is Array<any>

at

const isAnyAtFoo = at('foo', isAny) // (value: unknown) => value is { foo: any }

below

const isBelow21 = below(21) // (value: unknown) => value is { foo: any }

either

const isFooOrBar = either('foo', 'bar') // (value: unknown) => value is 'foo' | 'bar'

has

const hasFoo = has('foo') // (value: unknown) => value is { 'foo': unknown }

instance

const isInstanceofString = instance(String) // (value: unknown) => value is String

literal

const is42 = literal(42) // (value: unknown) => value is 42

max

const isMax255 = max(255) // (value: unknown) => value is number

min

const isMin18 = min(18) // (value: unknown) => value is number

noneable

const isNoneableString = noneable(isString) // (value: unknown) => value is string | null | undefined

nullable

const isNullableString = nullable(isString) // (value: unknown) => value is string | null

object

const isEnum = object(isNumber) // (value: unknown) => value is ObjectOf<number>

optional

const isOptionalString = optional(isString) // (value: unknown) => value is string | undefined

or

const isStringOrNumber = or(isString, isNumber) // (value: unknown) => value is string | number

record

const isEnum = record(isString, isNumber) // (value: unknown) => value is Record<string, number>

Note: record is limited to string and symbol type keys.

shape

const isPosition = shape({ x: isNumber, y: isNumber }) // (value: unknown) => value is { x: number, y: number }

test

const isSlug = test(/^[\w-]+$/) // (value: unknown) => value is string

tuple

const isEntry = tuple(isNumber, isNumber) // (value: unknown) => value is [number, number]

Predicates

isAny

isAny(value) // value is any

isArray

isArray(value) // value is Array<unknown>

isArrayLike

isArrayLike(value) // value is Record<number, unknown>

isBigInt

isBigInt(value) // value is bigint

isBoolean

isBoolean(value) // value is boolean

isDate

isDate(value) // value is Date

isDictionary

isDictionary(value) // value is ObjectOf<string>

isFalse

isFalse(value) // value is false

isFunction

isFunction(value) // value is Function

isInt

isInt(value) // value is number

isInt8

isInt8(value) // value is number

isInt16

isInt16(value) // value is number

isInt32

isInt32(value) // value is number

isLength

isLength(value) // value is number

isMap

isMap(value) // value is Map<any, unknown>

isNegative

isNegative(value) // value is number

isNever

isNever(value) // value is never

isNone

isNone(value) // value is null | undefined

isNull

isNull(value) // value is null

isNumber

isNumber(value) // value is number

isObject

isObject(value) // value is object

isObjectLike

isObjectLike(value) // value is ObjectLike

isPositive

isPositive(value) // value is number

isPrimitive

isPrimitive(value) // value is Primitive

isRegExp

isRegExp(value) // value is RegExp

isSerializable

isSerializable(value) // value is Serializable

isSerializableArray

isSerializableArray(value) // value is Array<Serializable>

isSerializableNumber

isSerializableNumber(value) // value is number

isSerializableObject

isSerializableObject(value) // value is Record<string, Serializable>

isSerializablePrimitive

isSerializablePrimitive(value) // value is SerializablePrimitive

isSet

isSet(value) // value is Set<unknown>

isSome

isSome(value) // value is Some

isString

isString(value) // value is string

isSymbol

isSymbol(value) // value is symbol

isTrue

isTrue(value) // value is true

isUint

isUint(value) // value is number

isUint8

isUint8(value) // value is number

isUint16

isUint16(value) // value is number

isUint32

isUint32(value) // value is number

isUndefined

isUndefined(value) // value is undefined

isWeakMap

isWeakMap(value) // value is WeakMap<any, unknown>

isWithLength

isWithLength(value) // value is { length: number }

Types

Intersect

Intersect<A | B> // A & B

None

None // null | undefined

Predicate

Predicate<T> // (value: unknown, ...rest: Array<unknown>) => value is T

Primitive

Primitive // null | undefined | boolean | number | string | symbol | bigint

Serializable

Serializable // SerializableArray | SerializableObject | SerializablePrimitive

SerializableArray

SerializableArray // Array<Serializable>

SerializableObject

SerializableObject // { [key: string]: Serializable }

SerializablePrimitive

SerializableObject // null | boolean | number | string

Some

Some // Function | boolean | bigint | number | string | symbol | object

Static

Static<Predicate<T>> // T

Current Tags

  • 1.3.0                                ...           latest (2 months ago)

11 Versions

  • 1.3.0                                ...           2 months ago
  • 1.2.5                                ...           6 months ago
  • 1.2.4                                ...           6 months ago
  • 1.2.3                                ...           6 months ago
  • 1.2.1                                ...           6 months ago
  • 1.2.2                                ...           6 months ago
  • 1.2.0                                ...           6 months ago
  • 1.1.0                                ...           6 months ago
  • 1.0.2                                ...           9 months ago
  • 1.0.1                                ...           9 months ago
  • 1.0.0                                ...           9 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (4)

Copyright 2014 - 2016 © taobao.org |