@@ -26,12 +26,12 @@ export type Options = {
26
26
* Parses a string and creates a new MultiIntegerRange array.
27
27
* This is the default parser, but you can create and use another parser
28
28
* to suit your needs as long as it produces a normalized array of `Range`s.
29
- * @param data The string to parse.
30
- * @param options Options to modify the parsing behavior.
29
+ * @param data - The string to parse.
30
+ * @param options - Options to modify the parsing behavior.
31
31
* @returns A new normalized MultiIntegerRange.
32
32
* @example
33
- * parse('1-10'); //=> [[1, 10]]
34
- * parse(' 10-, 7', { parseUnbounded: true }); //=> [[7, 7], [10, Infinity]]
33
+ * parse('1-10'); // [[1, 10]]
34
+ * parse(' 10-, 7', \ { parseUnbounded: true \ }); // [[7, 7], [10, Infinity]]
35
35
*/
36
36
export const parse = ( data : string , options ?: Options ) : MIR => {
37
37
const { parseNegative = false , parseUnbounded = false } = options || { } ;
@@ -78,13 +78,13 @@ export const parse = (data: string, options?: Options): MIR => {
78
78
/**
79
79
* Takes a number or an unsorted array of ranges,
80
80
* and returns a new normalized MultiIntegerRange.
81
- * @param data A number or an unsorted array, e.g., `[[7, 5], 1]`.
81
+ * @param data - A number or an unsorted array, e.g., `[[7, 5], 1]`.
82
82
* @returns Normalized array, e.g., `[[1, 1], [5, 7]]`.
83
83
* @example
84
- * normalize(5); //=> [[5, 5]]
85
- * normalize([1, 8]) //=> [[1, 1], [8, 8]]
86
- * normalize([[1, 8]]) //=> [[1, 8]]
87
- * normalize([[1, Infinity]]) //=> [[1, Infinity]]
84
+ * normalize(5); // [[5, 5]]
85
+ * normalize([1, 8]) // [[1, 1], [8, 8]]
86
+ * normalize([[1, 8]]) // [[1, 8]]
87
+ * normalize([[1, Infinity]]) // [[1, Infinity]]
88
88
*/
89
89
export const normalize = ( data ?: ( number | Range ) [ ] | number ) : MIR => {
90
90
const result : Range [ ] = [ ] ;
@@ -116,13 +116,13 @@ export const normalize = (data?: (number | Range)[] | number): MIR => {
116
116
/**
117
117
* Takes any supported data and returns a normalized MultiIntegerRange.
118
118
* Conditionally calls either `parse` or `normalize` under the hood.
119
- * This is an equivalent of "initializer" constructor of version <= 4.
120
- * @param data Anything understood by either `parse` or `normalize`.
121
- * @param options Parse options passed to `parse`.
119
+ * This is an equivalent of "initializer" constructor of version ≤ 4.
120
+ * @param data - Anything understood by either `parse` or `normalize`.
121
+ * @param options - Parse options passed to `parse`.
122
122
* @returns A new normalized MultiIntegerRange.
123
123
* @example
124
- * initialize(5); //=> [[5, 5]]
125
- * initialize('2-8'); //=> [[2,8]]
124
+ * initialize(5); // [[5, 5]]
125
+ * initialize('2-8'); // [[2,8]]
126
126
*/
127
127
export const initialize = (
128
128
data ?: ( number | Range ) [ ] | number | string ,
@@ -133,8 +133,8 @@ export const initialize = (
133
133
134
134
/**
135
135
* Calculates the union of two specified ranges.
136
- * @param a Range A.
137
- * @param b Range B.
136
+ * @param a - Range A.
137
+ * @param b - Range B.
138
138
* @private
139
139
* @returns Union of `a` and `b`.
140
140
* Returns `null` if `a` and `b` do not touch nor intersect.
@@ -150,7 +150,8 @@ const calcUnion = (a: Range, b: Range): Range | null => {
150
150
* Determines how the given range overlaps or touches the existing ranges.
151
151
* This is a helper method that calculates how an append/subtract operation
152
152
* affects the existing range members.
153
- * @param target The range array to test.
153
+ * @private
154
+ * @param target - The range array to test.
154
155
* @returns An object containing information about how the given range
155
156
* overlaps or touches this instance.
156
157
*/
@@ -223,11 +224,11 @@ const findOverlap = (
223
224
224
225
/**
225
226
* Appends two MultiIntegerRange's.
226
- * @param a The first value.
227
- * @param b The second value.
227
+ * @param a - The first value.
228
+ * @param b - The second value.
228
229
* @example
229
- * append([[1, 5]], [[3, 8], [10, 15]]); //=> 1-8,10-15
230
- * append([[5, Infinity ]], [[-Infinity, 2]]); //=> -2,5-
230
+ * append([[1, 5]], [[3, 8], [10, 15]]); // [[1, 8], [10, 15]]
231
+ * append([[5, 9 ]], [[-Infinity, 2]]); // [[-Infinity, 2], [5, 9]]
231
232
*/
232
233
export const append = ( a : MIR , b : MIR ) : MIR => {
233
234
let result = a . slice ( 0 ) ;
@@ -240,11 +241,11 @@ export const append = (a: MIR, b: MIR): MIR => {
240
241
241
242
/**
242
243
* Subtracts the second value from the first value.
243
- * @param a The value to be subtracted.
244
- * @param b The value to subtract.
244
+ * @param a - The value to be subtracted.
245
+ * @param b - The value to subtract.
245
246
* @example
246
- * subtract([[1, 7]], [[2, 4]]); //=> 1,5-7
247
- * subtract([[-Infinity, Infinity]], [[2, 4]]); //=> -1,5-
247
+ * subtract([[1, 7]], [[2, 4]]); // [[1, 1], [5, 7]]
248
+ * subtract([[-Infinity, Infinity]], [[2, 4]]); // [[-Infinity, 1], [5, Infinity]]
248
249
*/
249
250
export const subtract = ( a : MIR , b : MIR ) : MIR => {
250
251
let result = a . slice ( 0 ) ;
@@ -266,13 +267,13 @@ export const subtract = (a: MIR, b: MIR): MIR => {
266
267
267
268
/**
268
269
* Calculates the intersection (common integers) of the two MultiIntegerRange's.
269
- * @param a The first value.
270
- * @param b The second value.
270
+ * @param a - The first value.
271
+ * @param b - The second value.
271
272
* @returns A new MultiIntegerRange containing all integers
272
273
* that belong to both `a` and `b`.
273
274
* @example
274
- * intersect([[2, 5]], [[4, 9]]); //=> 4-5
275
- * intersect([[5, 10]], [[-Infinity, Infinity]]); //=> 5-10
275
+ * intersect([[2, 5]], [[4, 9]]); // [[4, 5]]
276
+ * intersect([[5, 10]], [[-Infinity, Infinity]]); // [[5, 10]]
276
277
*/
277
278
export const intersect = ( a : MIR , b : MIR ) : MIR => {
278
279
const result : Range [ ] = [ ] ;
@@ -296,12 +297,12 @@ export const intersect = (a: MIR, b: MIR): MIR => {
296
297
297
298
/**
298
299
* Checks if `a` contains or is equal to `b` (a ⊇ b).
299
- * @param a The value that possibly contains `b`.
300
- * @param b The value that is possibly contained by `a`.
300
+ * @param a - The value that possibly contains `b`.
301
+ * @param b - The value that is possibly contained by `a`.
301
302
* @returns True if `b` is a subset of `a`.
302
303
* @example
303
- * has([[0, 100]], [[2, 10]]) //=> true
304
- * has([[2, 10]], [[0, 100]]) //=> false
304
+ * has([[0, 100]], [[2, 10]]) // true
305
+ * has([[2, 10]], [[0, 100]]) // false
305
306
*/
306
307
export const has = ( a : MIR , b : MIR ) : boolean => {
307
308
const s = 0 ;
@@ -320,11 +321,11 @@ export const has = (a: MIR, b: MIR): boolean => {
320
321
321
322
/**
322
323
* Calculates how many integers are included in the given MultiIntegerRange.
323
- * @param data The value to calculate the length on.
324
+ * @param data - The value to calculate the length on.
324
325
* @returns The number of integers contained in `data`. May be `Infinity`.
325
326
* @example
326
- * length([[1, 3], [8, 10]]); //=> 6
327
- * length([[1, Infinity]]); //=> Infinity
327
+ * length([[1, 3], [8, 10]]); // 6
328
+ * length([[1, Infinity]]); // Infinity
328
329
*/
329
330
export const length = ( data : MIR ) : number => {
330
331
if ( isUnbounded ( data ) ) return Infinity ;
@@ -335,12 +336,12 @@ export const length = (data: MIR): number => {
335
336
336
337
/**
337
338
* Checks if the data contains an unbounded (aka inifinite) range.
338
- * @param data The value to check.
339
+ * @param data - The value to check.
339
340
* @returns True if `data` is unbounded.
340
341
* @example
341
- * isUnbounded([[1, Infinity]]); //=> true
342
- * isUnbounded([[-Infinity, 4]]); //=> true
343
- * isUnbounded([[7, 9]]); //=> false
342
+ * isUnbounded([[1, Infinity]]); // true
343
+ * isUnbounded([[-Infinity, 4]]); // true
344
+ * isUnbounded([[7, 9]]); // false
344
345
*/
345
346
export const isUnbounded = ( data : MIR ) : boolean => {
346
347
return (
@@ -351,12 +352,12 @@ export const isUnbounded = (data: MIR): boolean => {
351
352
352
353
/**
353
354
* Checks if the two values are the same.
354
- * @param a The first value to compare.
355
- * @param b The second value to compare.
355
+ * @param a - The first value to compare.
356
+ * @param b - The second value to compare.
356
357
* @returns True if `a` and `b` have the same range data.
357
358
* @example
358
- * equals([[1, 5], [7, 8]], [[1, 5], [7, 8]]); //=> true
359
- * equals([[1, 5]], [[2, 7]]); //=> false
359
+ * equals([[1, 5], [7, 8]], [[1, 5], [7, 8]]); // true
360
+ * equals([[1, 5]], [[2, 7]]); // false
360
361
*/
361
362
export const equals = ( a : MIR , b : MIR ) : boolean => {
362
363
if ( a === b ) return true ;
@@ -369,12 +370,12 @@ export const equals = (a: MIR, b: MIR): boolean => {
369
370
370
371
/**
371
372
* Returns the minimum integer of the given MultiIntegerRange.
372
- * @param data The value.
373
+ * @param data - The value.
373
374
* @returns The minimum integer. May be `undefined` of `-Infinity`.
374
375
* @example
375
- * min([[2, 5], [8, 10]]); //=> 2
376
- * min([[-Infinity, 0]]); //=> -Infinity
377
- * min([]); //=> undefined
376
+ * min([[2, 5], [8, 10]]); // 2
377
+ * min([[-Infinity, 0]]); // -Infinity
378
+ * min([]); // undefined
378
379
*/
379
380
export const min = ( data : MIR ) : number | undefined => {
380
381
if ( data . length === 0 ) return undefined ;
@@ -383,12 +384,12 @@ export const min = (data: MIR): number | undefined => {
383
384
384
385
/**
385
386
* Returns the maximum integer of the given MultiIntegerRange.
386
- * @param data The value.
387
+ * @param data - The value.
387
388
* @returns The minimum integer. May be `undefined` of `Infinity`.
388
389
* @example
389
- * max([[2, 5], [8, 10]]); //=> 10
390
- * max([[3, Infinity]]); //=> Infinity
391
- * max([]); //=> undefined
390
+ * max([[2, 5], [8, 10]]); // 10
391
+ * max([[3, Infinity]]); // Infinity
392
+ * max([]); // undefined
392
393
*/
393
394
export const max = ( data : MIR ) : number | undefined => {
394
395
if ( data . length === 0 ) return undefined ;
@@ -397,11 +398,11 @@ export const max = (data: MIR): number | undefined => {
397
398
398
399
/**
399
400
* Returns all but the minimum integer.
400
- * @param data The value.
401
+ * @param data - The value.
401
402
* @returns A new MultiIntegerRange which is almost the same as `data` but with
402
403
* its minimum integer removed.
403
404
* @example
404
- * tail([[2, 5], [8, 10]]); //=> 3-5,8-10
405
+ * tail([[2, 5], [8, 10]]); // [[3, 5], [8, 10]]
405
406
*/
406
407
export const tail = ( data : MIR ) : MIR => {
407
408
const m = min ( data ) ;
@@ -415,11 +416,11 @@ export const tail = (data: MIR): MIR => {
415
416
416
417
/**
417
418
* Returns all but the maximum integer.
418
- * @param data The value.
419
+ * @param data - The value.
419
420
* @returns A new MultiIntegerRange which is almost the same as `data` but with
420
421
* its maximum integer removed.
421
422
* @example
422
- * init([[2, 5], [8, 10]]); //=> 2-5,8-9
423
+ * init([[2, 5], [8, 10]]); // [[2, 5], [8, 9]]
423
424
*/
424
425
export const init = ( data : MIR ) : MIR => {
425
426
const m = max ( data ) ;
@@ -433,9 +434,9 @@ export const init = (data: MIR): MIR => {
433
434
434
435
/**
435
436
* Returns the string respresentation of the given MultiIntegerRange.
436
- * @param data The value to stringify.
437
+ * @param data - The value to stringify.
437
438
* @example
438
- * stringify([[3, 5], [7, Infinity]]); //=> '3-5,7-'
439
+ * stringify([[3, 5], [7, Infinity]]); // '3-5,7-'
439
440
*/
440
441
export const stringify = ( data : MIR ) : string => {
441
442
const wrap = ( i : number ) => ( i >= 0 ? String ( i ) : `(${ i } )` ) ;
@@ -462,9 +463,9 @@ export const stringify = (data: MIR): string => {
462
463
* Builds a flattened array of integers.
463
464
* Note that this may be slow and memory-consuming for large ranges.
464
465
* Consider using the iterator whenever possible.
465
- * @param data The value to build an array on.
466
+ * @param data - The value to build an array on.
466
467
* @example
467
- * flatten([[-1, 1], [7, 9]]); //=> [-1, 0, 1, 7, 8, 9]
468
+ * flatten([[-1, 1], [7, 9]]); // [-1, 0, 1, 7, 8, 9]
468
469
*/
469
470
export const flatten = ( data : MIR ) : number [ ] => {
470
471
if ( isUnbounded ( data ) ) {
@@ -482,10 +483,10 @@ export const flatten = (data: MIR): number[] => {
482
483
483
484
/**
484
485
* Returns an Iterable with which you can use `for-of` or the spread syntax.
485
- * @param data The normalized MultiIntegerRange to iterate over.
486
+ * @param data - The normalized MultiIntegerRange to iterate over.
486
487
* @returns An Iterable object.
487
488
* @example
488
- * Array.from(iterate([[1, 3], [7, 9]])); //=> [1, 2, 3, 7, 8, 9]
489
+ * Array.from(iterate([[1, 3], [7, 9]])); // [1, 2, 3, 7, 8, 9]
489
490
*/
490
491
export const iterate = ( data : MIR ) : Iterable < number > => {
491
492
if ( isUnbounded ( data ) ) {
0 commit comments