JSPM

  • Created
  • Published
  • Downloads 253384
  • Score
    100M100P100Q176355F
  • License MIT

Merge and sort arrays which mean string slice ranges

Package Exports

  • ranges-merge

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ranges-merge) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ranges-merge

ESLint on airbnb-base with caveats

Merge and sort arrays which mean string slice ranges

Minimum Node version required Link to npm page Build Status Coverage bitHound Overall Score bitHound Dependencies View dependencies as 2D chart bitHound Dev Dependencies Known Vulnerabilities Downloads/Month Test in browser MIT License

Table of Contents

Install

npm i ranges-merge
// consume as a CommonJS require:
const mergeRanges = require('ranges-merge')
// or as native ES Module:
import mergeRanges from 'ranges-merge'

Here's what you'll get:

Type Key in package.json Path Size
Main export - CommonJS version, transpiled to ES5, contains require and module.exports main dist/ranges-merge.cjs.js 2 KB
ES module build that Webpack/Rollup understands. Untranspiled ES6 code with import/export. module dist/ranges-merge.esm.js 1 KB
UMD build for browsers, transpiled, minified, containing iife's and has all dependencies baked-in browser dist/ranges-merge.umd.js 16 KB

⬆  back to top

The Idea

If, after sorting, two ranges in the vicinity have the same edge value (like 2 below), merge those ranges:

const rangesMerge = require('ranges-merge')
rangesMerge([
  [1, 2], [2, 3], [9, 10]
])
// => [
//   [1, 3], [9, 10]
// ]
}

If ranges overlap, merge them too:

const rangesMerge = require('ranges-merge')
rangesMerge([
  [1, 5], [2, 10]
])
// => [
//   [1, 10]
// ]
}

⬆  back to top

API

rangesMerge(arr)

It returns a new array of arrays, with ranges merged (where applicable).

Contributing

  • If you want a new feature in this package or you would like us to change some of its functionality, raise an issue on this repo.

  • If you tried to use this library but it misbehaves, or you need an advice setting it up, and its readme doesn't make sense, just document it and raise an issue on this repo.

  • If you would like to add or change some features, just fork it, hack away, and file a pull request. We'll do our best to merge it quickly. Code style is airbnb-base, only without semicolons. If you use a good code editor, it will pick up the established ESLint setup.

⬆  back to top

Licence

MIT License (MIT)

Copyright © 2018 Codsen Ltd, Roy Revelt