Skip to main content
Go to Latest
import * as openbox from "https://deno.land/x/openbox@1.1.1/deps.ts";

A library of assertion functions. If the assertion is false an AssertionError will be thrown which will result in pretty-printed diff of failing assertion.

This module is browser compatible, but do not rely on good formatting of values for AssertionError messages in browsers.

Namespaces

Fast undefined check used for properties of type undefined

A registry for user defined string formats

Specialized Clone for Types

Compiles Types for Runtime Type Checking

Provides functions to test if JavaScript values are TypeBox types

A registry for user defined types

Functions to perform structural operations on JavaScript values

Provides functions to type guard raw JavaScript values

Functions

Make an assertion, error will be thrown if expr does not have truthy value.

Make an assertion that actual and expected are almost equal numbers through a given tolerance. It can be used to take into account IEEE-754 double-precision floating-point representation limitations. If the values are not almost equal then throw.

Make an assertion that actual includes the expected values. If not then an error will be thrown.

Make an assertion that actual and expected are equal, deeply. If not deeply equal, then throw.

Make an assertion that actual is not null or undefined. If not then throw.

Make an assertion, error will be thrown if expr have truthy value.

Make an assertion that actual is greater than expected. If not then throw.

Make an assertion that actual is greater than or equal to expected. If not then throw.

Make an assertion that obj is an instance of type. If not then throw.

Make an assertion that error is an Error. If not then an error will be thrown. An error class and a string that should be included in the error message can also be asserted.

Make an assertion that actual is less than expected. If not then throw.

Make an assertion that actual is less than or equal to expected. If not then throw.

Make an assertion that actual match RegExp expected. If not then throw.

Make an assertion that actual and expected are not equal, deeply. If not then throw.

Make an assertion that obj is not an instance of type. If so, then throw.

Make an assertion that actual not match RegExp expected. If match then throw.

Make an assertion that actual and expected are not strictly equal. If the values are strictly equal then throw.

Make an assertion that actual object is a subset of expected object, deeply. If not, then throw.

Executes a function which returns a promise, expecting it to reject.

Make an assertion that actual and expected are strictly equal. If not then throw.

Make an assertion that actual includes expected. If not then throw.

Executes a function, expecting it to throw. If it does not, then it throws.

Concatenate the given arrays into a new Uint8Array.

Deep equality comparison used in assertions

Check whether binary arrays are equal to each other.

Forcefully throws a failed assertion

Clears all user defined string formats

Deletes a registered format

Returns the entries in this registry

Gets a validation function for a user defined string format

Returns true if the user defined string format exists

Sets a validation function for a user defined string format

Returns the index of the first occurrence of the needle array in the source array, or -1 if it is not present.

Applies an intrinsic string manipulation to the given type.

Resolves an array of string[] keys from the given schema or array type.

Resolves an array of keys in this schema

Resolves a regular expression pattern matching all keys in this schema

Returns the index of the last occurrence of the needle array in the source array, or -1 if it is not present.

Returns true if the prefix array appears at the start of the source array, false otherwise.

Parses a pattern and returns an expression tree

Parses a pattern and strips forward and trailing ^ and $

Resolves a template literal as a TUnion

Clones a Rest

Clones a Type

Generates the code used to assert this type and returns it as a string

Compiles a TypeBox type for optimal runtime type checking. Types must be valid TypeBox types of TSchema

Returns true if the given value is TAny

Returns true if the given value is TArray

Returns true if the given value is TAsyncIterator

Returns true if the given value is TBigInt

Returns true if the given value is TBoolean

Returns true if the given value is TConstructor

Returns true if the given value is TDate

Returns true if the given value is TFunction

Returns true if the given value is TInteger

Returns true if the given value is TIntersect

Returns true if the given value is TIterator

Returns true if the given value is TKind

Returns true if the given value is a TKind with the given name.

Returns true if the given value is TLiteral

Returns true if the given value is TLiteral

Returns true if the given value is TLiteral

Returns true if the given value is TLiteral

Returns true if the given value is TNever

Returns true if the given value is TNot

Returns true if the given value is TNull

Returns true if the given value is TNumber

Returns true if the given value is TObject

Returns true if this value has a Optional symbol

Returns true if the given value is TPromise

Returns true if this value has a Readonly symbol

Returns true if the given value is TRecord

Returns true if this value is TRecursive

Returns true if the given value is TRef

Returns true if the given value is TSchema

Returns true if the given value is TString

Returns true if the given value is TSymbol

Returns true if the given value is TTemplateLiteral

Returns true if the given value is TThis

Returns true of this value is TTransform

Returns true if the given value is TTuple

Returns true if the given value is TUint8Array

Returns true if the given value is TUndefined

Returns true if the given value is TUnion

Returns true if the given value is TUnion<Literal<string | number>[]>

Returns true if the given value is TUnknown

Returns true if the given value is a raw TUnsafe

Returns true if the given value is TVoid

Clears all user defined types

Deletes a registered type

Returns the entries in this registry

Gets a custom validation function for a user defined type

Returns true if this registry contains this kind

Sets a validation function for a user defined type

Use this to stub out methods that will throw when invoked.

Returns a resolved union with interior unions flattened

Use this to assert unreachable code.

Casts a value into a given type. The return value will retain as much information of the original value as possible.

Returns true if the value matches the given type and references

Returns a structural clone of the given value

Converts any type mismatched values to their target type if a reasonable conversion is possible

Creates a value from the given type and references

Decodes a value or throws if error

Returns edits to transform the current value into the next value

Encodes a value or throws if error

Returns true if left and right values are structurally equal

Returns an iterator for each error in this value.

Returns a FNV1A-64 non cryptographic hash of the given value

Performs a deep mutable value assignment while retaining internal references.

Returns a new value with edits applied to the given value

Returns true if this value is an array

Returns true if this value is bigint

Returns true if this value is a boolean

Returns true if this value is null

Returns true if this value is number

Returns true if this value is an object

Returns true if this value is string

Returns true if this value is undefined

Type Aliases

Creates the static type for a TypeBox type

Creates the decoded static form for a TypeBox type

Creates the encoded static form for a TypeBox type