46 lines
1.9 KiB
TypeScript
46 lines
1.9 KiB
TypeScript
|
// 4.5. Code points https://infra.spec.whatwg.org/#code-points
|
||
|
export class CodePoints {
|
||
|
// https://infra.spec.whatwg.org/#ascii-code-point
|
||
|
public static ASCIICodePoint(input: string): boolean {
|
||
|
// An ASCII code point is a code point in the range U+0000 NULL to U+007F DELETE, inclusive.
|
||
|
// eslint-disable-next-line no-control-regex
|
||
|
return /[\u0000-\u007F]/.test(input);
|
||
|
}
|
||
|
|
||
|
// https://infra.spec.whatwg.org/#ascii-alphanumeric
|
||
|
public static ASCIIAlphanumeric(input: string): boolean {
|
||
|
// An ASCII alphanumeric is an ASCII digit or ASCII alpha.
|
||
|
return this.ASCIIiAlpha(input) || this.ASCIIDigit(input);
|
||
|
}
|
||
|
|
||
|
// https://infra.spec.whatwg.org/#ascii-alpha
|
||
|
public static ASCIIiAlpha(input: string): boolean {
|
||
|
// An ASCII alpha is an ASCII upper alpha or ASCII lower alpha.
|
||
|
return this.ASCIIUpperAlpha(input) || this.ASCIILowerAlpha(input);
|
||
|
}
|
||
|
|
||
|
// https://infra.spec.whatwg.org/#ascii-upper-alpha
|
||
|
public static ASCIIUpperAlpha(input: string): boolean {
|
||
|
// An ASCII upper alpha is a code point in the range U+0041 (A) to U+005A (Z), inclusive.
|
||
|
return /[\u0041-\u005A]/.test(input);
|
||
|
}
|
||
|
|
||
|
// https://infra.spec.whatwg.org/#ascii-lower-alpha
|
||
|
public static ASCIILowerAlpha(input: string): boolean {
|
||
|
// An ASCII lower alpha is a code point in the range U+0061 (a) to U+007A (z), inclusive.
|
||
|
return /[\u0061-\u007A]/.test(input);
|
||
|
}
|
||
|
|
||
|
// https://infra.spec.whatwg.org/#ascii-digit
|
||
|
public static ASCIIDigit(input: string): boolean {
|
||
|
// An ASCII digit is a code point in the range U+0030 (0) to U+0039 (9), inclusive.
|
||
|
return /[\u0030-\u0039]/.test(input);
|
||
|
}
|
||
|
|
||
|
// https://infra.spec.whatwg.org/#ascii-string
|
||
|
public static ASCIIString(input: string): boolean {
|
||
|
// An ASCII string is a string whose code points are all ASCII code points.
|
||
|
return input.split('').every(codePoint => this.ASCIICodePoint(codePoint));
|
||
|
}
|
||
|
}
|