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

prevOpen Source→ranges-sortnext

ranges-sort6.2.0

Sort string index ranges

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

Installation

Quick Take

Examples

  • Preserve empty range collections
  • Observe sorting progress
  • Require two-element ranges

API — rSort()

The main function rSort() is imported like this:

It’s a function which takes two input arguments:

Input argumentTypeObligatoryDescription
arrOfRanges
Type: Array or null
Obligatory: yes
arrOfRangesArray or nullyesInput ranges.
opts
Type: Plain object
Obligatory: no
optsPlain objectnoOptional Options Object.

None of the input arguments will be mutated by this program, we have unit tests to prove that.

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 elements, otherwise error is thrown. For example, input being [ [1, 2, 'zzz'] ] would throw (3 elements), as well as [ ['a'] ] (1 element).
progressFn
Type: Function
Obligatory: no
Default: null
progressFnFunctionnonullIf a function is given, it will be called with natural number meaning percentage of the total work done. It’s approximate and used in worker setups.

Here are all defaults in one place for copying:

The function will return sorted ranges array (or null if that was passed).

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:

API — types

This package is written in TypeScript and exports the following types:

TypeDescription
Opts
Type: Opts
OptsThe Optional Options Object of rSort(), documented above.
ProgressFn
Type: ProgressFn
ProgressFnThe signature of opts.progressFn — called with the percentage done.
Range
Type: Range
RangeA single range: a two- or three-element array.
Ranges
Type: Ranges
RangesZero or more Ranges, or null.
import type { Opts, ProgressFn, Range, Ranges } from "ranges-sort";

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