Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

prevOpen Source→ranges-offsetnext

ranges-offset

Increment or decrement each index in every range

Downloads per monthMIT Licenselibera manifesto
  • the top
  • PURPOSE
  • API — ROFFSET()

Purpose

For example, when working on parsed tokens, you have a value, a chunk of string, but you know it starts at an index X, not at an index zero. When you 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 argumentTypeObligatoryDescription
arrOfRanges
Type: null or Array of one or more arrays (Ranges)
Obligatory: no
arrOfRangesnull or Array of one or more arrays (Ranges)noProvide an array of ranges to invert. Ranges do not have to be sorted or merged.
offset
Type: Integer number
Obligatory: no
offsetInteger numbernoThis 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.

↑ back to top
prev next

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab