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) • 566 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isAscii = isAscii;
/**
* 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`.
*/
function isAscii(str, params) {
if (params === null || params === void 0 ? void 0 : params.onlyPrintable)
return (RegExp("^[\\x20-\\x7E]+$").test(str));
return (RegExp("^[\\x00-\\x7F]+$").test(str));
}