@@ -133,19 +133,12 @@ Available `options` that can be passed to the constructor:
133
133
- ` parseNegative ` (boolean, default = false): Enables parsing negative ranges (eg ` (-10)-(-3) ` ).
134
134
- ` parseUnbounded ` (boolean, default = false): Enables parsing unbounded ranges (eg ` -5,10- ` ).
135
135
136
- The following methods have been removed:
137
-
138
- - ` appendRange(min: number, max: number): MultiRange ` Use ` append([[min, max]]) ` instead.
139
- - ` subtractRange(min: number, max: number): MultiRange ` Use ` subtract([[min, max]]) ` instead.
140
- - ` hasRange(min: number, max: number): boolean ` Use ` has([[min, max]]) ` instead.
141
- - ` isContinuous(): boolean ` Use ` segmentLength() === 1 ` instead.
142
-
143
136
144
137
### Unbounded Ranges (optional)
145
138
146
- You can use unbounded (or infinite) ranges.
147
- Parsing unbounded ranges are disabled by default,
148
- and you have to enable them via the ` parseUnbounded ` option parameter.
139
+ You can use unbounded (aka infinite) ranges.
140
+ Parsing unbounded ranges is disabled by default,
141
+ and you have to enable it via the ` parseUnbounded ` option parameter.
149
142
150
143
``` js
151
144
// The `parseUnbounded` option enables unbounded ranges.
@@ -163,7 +156,7 @@ const range6 = multirange([[-Infinity, Infinity]]); // all integers
163
156
```
164
157
165
158
Note that the ` parseUnbounded ` option only affects the way * string* initializers are parsed.
166
- You have to pass no option to create unbounded ranges using non-string initializers.
159
+ You do not have to pass any option to create unbounded ranges using non-string initializers.
167
160
Once ` parseUnbounded ` is enabled at the constructor,
168
161
subsequent chained methods will also correctly parse unbounded ranges.
169
162
@@ -178,9 +171,9 @@ console.log(unbounded('-').subtract('3-5,7,11-') + ''); // '-2,6,8-10'
178
171
console .log (unbounded (' -5,10-' ).has (' -3,20' )); // true
179
172
180
173
// Intersection is especially useful to "trim" any unbounded ranges:
181
- var userInput = ' -10,15-20,90-' ;
182
- var pagesInMyDoc = [[1 , 100 ]]; // '1-100'
183
- var pagesToPrint = unbounded (userInput).intersect (pagesInMyDoc);
174
+ const userInput = ' -10,15-20,90-' ;
175
+ const pagesInMyDoc = [[1 , 100 ]]; // '1-100'
176
+ const pagesToPrint = unbounded (userInput).intersect (pagesInMyDoc);
184
177
console .log (pagesToPrint .toString ()); // prints '1-10,15-20,90-100'
185
178
```
186
179
@@ -203,6 +196,9 @@ mr1.append([[-4, -2]]); // -4 to -2
203
196
console .log (mr1 + ' ' ); // prints '(-5)-0'
204
197
```
205
198
199
+ Note that the ` parseNegative ` option only affects the way string initializers are parsed.
200
+ You do not have to pass any option to create negative ranges using non-string initializers.
201
+
206
202
Once ` parseNegative ` is enabled at the constructor,
207
203
subsequent chained methods will also recognize and parse negative ranges.
208
204
@@ -211,18 +207,19 @@ const mr2 = multirange('(-5)', { parseNegative: true }).append('(-3)');
211
207
console .log (mr2); // prints '(-5),(-3)'
212
208
```
213
209
210
+
214
211
### Iteration
215
212
216
- ** ES2015 (ES6) iterator** : If ` Symbol.iterator ` is defined in the runtime,
217
- you can simply iterate over the instance like this:
213
+ ** ES2015 (ES6) iterator** : If ` Symbol.iterator ` is defined
214
+ (either natively or by a polyfill), you can simply iterate over the instance like this:
218
215
219
216
``` js
220
- for (let page of multirange (' 2,5-7' )) {
217
+ for (const page of multirange (' 2,5-7' )) {
221
218
console .log (page);
222
- } // prints 2, 5, 6, 7
219
+ } // prints 2, 5, 6 and 7
223
220
224
221
// Instead of calling toArray() ...
225
- var arr = [... multirange (' 2,5-7' )]; // array spreading
222
+ const arr = [... multirange (' 2,5-7' )]; // array spreading
226
223
// arr becomes [2, 5, 6, 7]
227
224
```
228
225
@@ -237,14 +234,15 @@ while (!(page = it.next()).done) {
237
234
}
238
235
```
239
236
237
+
240
238
## TypeScript Definition File
241
239
242
240
This library comes with a TypeScript definition file. Starting from TypeScript 1.6,
243
241
The TypeScript compiler can find this definition file automatically.
244
242
245
243
The definition file only contains declarations that are compatible with ES5.
246
- If your TypeScript project targets ES6 ( ` --target ES6 ` ) and uses iterators,
247
- add the following snippet somewhere in your project (e.g., "typings" directory)
244
+ If your TypeScript project needs support for iterators,
245
+ add the following snippet somewhere in your project (eg "typings" directory)
248
246
to avoid compile-time errors.
249
247
250
248
``` ts
@@ -255,9 +253,15 @@ declare module "multi-integer-range" {
255
253
}
256
254
```
257
255
256
+ Note that downlevel iteration for ` --target=es5 ` needs a polyfill for symbols and
257
+ ` --downlevelIteration ` compile flag, available since TypeScript 2.3.
258
+ If these bothers you, you can always manually use ` getIterator ` as described above.
259
+
260
+
258
261
## Changelog
259
262
260
- See [ the relase page on GitHub] ( https://github.com/smikitky/node-multi-integer-range/releases ) .
263
+ See [ the release page on GitHub] ( https://github.com/smikitky/node-multi-integer-range/releases ) .
264
+
261
265
262
266
## Development
263
267
@@ -279,10 +283,12 @@ However, this library is not intended to be efficient
279
283
with a heavily fragmentated set of integers which are scarcely continuous
280
284
(e.g., random 10000 integers between 1 to 1000000).
281
285
286
+
282
287
## Author
283
288
284
289
Soichiro Miki (https://github.com/smikitky )
285
290
291
+
286
292
## License
287
293
288
294
MIT
0 commit comments