ts-regex-builder
Version:
Maintainable regular expressions for TypeScript and JavaScript.
21 lines • 686 B
JavaScript
export function unicodeChar(codePoint) {
if (!Number.isInteger(codePoint) || codePoint < 0 || codePoint > 0x10ffff) {
throw new RangeError(`Expected a valid unicode code point but received ${codePoint}`);
}
let escape = codePoint < 0x10000 ? `\\u${codePoint.toString(16).padStart(4, '0')}` : `\\u{${codePoint.toString(16)}}`;
return {
precedence: 'atom',
pattern: escape,
chars: [escape]
};
}
export const char = unicodeChar;
export function unicodeProperty(property, value) {
const escape = `\\p{${property}${value ? `=${value}` : ''}}`;
return {
precedence: 'atom',
pattern: escape,
chars: [escape]
};
}
//# sourceMappingURL=unicode.mjs.map