UNPKG

regops

Version:

A small javascript library for performing operations on regular expressions

32 lines (31 loc) 2.63 kB
/** If necessary, put non-capturing brackets around a regex source string. */ declare function autoBracket(str: string): string; /** Concatenate a list a of regular expressions. */ declare function concat(...operands: (RegExp | string | null)[]): RegExp; /** Concatenate a list of regular expressions with a single-space (' ') delimiter.*/ declare function concatSpaced(...operands: (RegExp | string | null)[]): RegExp; /** Combine regular expressions with OR (|) operator. */ declare function or(...operands: (RegExp | string | null)[]): RegExp; /** Apply OPTIONAL (?) operator to a regular expressions. */ declare function optional(operand: RegExp | string): string; /** Apply Kleene closure (*) operator to a regular expression. */ declare function kleene(operand: RegExp | string): string; /** Apply Kleene closure (*) operator to a regular expression, delimiting repetitions with a single-space (' ') */ declare function kleeneSpaced(operand: RegExp | string): RegExp; /** Apply Kleene repetitions of a regular expression with some specified delimiter. */ declare function kleeneJoin(operand: RegExp | string, delimiter: string): RegExp; /** Create a "polite list" (form: X, X, X and X) using Kleene closure to allow any number of items. */ declare function kleenePoliteList(...operands: (RegExp | string)[]): RegExp; /** Concatenate a list of regular expressions with optional (?) modifiers. */ declare function optionalConcatSpaced(stem: RegExp | string, ...optionalAppendages: (RegExp | string | null)[]): RegExp; /** Concatenate an item with itself any number of times (using kleene closure *) using a single-space (' ') as a delimiter. */ declare function kleeneConcatSpaced(stem: RegExp | string, ...optionalAppendages: (RegExp | string | null)[]): RegExp; /** Add ^ and $ markers either side of a regular expression so that it must match an entire string. */ declare function whole(operand: RegExp | string): RegExp; /** Add a ^ marker at the beginning of a regular expression, so that it must match the beginning of a string. */ declare function initial(operand: RegExp | string): RegExp; /** Add a $ marker at the end of a regular expression, so that it matches the end of a string. */ declare function terminal(operand: RegExp | string): RegExp; /** Surround a regular expression with capturing parentheses, optionally specifying a group name. */ declare function capture(operand: RegExp | string, groupName: string): RegExp; export { concat, concatSpaced, or, optional, kleene, kleeneJoin, kleeneSpaced, kleenePoliteList, kleeneConcatSpaced, optionalConcatSpaced, autoBracket, whole, initial, terminal, capture, };