The name of the custom token. In TypeScript, it needs to be defined in the RegExpToken interface.
The configuration for the custom token. Implement the constant
method to return a constant token, or the dynamic
method for a token that accepts arguments. Implement both for a mixed token.
The custom token
Create a constant token
Extend the RegExpToken interface to add a new token:
import { RegExpToken } from 'readable-regexp';
declare module 'readable-regexp' {
interface RegExpToken {
severity: RegExpToken;
}
}
Implement the custom token:
const severity = defineToken('severity', {
constant(this: RegExpToken) {
return this.oneOf`error` `warning` `info` `debug`;
},
});
Use the custom token:
// Referencing the token returned by the defineToken function
console.log(severity.toString()); // (?:error|warning|info|debug)
// Referencing the token in an expression
console.log(lineStart.severity.lineEnd.toString()); // ^(?:error|warning|info|debug)$
Generated using TypeDoc
Define a custom token that can be used in conjunction with other tokens. For a detailed guide on custom tokens, please read https://github.com/hlysine/readable-regexp#custom-tokens
Notes: