UNPKG

1.67 kBTypeScriptView Raw
1declare namespace toRegex {
2 interface Options {
3 /**
4 * Generate a regex that will match any string that contains the given
5 * pattern. By default, regex is strict will only return true for
6 * exact matches.
7 */
8 contains?: boolean;
9
10 /**
11 * Create a regex that will match everything except the given pattern.
12 */
13 negate?: boolean;
14
15 /**
16 * Adds the i flag, to enable case-insensitive matching.
17 */
18 nocase?: boolean;
19
20 /**
21 * Define the flags you want to use on the generated regex.
22 */
23 flags?: string;
24
25 /**
26 * Generated regex is cached based on the provided string and options.
27 * As a result, runtime compilation only happens once per pattern (as
28 * long as options are also the same), which can result in dramatic
29 * speed improvements.
30 *
31 * This also helps with debugging, since adding options and pattern
32 * are added to the generated regex.
33 * @default true
34 */
35 cache?: boolean;
36
37 /**
38 * Check the generated regular expression with safe-regex and throw an
39 * error if the regex is potentially unsafe.
40 */
41 safe?: boolean;
42 }
43
44 /**
45 * Create a regular expression from the given `pattern` string.
46 */
47 function makeRe(pattern: string | RegExp, options?: Options): RegExp;
48}
49
50/**
51 * Create a regular expression from the given `patterns` string.
52 */
53declare function toRegex(patterns: string | readonly string[] | RegExp, options?: toRegex.Options): RegExp;
54
55export = toRegex;