Skip to content

Commit 001c1c1

Browse files
committed
Documentation
1 parent 2391923 commit 001c1c1

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

README.md

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,12 @@ Available `options` that can be passed to the constructor:
133133
- `parseNegative` (boolean, default = false): Enables parsing negative ranges (eg `(-10)-(-3)`).
134134
- `parseUnbounded` (boolean, default = false): Enables parsing unbounded ranges (eg `-5,10-`).
135135

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-
143136

144137
### Unbounded Ranges (optional)
145138

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.
149142

150143
```js
151144
// The `parseUnbounded` option enables unbounded ranges.
@@ -163,7 +156,7 @@ const range6 = multirange([[-Infinity, Infinity]]); // all integers
163156
```
164157

165158
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.
167160
Once `parseUnbounded` is enabled at the constructor,
168161
subsequent chained methods will also correctly parse unbounded ranges.
169162

@@ -178,9 +171,9 @@ console.log(unbounded('-').subtract('3-5,7,11-') + ''); // '-2,6,8-10'
178171
console.log(unbounded('-5,10-').has('-3,20')); // true
179172

180173
// 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);
184177
console.log(pagesToPrint.toString()); // prints '1-10,15-20,90-100'
185178
```
186179

@@ -203,6 +196,9 @@ mr1.append([[-4, -2]]); // -4 to -2
203196
console.log(mr1 + ''); // prints '(-5)-0'
204197
```
205198

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+
206202
Once `parseNegative` is enabled at the constructor,
207203
subsequent chained methods will also recognize and parse negative ranges.
208204

@@ -211,18 +207,19 @@ const mr2 = multirange('(-5)', { parseNegative: true }).append('(-3)');
211207
console.log(mr2); // prints '(-5),(-3)'
212208
```
213209

210+
214211
### Iteration
215212

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:
218215

219216
```js
220-
for (let page of multirange('2,5-7')) {
217+
for (const page of multirange('2,5-7')) {
221218
console.log(page);
222-
} // prints 2, 5, 6, 7
219+
} // prints 2, 5, 6 and 7
223220

224221
// Instead of calling toArray() ...
225-
var arr = [...multirange('2,5-7')]; // array spreading
222+
const arr = [...multirange('2,5-7')]; // array spreading
226223
// arr becomes [2, 5, 6, 7]
227224
```
228225

@@ -237,14 +234,15 @@ while (!(page = it.next()).done) {
237234
}
238235
```
239236

237+
240238
## TypeScript Definition File
241239

242240
This library comes with a TypeScript definition file. Starting from TypeScript 1.6,
243241
The TypeScript compiler can find this definition file automatically.
244242

245243
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)
248246
to avoid compile-time errors.
249247

250248
```ts
@@ -255,9 +253,15 @@ declare module "multi-integer-range" {
255253
}
256254
```
257255

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+
258261
## Changelog
259262

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+
261265

262266
## Development
263267

@@ -279,10 +283,12 @@ However, this library is not intended to be efficient
279283
with a heavily fragmentated set of integers which are scarcely continuous
280284
(e.g., random 10000 integers between 1 to 1000000).
281285

286+
282287
## Author
283288

284289
Soichiro Miki (https://github.com/smikitky)
285290

291+
286292
## License
287293

288294
MIT

0 commit comments

Comments
 (0)