is-string-ascii-es/all.ts
2026-01-29 17:47:49 +08:00

31 lines
632 B
TypeScript

//deno-lint-ignore no-control-regex -- Intentional.
const regexpASCII = /^[\x00-\x7F]*$/;
/**
* Determine whether the string is ASCII.
* @param {string} item Item that need to determine.
* @returns {boolean} Determine result.
* @example
* ```ts
* isStringASCII("日本語");
* //=> false
* ```
* @example
* ```ts
* isStringASCII("👀");
* //=> false
* ```
* @example
* ```ts
* isStringASCII("Hello, world!");
* //=> true
* ```
* @example
* ```ts
* isStringASCII("");
* //=> true
* ```
*/
export function isStringASCII(item: string): boolean {
return regexpASCII.test(item);
}
export default isStringASCII;