Table of contents

namespace

Signature
Source

packages/validate/src/index.ts


Properties

any

Public readonly variable

Validation that accepts any value. Generally this should be avoided, but you can use it as an escape hatch if you want to work without validations for e.g. a prototype.

Signature
any: Validator<any>
References

Validator

Source

packages/validate/src/lib/validation.ts


array

Public readonly variable

Validates that a value is an array. To check the contents of the array, use T.arrayOf.

Signature
array: Validator<unknown[]>
References

Validator

Source

packages/validate/src/lib/validation.ts


bigint

Public readonly variable

Validates that a value is a bigint.

Signature
bigint: Validator<bigint>
References

Validator

Source

packages/validate/src/lib/validation.ts


boolean

Public readonly variable

Validates that a value is boolean.

Signature
boolean: Validator<boolean>
References

Validator

Source

packages/validate/src/lib/validation.ts


indexKey

Public readonly variable

Validates that a value is an IndexKey.

Signature
indexKey: Validator<IndexKey>
References

Validator

Source

packages/validate/src/lib/validation.ts


integer

Public readonly variable

Fails if number is not an integer

Signature
integer: Validator<number>
References

Validator

Source

packages/validate/src/lib/validation.ts


jsonValue

Public readonly variable

Validate that a value is valid JSON.

Signature
jsonValue: Validator<JsonValue>
References

Validator

Source

packages/validate/src/lib/validation.ts


linkUrl

Public readonly variable

Validates that a value is a url safe to use as a link.

Signature
linkUrl: Validator<string>
References

Validator

Source

packages/validate/src/lib/validation.ts


nonZeroInteger

Public readonly variable

Fails if value <= 0 and is not an integer

Signature
nonZeroInteger: Validator<number>
References

Validator

Source

packages/validate/src/lib/validation.ts


nonZeroNumber

Public readonly variable

Fails if value <= 0

Signature
nonZeroNumber: Validator<number>
References

Validator

Source

packages/validate/src/lib/validation.ts


number

Public readonly variable

Validates that a value is a finite non-NaN number.

Signature
number: Validator<number>
References

Validator

Source

packages/validate/src/lib/validation.ts


positiveInteger

Public readonly variable

Fails if value < 0 and is not an integer

Signature
positiveInteger: Validator<number>
References

Validator

Source

packages/validate/src/lib/validation.ts


positiveNumber

Public readonly variable

Fails if value < 0

Signature
positiveNumber: Validator<number>
References

Validator

Source

packages/validate/src/lib/validation.ts


srcUrl

Public readonly variable

Validates that a valid is a url safe to load as an asset.

Signature
srcUrl: Validator<string>
References

Validator

Source

packages/validate/src/lib/validation.ts


string

Public readonly variable

Validates that a value is a string.

Signature
string: Validator<string>
References

Validator

Source

packages/validate/src/lib/validation.ts


unknown

Public readonly variable

Validation that accepts any value. Useful as a starting point for building your own custom validations.

Signature
unknown: Validator<unknown>
References

Validator

Source

packages/validate/src/lib/validation.ts


unknownObject

Public readonly variable

Signature
unknownObject: Validator<Record<string, unknown>>
References

Validator

Source

packages/validate/src/lib/validation.ts


Methods

arrayOf

Public function

Validates that a value is an array whose contents matches the passed-in validator.

Signature
function arrayOf<T>(itemValidator: Validatable<T>): ArrayOfValidator<T>
Parameters
NameDescription

itemValidator

Validatable<T>
Returns
ArrayOfValidator<T>
References

Validatable, ArrayOfValidator

Source

packages/validate/src/lib/validation.ts


dict

Public function

Validation that an option is a dict with particular keys and values.

Signature
function dict<Key extends string, Value>(
  keyValidator: Validatable<Key>,
  valueValidator: Validatable<Value>
): DictValidator<Key, Value>
Parameters
NameDescription

keyValidator

Validatable<Key>

valueValidator

Validatable<Value>
Returns
DictValidator<Key, Value>
References

Validatable, DictValidator

Source

packages/validate/src/lib/validation.ts


jsonDict

Public function

Validate an object has a particular shape.

Signature
function jsonDict(): DictValidator<string, JsonValue>
References

DictValidator

Source

packages/validate/src/lib/validation.ts


literal

Public function

Validates that a value matches another that was passed in.

Example
const trueValidator = T.literal(true)
Signature
function literal<T extends boolean | number | string>(
  expectedValue: T
): Validator<T>
Parameters
NameDescription

expectedValue

T
Returns
Validator<T>
References

Validator

Source

packages/validate/src/lib/validation.ts


literalEnum

Public function

Signature
function literalEnum<const Values extends readonly unknown[]>(
  ...values: Values
): Validator<Values[number]>
Parameters
NameDescription

values

Values
Returns
Validator<Values[number]>
References

Validator

Source

packages/validate/src/lib/validation.ts


model

Public function

A named object with an ID. Errors will be reported as being part of the object with the given name.

Signature
function model<
  T extends {
    readonly id: string
  },
>(name: string, validator: Validatable<T>): Validator<T>
Parameters
NameDescription

name

string

validator

Validatable<T>
Returns
Validator<T>
References

Validatable, Validator

Source

packages/validate/src/lib/validation.ts


nullable

Public function

Signature
function nullable<T>(validator: Validatable<T>): Validator<null | T>
Parameters
NameDescription

validator

Validatable<T>
Returns
Validator<null | T>
References

Validatable, Validator

Source

packages/validate/src/lib/validation.ts


object

Public function

Validate an object has a particular shape.

Signature
function object<Shape extends object>(config: {
  readonly [K in keyof Shape]: Validatable<Shape[K]>
}): ObjectValidator<
  {
    [P in ExtractRequiredKeys<Shape>]: Shape[P]
  } & {
    [P in ExtractOptionalKeys<Shape>]?: Shape[P]
  }
>
Parameters
NameDescription

config

{
  readonly [K in keyof Shape]: Validatable<Shape[K]>
}
Returns
ObjectValidator<
  {
    [P in ExtractRequiredKeys<Shape>]: Shape[P]
  } & {
    [P in ExtractOptionalKeys<Shape>]?: Shape[P]
  }
>
References

Validatable, ObjectValidator

Source

packages/validate/src/lib/validation.ts


optional

Public function

Signature
function optional<T>(validator: Validatable<T>): Validator<T | undefined>
Parameters
NameDescription

validator

Validatable<T>
Returns
Validator<T | undefined>
References

Validatable, Validator

Source

packages/validate/src/lib/validation.ts


setEnum

Public function

Signature
function setEnum<T>(values: ReadonlySet<T>): Validator<T>
Parameters
NameDescription

values

ReadonlySet<T>
Returns
Validator<T>
References

Validator

Source

packages/validate/src/lib/validation.ts


union

Public function

Validate a union of several object types. Each object must have a property matching key which should be a unique string.

Example
const catValidator = T.object({ kind: T.value('cat'), meow: T.boolean })
const dogValidator = T.object({ kind: T.value('dog'), bark: T.boolean })
const animalValidator = T.union('kind', {
  cat: catValidator,
  dog: dogValidator,
})
Signature
function union<
  Key extends string,
  Config extends UnionValidatorConfig<Key, Config>,
>(key: Key, config: Config): UnionValidator<Key, Config>
Parameters
NameDescription

key

Key

config

Config
Returns
UnionValidator<Key, Config>
References

UnionValidator

Source

packages/validate/src/lib/validation.ts


ObjectValidatorUnionValidator