Skip to main content

is.string

Validates that a value is a string. Chain helpers directly on is.string to refine or transform the value.

Format validators

Length and content

Encoding validators

Hash validation

.hash(options?) validates a cryptographic hash string using @noble/hashes. Works in browser, Node.js, and edge runtimes. Options:
  • alg'sha1' | 'sha256' | 'sha384' | 'sha512' | 'md5' (default: 'sha256')
  • enc'hex' | 'base64' | 'base64url' (default: 'hex')
  • padding'required' | 'optional' | 'forbidden' (only relevant for base64/base64url)
Chain .verify(plaintext) after .hash() for a timing-safe comparison that re-hashes the plaintext and compares.

JSON validators

ISO date and time

Access sub-validators through .iso:

Transformers

Transformers modify the value as it flows through the chain. Subsequent validators operate on the transformed value.

Boolean strings

.boolStr validates strings that represent boolean values. It is case-insensitive by default and accepts:
  • Truthy: true, 1, yes, y, on, active, enabled (and their capitalised/uppercase variants)
  • Falsy: false, 0, no, n, off, inactive, disabled (and their capitalised/uppercase variants)
Chain .truthy(options?) or .falsy(options?) to accept only one side. Chain .asBool to transform the string to a boolean. Pass { values: [...strings] } into .truthy() or .falsy() to use a custom allowlist.

is.number

Validates that a value is a number (not NaN).

Helpers


is.boolean

Validates that a value is true or false.

Other primitives


Type-only guards

Unknown and any always pass at runtime and all three narrow the TypeScript type.

is.literal(...values)

Validates strict equality against one or more literal values. Uses Object.is semantics, so it correctly handles NaN and distinguishes 0 from -0.

is.templateLiteral(...)

Validates that a string matches a template literal pattern. Accepts a mix of string segments and guards for interpolated positions.


is.enum(values)

Validates that a value is one of the members of an array, TypeScript enum, or object literal.