Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

@nxtedition/ranges

Package Overview
Dependencies
Maintainers
10
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nxtedition/ranges

Merge and subtract numeric ranges. Useful for byte ranges, time ranges, and similar interval arithmetic.

latest
npmnpm
Version
1.0.1
Version published
Maintainers
10
Created
Source

@nxtedition/ranges

Merge and subtract numeric ranges. Useful for byte ranges, time ranges, and similar interval arithmetic.

Install

npm install @nxtedition/ranges

Usage

Merge overlapping ranges

import { merge } from '@nxtedition/ranges'

merge([
  [10, 20],
  [15, 30],
  [50, 60],
])
// [[10, 30], [50, 60]]

Subtract ranges

import { subtract } from '@nxtedition/ranges'

subtract(
  [[0, 100]],
  [
    [10, 20],
    [30, 40],
  ],
)
// [[0, 10], [20, 30], [40, 100]]

API

merge(ranges: Range[]): readonly Range[]

Sorts and merges overlapping or adjacent ranges. Returns a new array of non-overlapping ranges. Invalid ranges (empty, reversed, non-finite) are filtered out.

subtract(a: readonly Range[], b: readonly Range[]): readonly Range[]

Subtracts ranges b from ranges a. Returns the remaining intervals. Does not modify the input arrays.

Range

type Range = readonly [start: number, end: number]

Ranges are half-open intervals: start is inclusive, end is exclusive.

License

MIT

FAQs

Package last updated on 16 Feb 2026

Did you know?

Socket

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.

Install

Related posts