UNPKG

ts-regex-builder

Version:

Maintainable regular expressions for TypeScript and JavaScript.

1 lines 3.46 kB
{"version":3,"file":"types.mjs","names":[],"sources":["../../src/types.ts"],"sourcesContent":["export type ArrayOrSingle<T> = T[] | T;\n\n/**\n * Sequence of regex elements forming a regular expression.\n *\n * For developer convenience it also accepts a single element instead of array.\n */\nexport type RegexSequence = RegexElement[] | RegexElement;\n\n/**\n * Fundamental building block of a regular expression, defined as either a regex construct, `RegExp` object or a string.\n */\nexport type RegexElement = RegexConstruct | RegExp | string;\n\n/**\n * Fundamental building block of a regular expression, defined as either an encoded regex or a character class.\n */\nexport type RegexConstruct = EncodedRegex | LazyEncodableRegex;\n\n/**\n * Encoded regex pattern with information about its type (atom, sequence)\n */\nexport interface EncodedRegex {\n precedence: EncodePrecedence;\n pattern: string;\n}\n\nexport type EncodePrecedence = 'atom' | 'sequence' | 'disjunction';\n\nexport interface CharacterEscape extends EncodedRegex {\n // `CharacterClass` compatibility\n chars: string[];\n ranges?: never;\n}\n\nexport interface LazyEncodableRegex {\n encode: () => EncodedRegex;\n}\n\nexport interface CharacterClass extends LazyEncodableRegex {\n chars: string[];\n ranges?: CharacterRange[];\n}\n\nexport interface CharacterRange {\n start: string;\n end: string;\n}\n\n/**\n * Flags to be passed to RegExp constructor.\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/RegExp#flags\n */\nexport interface RegexFlags {\n /**\n * Find all matches in a string, instead of just the first one.\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global\n */\n global?: boolean;\n\n /**\n * Perform case-insensitive matching.\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase\n */\n ignoreCase?: boolean;\n\n /**\n * Treat the start and end of each line in a string as the beginning and end of the string.\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline\n */\n multiline?: boolean;\n\n /**\n * Generate the start and end indices of each captured group in a match.\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices\n */\n hasIndices?: boolean;\n\n /**\n * MDN: _Allows . to match newlines._\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/dotAll\n */\n dotAll?: boolean;\n\n /**\n * MDN: _Matches only from the index indicated by the `lastIndex` property of this regular expression in the target string. Does not attempt to match from any later indexes._\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky\n */\n sticky?: boolean;\n\n /**\n * Enables [Unicode-aware mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode#unicode-aware_mode).\n *\n * This enables features like:\n * - Unicode character escapes: `\\u{xxxx}`\n * - Unicode character property escapes:`\\p{Property=Value}`\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode\n */\n unicode?: boolean;\n}\n"],"mappings":"","ignoreList":[]}