UNPKG

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