validate
PoolZero-dependency string validation and sanitization - Tree-shakeable alternative to validator.js
dist
Functions
function isEmail(str: string, options?: EmailOptions): boolean
Validate email address (RFC 5322 practical regex) Uses practical 99.99% accurate regex instead of full RFC 5322 (full RFC regex is 6,343 chars and impractical)
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
optionsoptional | EmailOptions | - Email validation options |
function isURL(str: string, options?: URLOptions): boolean
Validate URL (RFC 3986) Supports http, https, ftp, file, data URLs
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
optionsoptional | URLOptions | - URL validation options |
function isNumeric(str: string, options?: NumericOptions): boolean
Check if string is numeric
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
optionsoptional | NumericOptions | - Numeric validation options (min, max, gt, lt) |
function isInt(str: string, options?: IntOptions): boolean
Check if string is an integer
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
optionsoptional | IntOptions | - Integer validation options |
function isFloat(str: string, options?: FloatOptions): boolean
Check if string is a float
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
optionsoptional | FloatOptions | - Float validation options |
function isDecimal(str: string, options?: FloatOptions): boolean
Check if string is a decimal (must have decimal separator)
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
optionsoptional | FloatOptions | - Float validation options |
function isAlpha(str: string, locale?: string): boolean
Check if string contains only letters (a-z, A-Z)
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
localeoptional | string | - Locale for character set (default: 'en-US') |
function isAlphanumeric(str: string, locale?: string): boolean
Check if string contains only letters and numbers
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
localeoptional | string | - Locale for character set (default: 'en-US') |
function isLength(str: string, options: LengthOptions): boolean
Check if string length is within range
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
options | LengthOptions | - Length options (min, max) |
function isAscii(str: string): boolean
Check if string contains only ASCII characters
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function isLowercase(str: string): boolean
Check if string is lowercase
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function isUppercase(str: string): boolean
Check if string is uppercase
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function isIP(str: string, version?: 4 | 6): boolean
Check if string is a valid IP address (IPv4 or IPv6)
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
versionoptional | 4 | 6 | - IP version (4, 6, or undefined for both) |
function isMACAddress(str: string, options?: MACAddressOptions): boolean
Check if string is a valid MAC address
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
optionsoptional | MACAddressOptions | - MAC address options |
function isPort(str: string): boolean
Check if string is a valid port number
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function isJSON(str: string): boolean
Check if string is valid JSON
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function isBase64(str: string, options?: Base64Options): boolean
Check if string is valid Base64
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
optionsoptional | Base64Options | - Base64 options |
function isHexadecimal(str: string): boolean
Check if string is valid hexadecimal
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function isHexColor(str: string): boolean
Check if string is valid hex color
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function isISO8601(str: string): boolean
Check if string is valid ISO 8601 date
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function isRFC3339(str: string): boolean
Check if string is valid RFC 3339 date-time
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function isUUID(str: string, version?: 1 | 3 | 4 | 5): boolean
Check if string is a valid UUID
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
versionoptional | 1 | 3 | 4 | 5 | - UUID version (1, 3, 4, 5, or undefined for any) |
function isISBN(str: string, version?: 10 | 13): boolean
Check if string is a valid ISBN
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
versionoptional | 10 | 13 | - ISBN version (10, 13, or undefined for both) |
function isMongoId(str: string): boolean
Check if string is a valid MongoDB ObjectId
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function isJWT(str: string): boolean
Check if string is a valid JSON Web Token (JWT)
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function isCreditCard(str: string): boolean
Check if string is a valid credit card number (Luhn algorithm) Validates using the Luhn algorithm (mod 10 checksum) Supports Visa, MasterCard, American Express, Discover, and more
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function escape(str: string): string
Escape HTML entities to prevent XSS attacks
| Parameter | Type | Description |
|---|---|---|
str | string | - String to escape |
function unescape(str: string): string
Unescape HTML entities
| Parameter | Type | Description |
|---|---|---|
str | string | - String to unescape |
function trim(str: string, chars?: string): string
Trim whitespace from both ends of string
| Parameter | Type | Description |
|---|---|---|
str | string | - String to trim |
charsoptional | string | - Characters to trim (default: whitespace) |
function ltrim(str: string, chars?: string): string
Trim whitespace from left side of string
| Parameter | Type | Description |
|---|---|---|
str | string | - String to trim |
charsoptional | string | - Characters to trim (default: whitespace) |
function rtrim(str: string, chars?: string): string
Trim whitespace from right side of string
| Parameter | Type | Description |
|---|---|---|
str | string | - String to trim |
charsoptional | string | - Characters to trim (default: whitespace) |
function normalizeEmail(email: string, options?: NormalizeEmailOptions): string
Normalize email address
| Parameter | Type | Description |
|---|---|---|
email | string | - Email to normalize |
optionsoptional | NormalizeEmailOptions | - Normalization options |
function stripLow(str: string, keepNewLines?: boolean): string
Remove control characters (ASCII 0-31 and 127)
| Parameter | Type | Description |
|---|---|---|
str | string | - String to strip |
keepNewLinesoptional | boolean | - Keep newline characters (default: false) |
dist
Functions
function isEmail(str: string, options?: EmailOptions): boolean
Validate email address (RFC 5322 practical regex) Uses practical 99.99% accurate regex instead of full RFC 5322 (full RFC regex is 6,343 chars and impractical)
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
optionsoptional | EmailOptions | - Email validation options |
function isURL(str: string, options?: URLOptions): boolean
Validate URL (RFC 3986) Supports http, https, ftp, file, data URLs
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
optionsoptional | URLOptions | - URL validation options |
function isNumeric(str: string, options?: NumericOptions): boolean
Check if string is numeric
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
optionsoptional | NumericOptions | - Numeric validation options (min, max, gt, lt) |
function isInt(str: string, options?: IntOptions): boolean
Check if string is an integer
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
optionsoptional | IntOptions | - Integer validation options |
function isFloat(str: string, options?: FloatOptions): boolean
Check if string is a float
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
optionsoptional | FloatOptions | - Float validation options |
function isDecimal(str: string, options?: FloatOptions): boolean
Check if string is a decimal (must have decimal separator)
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
optionsoptional | FloatOptions | - Float validation options |
function isAlpha(str: string, locale?: string): boolean
Check if string contains only letters (a-z, A-Z)
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
localeoptional | string | - Locale for character set (default: 'en-US') |
function isAlphanumeric(str: string, locale?: string): boolean
Check if string contains only letters and numbers
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
localeoptional | string | - Locale for character set (default: 'en-US') |
function isLength(str: string, options: LengthOptions): boolean
Check if string length is within range
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
options | LengthOptions | - Length options (min, max) |
function isAscii(str: string): boolean
Check if string contains only ASCII characters
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function isLowercase(str: string): boolean
Check if string is lowercase
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function isUppercase(str: string): boolean
Check if string is uppercase
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function isIP(str: string, version?: 4 | 6): boolean
Check if string is a valid IP address (IPv4 or IPv6)
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
versionoptional | 4 | 6 | - IP version (4, 6, or undefined for both) |
function isMACAddress(str: string, options?: MACAddressOptions): boolean
Check if string is a valid MAC address
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
optionsoptional | MACAddressOptions | - MAC address options |
function isPort(str: string): boolean
Check if string is a valid port number
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function isJSON(str: string): boolean
Check if string is valid JSON
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function isBase64(str: string, options?: Base64Options): boolean
Check if string is valid Base64
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
optionsoptional | Base64Options | - Base64 options |
function isHexadecimal(str: string): boolean
Check if string is valid hexadecimal
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function isHexColor(str: string): boolean
Check if string is valid hex color
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function isISO8601(str: string): boolean
Check if string is valid ISO 8601 date
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function isRFC3339(str: string): boolean
Check if string is valid RFC 3339 date-time
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function isUUID(str: string, version?: 1 | 3 | 4 | 5): boolean
Check if string is a valid UUID
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
versionoptional | 1 | 3 | 4 | 5 | - UUID version (1, 3, 4, 5, or undefined for any) |
function isISBN(str: string, version?: 10 | 13): boolean
Check if string is a valid ISBN
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
versionoptional | 10 | 13 | - ISBN version (10, 13, or undefined for both) |
function isMongoId(str: string): boolean
Check if string is a valid MongoDB ObjectId
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function isJWT(str: string): boolean
Check if string is a valid JSON Web Token (JWT)
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function isCreditCard(str: string): boolean
Check if string is a valid credit card number (Luhn algorithm) Validates using the Luhn algorithm (mod 10 checksum) Supports Visa, MasterCard, American Express, Discover, and more
| Parameter | Type | Description |
|---|---|---|
str | string | - String to validate |
function escape(str: string): string
Escape HTML entities to prevent XSS attacks
| Parameter | Type | Description |
|---|---|---|
str | string | - String to escape |
function unescape(str: string): string
Unescape HTML entities
| Parameter | Type | Description |
|---|---|---|
str | string | - String to unescape |
function trim(str: string, chars?: string): string
Trim whitespace from both ends of string
| Parameter | Type | Description |
|---|---|---|
str | string | - String to trim |
charsoptional | string | - Characters to trim (default: whitespace) |
function ltrim(str: string, chars?: string): string
Trim whitespace from left side of string
| Parameter | Type | Description |
|---|---|---|
str | string | - String to trim |
charsoptional | string | - Characters to trim (default: whitespace) |
function rtrim(str: string, chars?: string): string
Trim whitespace from right side of string
| Parameter | Type | Description |
|---|---|---|
str | string | - String to trim |
charsoptional | string | - Characters to trim (default: whitespace) |
function normalizeEmail(email: string, options?: NormalizeEmailOptions): string
Normalize email address
| Parameter | Type | Description |
|---|---|---|
email | string | - Email to normalize |
optionsoptional | NormalizeEmailOptions | - Normalization options |
function stripLow(str: string, keepNewLines?: boolean): string
Remove control characters (ASCII 0-31 and 127)
| Parameter | Type | Description |
|---|---|---|
str | string | - String to strip |
keepNewLinesoptional | boolean | - Keep newline characters (default: false) |
Taxes calculated at checkout based on your location.