is.string
Validates that a value is a string. Chain helpers directly on is.string to refine or transform the value.
Format validators
| Helper | Validates |
|---|---|
.email | RFC 5322 email address |
.url | Any WHATWG-compliant URL string |
.httpUrl | URL with http: or https: protocol |
.uuid(options?) | UUID (any version by default); pass { version: 'v4' } to pin to a version |
.uuidv4() | Shorthand for UUID v4 |
.uuidv6() | Shorthand for UUID v6 |
.uuidv7() | Shorthand for UUID v7 |
.ulid | ULID (26-character lexicographically sortable ID) |
.nanoid(options?) | NanoID; default length 21, override with { length: n } |
.ipv4 | IPv4 address |
.ipv6 | IPv6 address |
.cidrv4 | IPv4 CIDR block (e.g. 192.168.1.0/24) |
.cidrv6 | IPv6 CIDR block (e.g. 2001:db8::/32) |
.mac(options?) | MAC address; delimiter defaults to :, pass { delimiter: '-' | '.' | 'none' } to override |
.emoji | Contains at least one emoji character |
.uppercase | All characters are uppercase |
.lowercase | All characters are lowercase |
Length and content
| Helper | Validates |
|---|---|
.min(n) | Length ≥ n |
.max(n) | Length ≤ n |
.length(n) | Exact length of n |
.regex(re) | Matches regular expression |
.includes(str) | Contains substring |
.startsWith(str) | Starts with prefix |
.endsWith(str) | Ends with suffix |
Encoding validators
| Helper | Validates |
|---|---|
.base64(options?) | Base64 encoding; options: { padding: 'required' | 'optional' | 'forbidden' } |
.hex(options?) | Hex encoding; options: { prefix?: boolean, evenLength?: boolean, case?: 'lower' | 'upper' | 'mixed' } |
.jwt(options?) | JWT structure; options: { validateJson?: boolean, alg?: string | string[] } |
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)
.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:
| Helper | Validates |
|---|---|
.iso | Any ISO 8601 string |
.iso.date | Date only: YYYY-MM-DD |
.iso.time(options?) | Time: HH:MM or HH:MM:SS[.s+]; { precision: -1 } for minute-only |
.iso.datetime(options?) | Full datetime with timezone; { offset: false } forbids it, { local: true } allows unqualified |
Transformers
Transformers modify the value as it flows through the chain. Subsequent validators operate on the transformed value.| Helper | Transforms |
|---|---|
.trim() | Removes leading and trailing whitespace |
.toLowerCase() | Converts to lowercase |
.toUpperCase() | Converts to uppercase |
.normalize(options?) | Unicode normalization; default form 'NFC' |
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)
.truthy() or .falsy() to accept only one side. Chain .asBool to transform the string to a boolean.
is.number
Validates that a value is a number (not NaN).
Helpers
| Helper | Validates |
|---|---|
.int | Safe integer (no decimal part) |
.positive | Greater than 0 |
.negative | Less than 0 |
.finite | Not Infinity or -Infinity |
.safe | Within Number.MAX_SAFE_INTEGER |
.even | Divisible by 2 |
.odd | Not divisible by 2 |
.gt(n) | Greater than n |
.gte(n) | Greater than or equal to n |
.lt(n) | Less than n |
.lte(n) | Less than or equal to n |
.between(min, max) | Inclusive range |
.eq(n) | Strictly equal to n |
.multipleOf(n) | Divisible by n with no remainder |
is.boolean
Validates that a value is true or false.
| Helper | Validates |
|---|---|
.true | Exactly true |
.false | Exactly false |
Other primitives
| Guard | Validates |
|---|---|
is.bigint | BigInt values |
is.symbol | Symbol values |
is.null | null |
is.undefined | undefined |
is.void | null or undefined |
is.nan | NaN (branded as NaN type) |
Type-only guards
These guards always pass at runtime but narrow the TypeScript type.| Guard | Type |
|---|---|
is.unknown | unknown |
is.any | any |
is.never | never (always fails at runtime) |
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.