UNPKG

5.66 kBTypeScriptView Raw
1// Type definitions for regenerate 1.4
2// Project: https://github.com/mathiasbynens/regenerate
3// Definitions by: ExE Boss <https://github.com/ExE-Boss>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5// TypeScript Version: 3.7
6
7export as namespace regenerate;
8export = regenerate;
9
10type RegenerateArgValue = string | number | regenerate;
11type RegenerateArgValueOrArray = RegenerateArgValue | readonly RegenerateArgValueOrArray[];
12
13/**
14 * The main Regenerate constructor. Calling this function creates a new set that gets a chainable API.
15 *
16 * Any arguments passed to `regenerate()` will be added to the set right away.
17 *
18 * Both code points (numbers) and symbols (strings consisting of a single Unicode symbol)
19 * are accepted, as well as arrays containing values of these types.
20 *
21 * It’s also possible to pass in a Regenerate instance.
22 * Doing so adds all code points in that instance to the new set.
23 */
24declare function regenerate(...values: readonly RegenerateArgValueOrArray[]): regenerate;
25declare class regenerate {
26 constructor(...values: readonly RegenerateArgValueOrArray[]);
27
28 /**
29 * Any arguments passed to `add()` are added to the set.
30 *
31 * Both code points (numbers) and symbols (strings consisting of a single Unicode symbol)
32 * are accepted, as well as arrays containing values of these types.
33 *
34 * It’s also possible to pass in a Regenerate instance.
35 * Doing so adds all code points in that instance to the current set.
36 */
37 add(value: RegenerateArgValueOrArray, ...rest: readonly RegenerateArgValueOrArray[]): this;
38
39 /**
40 * Any arguments passed to `remove()` are removed from the set.
41 *
42 * Both code points (numbers) and symbols (strings consisting of a single Unicode symbol)
43 * are accepted, as well as arrays containing values of these types.
44 *
45 * It’s also possible to pass in a Regenerate instance.
46 * Doing so removes all code points in that instance from the current set.
47 */
48 remove(value: RegenerateArgValueOrArray, ...rest: readonly RegenerateArgValueOrArray[]): this;
49
50 /**
51 * Adds a range of code points from `start` to `end` (inclusive) from the set.
52 *
53 * Both code points (numbers) and symbols (strings consisting of a single Unicode symbol) are accepted.
54 *
55 * @param start The start of the range to add.
56 * @param end The end of the range to add.
57 */
58 addRange(start: string | number, end: string | number): this;
59
60 /**
61 * Removes a range of code points from `start` to `end` (inclusive) from the set.
62 *
63 * Both code points (numbers) and symbols (strings consisting of a single Unicode symbol) are accepted.
64 *
65 * @param start The start of the range to remove.
66 * @param end The end of the range to remove.
67 */
68 removeRange(start: string | number, end: string | number): this;
69
70 /**
71 * Removes any code points from the set that are not present in both the set and the given `codePoints` array.
72 *
73 * @param argument must be an array of numeric code point values, i.e. numbers, or a Regenerate instance.
74 */
75 intersection(argument: regenerate | readonly number[]): this;
76
77 /**
78 * Returns `true` if the given value is part of the set, and `false` otherwise.
79 *
80 * Both code points (numbers) and symbols (strings consisting of a single Unicode symbol) are accepted.
81 *
82 * @param codePoint The codepoint to check for
83 */
84 contains(codePoint: string | number): boolean;
85
86 /**
87 * Returns a clone of the current code point set.
88 *
89 * Any actions performed on the clone won’t mutate the original set.
90 */
91 clone(): regenerate;
92
93 /**
94 * Returns a regular expression that matches all the symbols
95 * mapped to the code points within the set.
96 *
97 * @param flags The `flags` parameter to be passed to the regular expression.
98 */
99 toRegExp(flags?: string): RegExp;
100
101 /**
102 * Returns a string representing (part of) a regular expression that matches
103 * all the symbols mapped to the code points within the set.
104 *
105 * @param options The optional `options` object
106 */
107 toString(options?: regenerate.ToStringOptions): string;
108
109 /**
110 * Returns a sorted array of unique code points in the set.
111 *
112 * @alias valueOf
113 */
114 toArray(): number[];
115
116 /**
117 * Returns a sorted array of unique code points in the set.
118 *
119 * @alias toArray
120 */
121 valueOf(): number[];
122
123 /** A string representing the semantic version number. */
124 static readonly version: string;
125}
126
127declare namespace regenerate {
128 interface ToStringOptions {
129 /**
130 * When `bmpOnly` is set to `true`, the output matches surrogates individually,
131 * regardless of whether they’re lone surrogates or just part of a surrogate pair.
132 *
133 * This simplifies the output, but it can only be used in case you’re certain
134 * the strings it will be used on don’t contain any astral symbols.
135 */
136 readonly bmpOnly?: boolean | undefined;
137
138 /**
139 * When `hasUnicodeFlag` is set to `true`, the output makes use
140 * of Unicode code point escapes (`\u{…}`) where applicable.
141 *
142 * This simplifies the output at the cost of compatibility and portability,
143 * since it means the output can only be used as a pattern in a regular expression
144 * with the ES6 `u` flag enabled.
145 *
146 * @see https://mathiasbynens.be/notes/es6-unicode-regex
147 */
148 readonly hasUnicodeFlag?: boolean | undefined;
149 }
150}