type Flag = 'd' | 'g' | 'i' | 'm' | 's' | 'u' | 'y'; /** Generate indices for substring matches */ declare const withIndices = "d"; /** Case-insensitive search */ declare const caseInsensitive = "i"; /** Global search */ declare const global = "g"; /** Multi-line search */ declare const multiline = "m"; /** Allows `.` to match newline characters */ declare const dotAll = "s"; /** Treat a pattern as a sequence of unicode code points */ declare const unicode = "u"; /** Perform a "sticky" search that matches starting at the current position in the target string */ declare const sticky = "y"; type Join = T extends [infer F, ...infer R] ? F extends string ? `${Prefix}${F}${R extends string[] ? Join : ''}` : '' : ''; type UnionToIntersection = (Union extends Union ? (a: Union) => any : never) extends (a: infer I) => any ? I : never; type UnionToTuple = UnionToIntersection Union : never> extends () => infer Item ? UnionToTuple, [...Tuple, Item]> : Tuple; declare const NamedGroupsS: unique symbol; declare const ValueS: unique symbol; declare const CapturedGroupsArrS: unique symbol; declare const FlagsS: unique symbol; type MagicRegExp = RegExp & { [NamedGroupsS]: NamedGroups; [CapturedGroupsArrS]: CapturedGroupsArr; [ValueS]: Value; [FlagsS]: Flags; }; type ExtractGroups> = T extends MagicRegExp ? V : never; type StringWithHint = string & { _capturedBy: S; }; type StringCapturedBy = StringWithHint; type MapToStringCapturedBy = { [K in keyof Ar]: Ar[K] extends string ? StringCapturedBy | undefined : undefined; }; type MagicRegExpMatchArray> = Omit & { groups: Record, string | undefined>; } & { [index: number | string | symbol]: never; } & (T extends MagicRegExp ? readonly [string | undefined, ...MapToStringCapturedBy] : {}); type IfUnwrapped = Value extends `(${string})` ? No : StripEscapes extends `${infer A}${infer B}` ? A extends '' ? No : B extends '' ? No : Yes : never; /** This matches any character in the string provided */ declare const charIn: ((chars: T) => CharInput>) & CharInput<"">; /** This matches any character that is not in the string provided */ declare const charNotIn: ((chars: T) => CharInput<`^${Escape}`>) & CharInput<"^">; /** * This takes a variable number of inputs and matches any of them * @example * anyOf('foo', maybe('bar'), 'baz') // => /(?:foo|(?:bar)?|baz)/ * @argument inputs - arbitrary number of `string` or `Input`, where `string` will be escaped */ declare function anyOf(...inputs: Inputs): Input<`(?:${Join>})`, MapToGroups, MapToCapturedGroupsArr>; declare const char: Input<".", never, []>; declare const word: Input<"\\b\\w+\\b", never, []>; declare const wordChar: Input<"\\w", never, []>; declare const wordBoundary: Input<"\\b", never, []>; declare const digit: Input<"\\d", never, []>; declare const whitespace: Input<"\\s", never, []>; declare const letter: Input<"[a-zA-Z]", never, []> & { lowercase: Input<"[a-z]", never, []>; uppercase: Input<"[A-Z]", never, []>; }; declare const tab: Input<"\\t", never, []>; declare const linefeed: Input<"\\n", never, []>; declare const carriageReturn: Input<"\\r", never, []>; declare const not: { word: Input<"\\W+", never, []>; wordChar: Input<"\\W", never, []>; wordBoundary: Input<"\\B", never, []>; digit: Input<"\\D", never, []>; whitespace: Input<"\\S", never, []>; letter: Input<"[^a-zA-Z]", never, []> & { lowercase: Input<"[^a-z]", never, []>; uppercase: Input<"[^A-Z]", never, []>; }; tab: Input<"[^\\t]", never, []>; linefeed: Input<"[^\\n]", never, []>; carriageReturn: Input<"[^\\r]", never, []>; }; /** * Equivalent to `?` - takes a variable number of inputs and marks them as optional * @example * maybe('foo', exactly('ba?r')) // => /(?:fooba\?r)?/ * @argument inputs - arbitrary number of `string` or `Input`, where `string` will be escaped */ declare function maybe, '', ''>>(...inputs: Inputs): Input, MapToGroups, MapToCapturedGroupsArr>; /** * This takes a variable number of inputs and concatenate their patterns, and escapes string inputs to match it exactly * @example * exactly('fo?o', maybe('bar')) // => /fo\?o(?:bar)?/ * @argument inputs - arbitrary number of `string` or `Input`, where `string` will be escaped */ declare function exactly(...inputs: Inputs): Input, '', ''>, MapToGroups, MapToCapturedGroupsArr>; /** * Equivalent to `+` - this takes a variable number of inputs and marks them as repeatable, any number of times but at least once * @example * oneOrMore('foo', maybe('bar')) // => /(?:foo(?:bar)?)+/ * @argument inputs - arbitrary number of `string` or `Input`, where `string` will be escaped */ declare function oneOrMore, '', ''>>(...inputs: Inputs): Input, MapToGroups, MapToCapturedGroupsArr>; type Escape = T extends `${infer Start}${EscapeChar}${string}` ? Start extends `${string}${EscapeChar}${string}` ? never : T extends `${Start}${infer Char}${string}` ? Char extends EscapeChar ? T extends `${Start}${Char}${infer Rest}` ? `${Start}\\${Char}${Escape}` : never : never : never : T; type EscapeChar = Escape; type StripEscapes = T extends `${infer A}\\${infer B}` ? `${A}${B}` : T; type ExactEscapeChar = '.' | '*' | '+' | '?' | '^' | '$' | '{' | '}' | '(' | ')' | '|' | '[' | ']' | '/'; type GetValue = T extends string ? Escape : T extends Input ? R : never; interface Input { /** * this takes a variable number of inputs and adds them as new pattern to the current input, or you can use `and.referenceTo(groupName)` to adds a new pattern referencing to a named group * @example * exactly('foo').and('bar', maybe('baz')) // => /foobar(?:baz)?/ * @argument inputs - arbitrary number of `string` or `Input`, where `string` will be escaped */ and: { >(...inputs: I): Input<`${V}${Join, '', ''>}`, G | MapToGroups, [...C, ...CG]>; /** this adds a new pattern to the current input, with the pattern reference to a named group. */ referenceTo: (groupName: N) => Input<`${V}\\k<${N}>`, G, C>; }; /** * this takes a variable number of inputs and provides as an alternative to the current input * @example * exactly('foo').or('bar', maybe('baz')) // => /foo|bar(?:baz)?/ * @argument inputs - arbitrary number of `string` or `Input`, where `string` will be escaped */ or: >(...inputs: I) => Input<`(?:${V}|${Join, '', ''>})`, G | MapToGroups, [...C, ...CG]>; /** * this takes a variable number of inputs and activate a positive lookbehind. Make sure to check [browser support](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#browser_compatibility) as not all browsers support lookbehinds (notably Safari) * @example * exactly('foo').after('bar', maybe('baz')) // => /(?<=bar(?:baz)?)foo/ * @argument inputs - arbitrary number of `string` or `Input`, where `string` will be escaped */ after: >(...inputs: I) => Input<`(?<=${Join, '', ''>})${V}`, G | MapToGroups, [...CG, ...C]>; /** * this takes a variable number of inputs and activate a positive lookahead * @example * exactly('foo').before('bar', maybe('baz')) // => /foo(?=bar(?:baz)?)/ * @argument inputs - arbitrary number of `string` or `Input`, where `string` will be escaped */ before: >(...inputs: I) => Input<`${V}(?=${Join, '', ''>})`, G, [...C, ...CG]>; /** * these takes a variable number of inputs and activate a negative lookbehind. Make sure to check [browser support](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#browser_compatibility) as not all browsers support lookbehinds (notably Safari) * @example * exactly('foo').notAfter('bar', maybe('baz')) // => /(?>(...inputs: I) => Input<`(?, '', ''>})${V}`, G, [...CG, ...C]>; /** * this takes a variable number of inputs and activate a negative lookahead * @example * exactly('foo').notBefore('bar', maybe('baz')) // => /foo(?!bar(?:baz)?)/ * @argument inputs - arbitrary number of `string` or `Input`, where `string` will be escaped */ notBefore: >(...inputs: I) => Input<`${V}(?!${Join, '', ''>})`, G, [...C, ...CG]>; /** repeat the previous pattern an exact number of times */ times: { >(number: N): Input; /** specify that the expression can repeat any number of times, _including none_ */ any: >() => Input; /** specify that the expression must occur at least `N` times */ atLeast: >(number: N) => Input; /** specify that the expression must occur at most `N` times */ atMost: >(number: N) => Input; /** specify a range of times to repeat the previous pattern */ between: >(min: Min, max: Max) => Input; }; /** this defines the entire input so far as a named capture group. You will get type safety when using the resulting RegExp with `String.match()`. Alias for `groupedAs` */ as: (key: K) => Input${S})` : `(?<${K}>${V})`, G | K, [ V extends `(?:${infer S})` ? `(?<${K}>${S})` : `(?<${K}>${V})`, ...C ]>; /** this defines the entire input so far as a named capture group. You will get type safety when using the resulting RegExp with `String.match()` */ groupedAs: (key: K) => Input${S})` : `(?<${K}>${V})`, G | K, [ V extends `(?:${infer S})` ? `(?<${K}>${S})` : `(?<${K}>${V})`, ...C ]>; /** this capture the entire input so far as an anonymous group */ grouped: () => Input; /** this allows you to match beginning/ends of lines with `at.lineStart()` and `at.lineEnd()` */ at: { lineStart: () => Input<`^${V}`, G, C>; lineEnd: () => Input<`${V}$`, G, C>; }; /** this allows you to mark the input so far as optional */ optionally: >() => Input; toString: () => string; } interface CharInput extends Input<`[${T}]`> { orChar: ((chars: Or) => CharInput<`${T}${EscapeChar}`>) & CharInput; from: (charFrom: From, charTo: To) => CharInput<`${T}${EscapeChar}-${EscapeChar}`>; } type InputSource = S | Input; type MapToValues = T extends [ infer First, ...infer Rest extends InputSource[] ] ? First extends InputSource ? [GetValue, ...MapToValues] : [] : []; type MapToGroups = T extends [ infer First, ...infer Rest extends InputSource[] ] ? First extends Input ? K | MapToGroups : MapToGroups : never; type MapToCapturedGroupsArr = Count['length'] extends Inputs['length'] ? CapturedGroupsArr : Inputs[Count['length']] extends Input ? [CaptureGroups] extends [never] ? MapToCapturedGroupsArr : MapToUndefined extends true ? MapToCapturedGroupsArr : MapToCapturedGroupsArr : MapToCapturedGroupsArr; export { maybe as A, exactly as B, oneOrMore as C, type MapToStringCapturedBy as D, type Flag as F, type InputSource as I, type Join as J, type MagicRegExp as M, type StringCapturedBy as S, type UnionToTuple as U, type MagicRegExpMatchArray as a, type MapToValues as b, type MapToGroups as c, type MapToCapturedGroupsArr as d, caseInsensitive as e, dotAll as f, global as g, type Input as h, charIn as i, charNotIn as j, anyOf as k, char as l, multiline as m, word as n, wordChar as o, wordBoundary as p, digit as q, whitespace as r, sticky as s, letter as t, unicode as u, tab as v, withIndices as w, linefeed as x, carriageReturn as y, not as z };