
Security News
npm ‘is’ Package Hijacked in Expanding Supply Chain Attack
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
ranges-sort
Advanced tools
The ranges-sort npm package is designed to sort and manage ranges of numbers or strings. It is particularly useful for tasks that involve handling multiple ranges and ensuring they are in a specific order.
Sorting Ranges
This feature allows you to sort an array of ranges. The ranges are sorted based on their starting values.
const rangesSort = require('ranges-sort');
const ranges = [[5, 10], [1, 3], [8, 12]];
const sortedRanges = rangesSort(ranges);
console.log(sortedRanges); // Output: [[1, 3], [5, 10], [8, 12]]
Handling Overlapping Ranges
This feature allows you to sort and merge overlapping ranges. The resulting array contains non-overlapping ranges.
const rangesSort = require('ranges-sort');
const ranges = [[5, 10], [1, 3], [8, 12]];
const sortedRanges = rangesSort(ranges, { mergeOverlapping: true });
console.log(sortedRanges); // Output: [[1, 3], [5, 12]]
The interval-tree package is used for managing and querying intervals. It supports efficient insertion, deletion, and querying of intervals. While it offers more advanced features for interval management compared to ranges-sort, it is more complex to use and may be overkill for simple range sorting tasks.
Sort string index ranges
This package is pure ESM. If you're not ready yet, install an older version of this program, 4.1.0 (npm i ranges-sort@4.1.0
).
npm i ranges-sort
import { strict as assert } from "assert";
import { rSort } from "ranges-sort";
// Ranges (see codsen.com/ranges/) are sorted:
assert.deepEqual(
rSort([
[2, 3],
[9, 10, "bad grey wolf"],
[1, 2],
]),
[
[1, 2],
[2, 3],
[9, 10, "bad grey wolf"],
],
);
Please visit codsen.com for a full description of the API.
To report bugs or request features or assistance, raise an issue on GitHub.
MIT License.
Copyright © 2010-2025 Roy Revelt and other contributors.
FAQs
Sort string index ranges
The npm package ranges-sort receives a total of 221,930 weekly downloads. As such, ranges-sort popularity was classified as popular.
We found that ranges-sort demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
Security News
A critical flaw in the popular npm form-data package could allow HTTP parameter pollution, affecting millions of projects until patched versions are adopted.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.