Installation
Quick Take
Purpose
For example, when working on parsed tokens, we have a value, a chunk of string, but we know it starts at an index X, not at an index zero. When we return a zero-based result, the receiving parties need to increment every index by X. This program performs this incrementing. The catch is, empty Ranges are typically null
(not an empty array) so the Array.prototype.map()
can’t be used. Hence this library.
API — rOffset()
The main function rOffset()
is imported like this:
It’s a function which takes three input arguments:
Input argument | Type | Obligatory | Description |
---|---|---|---|
arrOfRanges Type: null or Array of one or more arrays (Ranges) Obligatory: no | |||
arrOfRanges | null or Array of one or more arrays (Ranges) | no | Provide an array of ranges to invert. Ranges do not have to be sorted or merged. |
offset Type: Integer number Obligatory: no | |||
offset | Integer number | no | This number will be added to each index of every range. |
Output:
- if not ranges were passed, array of one or more arrays, same input will be returned
- ELSE, offset value will be added to each index of every range
Inputs are not mutated.