JSPM

  • Created
  • Published
  • Downloads 242141
  • Score
    100M100P100Q167795F
  • License MIT

Sort natural number index ranges [ [5, 6], [1, 3] ] => [ [1, 3], [5, 6] ]

Package Exports

  • ranges-sort

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-sort) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ranges-sort

ESLint on airbnb-base with caveats

Sort natural number index ranges [ [5, 6], [1, 3] ] => [ [1, 3], [5, 6] ]

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

Install

npm i ranges-sort
// consume as CommonJS require:
const rangesSort = require('ranges-sort')
// or as a native ES module:
import rangesSort from 'ranges-sort'

Here's what you'll get:

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

⬆  back to top

Table of Contents

Rationale

It sorts the array of index arrays, for example:

[ [5, 6], [1, 3] ] => [ [1, 3], [5, 6] ]
[ [5, 6], [5, 3], [5, 0] ] => [ [5, 0], [5, 3], [5, 6] ]
[] => []

[[1, 2], []] => // throws, because there's at least one empty range
[['a']] => // throws, because range is given as string
[[1], [2]] => // throws, because one index is not a range

// 3rd argument and onwards are ignored:
[[3, 4, 'aaa', 'bbb'], [1, 2, 'zzz']] => [[1, 2, 'zzz'], [3, 4, 'aaa', 'bbb']]

⬆  back to top

API

rangesSort(arr[, opts])

Input argument Type Obligatory? Description
arrOfRanges Plain object yes Array of zero or more arrays meaning natural number ranges (2 elements each)
opts Plain object no Optional options go here.

This package does not mutate the input array.

For example,

[ [5, 9], [5, 3] ] => [ [5, 3], [5, 9] ]

⬆  back to top

Options object

options object's key Type Obligatory? Default Description
{
strictlyTwoElementsInRangeArrays Boolean no false If set to true, when there are more or less than 3 elements in any of the ranges, it will throw. For example, input being [ [1, 2, 'zzz'] ] would throw.
}

Output: Sorted input array. First, we sort by the first argument of each child range array, then by second.

⬆  back to top

Contributing

Hi! 99% of people in the society are passive - consumers. They wait for others to take action, they prefer to blend in. The remaining 1% are proactive citizens who will do something rather than wait. If you are one of that 1%, you're in luck because I am the same and together we can make something happen.

  • If you want a new feature in this package or you would like to change some of its functionality, raise an issue on this repo. Also, you can email me. Just let it out.

  • 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. Alternatively, you can email me.

  • If you don't like the code in here and would like to give an advice about how something could be done better, please do. Same drill - GitHub issues or email, your choice.

  • If you would like to add or change some features, just fork it, hack away, and file a pull request. I'll do my best to merge it quickly. Code style is airbnb, 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 © 2017 Codsen Ltd, Roy Revelt