UNPKG

3.49 kBTypeScriptView Raw
1// Type definitions for regex-not 1.0
2// Project: https://github.com/jonschlinkert/regex-not
3// Definitions by: BendingBender <https://github.com/bendingbender>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
6export = regexNot;
7
8/**
9 * Create a javascript regular expression for matching everything except for the given string.
10 *
11 * ### Strict matching ###
12 * By default, the returned regex is for strictly (not) matching the exact given pattern
13 * (in other words, "match this string if it does NOT exactly equal `foo`").
14 *
15 * @example
16 * import not = require('regex-not');
17 *
18 * console.log(not('foo')); //=> /^(?:(?!^(?:foo)$).)+$/
19 * console.log(re.test('foo')); //=> false
20 * console.log(re.test('bar')); //=> true
21 * console.log(re.test('foobar')); //=> true
22 * console.log(re.test('barfoo')); //=> true
23 */
24declare function regexNot(str: string, options?: regexNot.Options): RegExp;
25
26declare namespace regexNot {
27 /**
28 * @returns A string to allow you to create your own regex.
29 *
30 * @example
31 * import not = require('regex-not');
32 *
33 * console.log(not.create('foo'));
34 * //=> '^(?:(?!^(?:foo)$).)+$'
35 */
36 function create(str: string, options?: Options): string;
37
38 interface Options {
39 /**
40 * You can relax strict matching by setting `contains` to `true` (in other words,
41 * "match this string if it does NOT contain `foo`").
42 *
43 * @default false
44 *
45 * @example
46 * import not = require('regex-not');
47 *
48 * const re = not('foo', {contains: true});
49 * console.log(re.test('foo')); //=> false
50 * console.log(re.test('bar')); //=> true
51 * console.log(re.test('foobar')); //=> false
52 * console.log(re.test('barfoo')); //=> false
53 */
54 contains?: boolean;
55
56 /**
57 * Controls whether the start of input anchor (`^`) should be generated for the pattern.
58 *
59 * @default true
60 *
61 * @example
62 * import not = require('regex-not');
63 *
64 * const re = not('foo'); // => '^(?:(?!^(?:foo)$).)+$'
65 * const re = not('foo', {strictOpen: '*'}); // => '(?:(?!^(?:foo)$).)+$'
66 */
67 strictOpen?: boolean;
68
69 /**
70 * Controls whether the end of input anchor (`$`) should be generated for the pattern.
71 *
72 * @default true
73 *
74 * @example
75 * import not = require('regex-not');
76 *
77 * const re = not('foo'); // => '^(?:(?!^(?:foo)$).)+$'
78 * const re = not('foo', {strictClose: '*'}); // => '^(?:(?!^(?:foo)$).)+'
79 */
80 strictClose?: boolean;
81
82 /**
83 * Controls the outermost repetition modifier in the generated RegExp.
84 *
85 * @default '+'
86 *
87 * @example
88 * import not = require('regex-not');
89 *
90 * const re = not('foo'); // => '^(?:(?!^(?:foo)$).)+$'
91 * const re = not('foo', {endChar: '*'}); // => '^(?:(?!^(?:foo)$).)*$'
92 */
93 endChar?: string;
94
95 /**
96 * Throw an error when a potentially catastrophic exponential-time regular expression is detected.
97 * See [strict-regex](https://github.com/davisjam/safe-regex) for more details and potential implications.
98 *
99 * @default false
100 */
101 safe?: boolean;
102 }
103}