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

prevOpen Source→ranges-sortnext

ranges-sort6.2.4

Sort string index ranges

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

No 3rd party dependencies. All dependencies and devDependencies, checked recursively, are Codsen packages.

Permalink to InstallationInstallation

Permalink to Quick TakeQuick Take

Permalink to ExamplesExamples

  • 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
strictlyTwoElementsInRangeArraysBooleannofalseWhen true, every range must contain exactly two elements. For example, [[1, 2, "zzz"]] and [["a"]] throw because their ranges contain three and one elements, respectively.
progressFn
Type: Function, false, null, or undefined
Obligatory: no
Default: null
progressFnFunction, false, null, or undefinednonullReceives best-effort integer progress from 0 to 100. A successful nonempty sort ends at 100 without duplicate values. Empty inputs and validation failures do not call it. Use false or null to disable it.

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";

Permalink to changelogChangelog

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