drange-immutable

4.0.1 • Public • Published

Immutable Discontinuous Range

Build Status npm page License MIT SemVer 2.0.0 JavaScript Style Guide

Wrapper for the excellent npm package DRange.

This wrapper keeps the exact same API syntax as DRange, except:

  • each method that mutates the range, instead returns a mutated clone,
  • the range is also sorted after .add() is used, instead of putting loose ranges at the end.

The immutability makes it fit better with a purely functional code style.

Installation

You need to install drange yourself, so you can upgrade to newer versions without me having to upgrade this wrapper too :)

yarn add drange drange-immutable
 
# or 
 
npm install --save drange drange-immutable 

Usage

const range = require('drange-immutable')(require('drange'))
 // or
import wrapper from 'drange-immutable'
import DRange from 'drange'
const range = wrapper(DRange)

Example:

const hundred = range(1, 100)
console.log(hundred.toString())        // [ 1-100 ]
 
const split = hundred.subtract(50, 60)
console.log(split.toString())          // [ 1-49, 61-100 ]
console.log(hundred.toString())        // [ 1-100 ]
                                       //   ^^ still the same.
                                       //   Original drange would have
                                       //   mutated 'hundred' too. 

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 4.0.1
    4
    • latest

Version History

Package Sidebar

Install

npm i drange-immutable

Weekly Downloads

7

Version

4.0.1

License

MIT

Unpacked Size

7.11 kB

Total Files

13

Last publish

Collaborators

  • hugojosefson