UNPKG

valia

Version:

A runtime data validator in TypeScript with advanced type inference, built-in validation functions, and seamless integration for server and client environments.

17 lines (16 loc) 530 B
interface AsciiConfig { /** **Default:** `false` */ onlyPrintable?: boolean; } /** * Check if all characters of the string are in the ASCII table (%d0-%d127). * * If you enable `onlyPrintable` valid characters will be limited to * printable characters from the ASCII table (%32-%d126). * * Empty returns `false`. */ export function isAscii(str: string, config?: AsciiConfig): boolean { if (config?.onlyPrintable) return (RegExp("^[\\x20-\\x7E]+$").test(str)) return (RegExp("^[\\x00-\\x7F]+$").test(str)); }