Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ranges-merge

codsen564.1kMIT9.0.18TypeScript support: included

Merge and sort string index ranges

index, join, manage, merge, multiple, ranges, slices, string, substring, two

readme

ranges-merge

Merge and sort string index ranges

page on codsen.com page on npm page on github Downloads per month changelog MIT Licence

Install

This package is pure ESM. If you're not ready yet, install an older version of this program, 7.1.0 (npm i ranges-merge@7.1.0).

npm i ranges-merge

Quick Take

import { strict as assert } from "assert";

import { rMerge } from "ranges-merge";

// joining edges:
assert.deepEqual(
  rMerge([
    [1, 2],
    [2, 3],
    [9, 10],
  ]),
  [
    [1, 3],
    [9, 10],
  ],
);

// an overlap:
assert.deepEqual(
  rMerge([
    [1, 5],
    [2, 10],
  ]),
  [[1, 10]],
);

Documentation

Please visit codsen.com for a full description of the API.

Contributing

To report bugs or request features or assistance, raise an issue on GitHub.

Licence

MIT License.

Copyright © 2010-2025 Roy Revelt and other contributors.

ok codsen star

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

9.0.0 (2022-12-01)

BREAKING CHANGES

  • Minimum supported Node version is v14.18; we're dropping v12 support

8.2.0 (2022-08-12)

Features

8.1.0 (2022-04-11)

Features

  • export defaults and version (1107244)

8.0.0 (2021-09-09)

Features

BREAKING CHANGES

  • programs now are in ES Modules and won't work with Common JS require()

7.1.0 (2021-05-24)

Features

  • config file based major bump blacklisting (e15f9bb)

7.0.15 (2021-04-11)

Reverts

  • Revert "chore: setup refresh" (23cf206)

7.0.1 (2021-01-28)

Fixed

  • add testStats to npmignore (f3c84e9)

7.0.0 (2021-01-23)

Features

  • rewrite in TS and start using named exports (3fdf215)

BREAKING CHANGES

  • previously: import rMerge from ... - now import { rMerge } from ...

6.2.0 (2020-11-29)

Features

  • simplify with unary plus operator (39a9f57)

6.1.0 (2020-11-29)

Features

  • simplify with unary plus operator (39a9f57)

6.0.0 (2020-11-28)

Accidental version bump during migration to SourceHut. Sorry about that.

5.0.0 (2020-09-07)

Features

  • discard any null ranges when merging (ae51bce)
  • return null instead of empty array (27fa708)

BREAKING CHANGES

  • return null instead of empty array

4.3.0 (2020-02-01)

Features

  • remove a dependency, rebase a little (625ba18)

4.2.0 (2019-06-01)

Features

  • Tweak API to correctly interpret opts.processFn given as an empty plain object (bcedd6e)

4.1.0 (2019-03-17)

Features

  • opts.joinRangesThatTouchEdges (40cf7e6)

3.12.0 (2019-01-20)

  • Various documentation and setup tweaks after we migrated to monorepo
  • Setup refresh: updated dependencies and all config files using automated tools

3.8.0 (2018-12-26)

  • Improvements against input argument mutation (924c7ae)
  • Removes ranges with no third arg with identical start and end points (707553b)

3.7.0 (2018-11-29)

  • Second input argument - progressFn is added, it will report percentage done so far. It's used in worker setups.

3.6.0 (2018-10-25)

  • Updated all dependencies
  • Restored coveralls.io reporting
  • Restored unit test linting

3.5.0 (2018-08-17)

  • Apparently the input arguments were mutated on some cases. That's fixed now.

3.4.0 (2018-08-16)

  • Now, ranges with identical starting and ending points with no third argument (nothing to add) will be removed. They're futile anyway. It's like saying at this index... and saying nothing else.

3.3.0 (2018-06-11)

GitHub sold us out. In the meantime, we:

  • Migrated to BitBucket (to host repo + perform CI) and Codacy (for code quality audit)
  • Dropped BitHound (RIP) and Travis
  • Removed package-lock

3.2.0 (2018-05-26)

  • Set up Prettier on a custom ESLint rule set.
  • Removed package.lock and .editorconfig
  • Wired Rollup to remove comments from non-dev builds. This means we can now leave the console.logs in the source code — there's no need to comment-out console.log statements or care about them not spilling into production. Now it's done automatically.
  • Unit tests are pointing at ES modules build, which means that code coverage is correct now, without Babel functions being missed. This is important because now code coverage is real again and now there are no excuses not to perfect it.

3.1.0 (2017-12-29)

  • If third argument is null on any side being merged, output is always null. This will stand for explicit "no" to remove any content to be added. Sibling libraries will tap this feature.

Previously null would have been turned into a string and shown/concatenated like that which was meaningless and kindof erroneous. We never used null anyway. That's why this is not a major semver bump but minor - it's only a feature, an extension of the API.

3.0.0 (2017-12-05)

  • If you have two ranges where second-one completely overlaps the first-one and the first has third argument, something to insert in its place, that third argument will be discarded upon merge.

Let's say you got these two ranges:

[
  [5, 6, " "],
  [1, 10],
];

Previously, result would be [1, 10, ' ']. Now result will be [1, 10]. This is logical, because each range should take care to consider its vicinity. If [1, 10] came in without instructions to add something in its place, we assume this was intentional.

This change is logical and natural but I'm bumping major version just in case it breaks somebody's unit tests.

2.0.0 (2017-12-04)

  • Rebased the source in ES Modules
  • Set up Rollup and now we are generating three builds: CommonJS, UMD and ES Modules (native code).

1.0.0 (2017-09-18)

  • First public release