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

prevOpen Source→ranges-invertnext

ranges-invert6.2.1

Invert string index ranges

Downloads per monthChangelogMIT Licenselibera manifesto
  • the top
  • Installation
  • Quick Take
  • Examples
  • API — RINVERT()
  • API — DEFAULTS
  • API — VERSION
  • Changelog

Installation

Quick Take

Examples

  • Merge overlapping ranges before inverting
  • Invert an absent ranges collection
  • Skip validation for already sorted ranges
  • Require two-element ranges

API — rInvert()

The main function rInvert() is imported like this:

It’s a function which takes three input arguments:

Input argumentTypeObligatoryDescription
arrOfRanges
Type: null or array of zero or more arrays
Obligatory: yes
arrOfRangesnull or array of zero or more arraysyesProvide an array of ranges to invert. Ranges do not have to be sorted or merged.
strLen
Type: Integer number
Obligatory: yes
strLenInteger numberyesAlgorithm needs to know the length of the reference string to calculate the inverted last slice’s ending index.
opts
Type: Plain object
Obligatory: no
optsPlain objectnoOptional Options Object.

The Optional Options Object has the following shape:

KeyTypeObligatoryDefaultDescription
strictlyTwoElementsInRangeArrays
Type: Boolean
Obligatory: no
Default: false
strictlyTwoElementsInRangeArraysBooleannofalseIf set to true, all ranges must have two and only two elements, otherwise an error will be thrown. For example, input being [ [1, 2, 'zzz'] ] would throw (because of 3 elements), as well as [ ['a'] ] (1 element).
skipChecks
Type: Boolean
Obligatory: no
Default: false
skipChecksBooleannofalseIf set to true, no checks will be performed. It’s handy to cut corners for perf reasons when you know input ranges are clean.

Here are all defaults in one place for copying:

Function will return inverted ranges — a null or array of one or more range arrays:

API — defaults

You can import defaults:

It's a plain object:

The main function calculates the options to be used by merging the options you passed with these defaults.

API — version

You can import version:

Changelog

Open Changelog
↑ 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