File: index.d.ts

package info (click to toggle)
node-regex-not 1.0.2%2B~1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 136 kB
  • sloc: javascript: 81; makefile: 2
file content (103 lines) | stat: -rwxr-xr-x 3,491 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Type definitions for regex-not 1.0
// Project: https://github.com/jonschlinkert/regex-not
// Definitions by: BendingBender <https://github.com/bendingbender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

export = regexNot;

/**
 * Create a javascript regular expression for matching everything except for the given string.
 *
 * ### Strict matching ###
 * By default, the returned regex is for strictly (not) matching the exact given pattern
 * (in other words, "match this string if it does NOT exactly equal `foo`").
 *
 * @example
 * import not = require('regex-not');
 *
 * console.log(not('foo'));         //=> /^(?:(?!^(?:foo)$).)+$/
 * console.log(re.test('foo'));     //=> false
 * console.log(re.test('bar'));     //=> true
 * console.log(re.test('foobar'));  //=> true
 * console.log(re.test('barfoo'));  //=> true
 */
declare function regexNot(str: string, options?: regexNot.Options): RegExp;

declare namespace regexNot {
    /**
     * @returns A string to allow you to create your own regex.
     *
     * @example
     * import not = require('regex-not');
     *
     * console.log(not.create('foo'));
     * //=> '^(?:(?!^(?:foo)$).)+$'
     */
    function create(str: string, options?: Options): string;

    interface Options {
        /**
         * You can relax strict matching by setting `contains` to `true` (in other words,
         * "match this string if it does NOT contain `foo`").
         *
         * @default false
         *
         * @example
         * import not = require('regex-not');
         *
         * const re = not('foo', {contains: true});
         * console.log(re.test('foo'));     //=> false
         * console.log(re.test('bar'));     //=> true
         * console.log(re.test('foobar'));  //=> false
         * console.log(re.test('barfoo'));  //=> false
         */
        contains?: boolean;

        /**
         * Controls whether the start of input anchor (`^`) should be generated for the pattern.
         *
         * @default true
         *
         * @example
         * import not = require('regex-not');
         *
         * const re = not('foo');                     // => '^(?:(?!^(?:foo)$).)+$'
         * const re = not('foo', {strictOpen: '*'});  // => '(?:(?!^(?:foo)$).)+$'
         */
        strictOpen?: boolean;

        /**
         * Controls whether the end of input anchor (`$`) should be generated for the pattern.
         *
         * @default true
         *
         * @example
         * import not = require('regex-not');
         *
         * const re = not('foo');                      // => '^(?:(?!^(?:foo)$).)+$'
         * const re = not('foo', {strictClose: '*'});  // => '^(?:(?!^(?:foo)$).)+'
         */
        strictClose?: boolean;

        /**
         * Controls the outermost repetition modifier in the generated RegExp.
         *
         * @default '+'
         *
         * @example
         * import not = require('regex-not');
         *
         * const re = not('foo');                  // => '^(?:(?!^(?:foo)$).)+$'
         * const re = not('foo', {endChar: '*'});  // => '^(?:(?!^(?:foo)$).)*$'
         */
        endChar?: string;

        /**
         * Throw an error when a potentially catastrophic exponential-time regular expression is detected.
         * See [strict-regex](https://github.com/davisjam/safe-regex) for more details and potential implications.
         *
         * @default false
         */
        safe?: boolean;
    }
}