Miss any of our Open RFC calls?Watch the recordings here! »

This package has been deprecated

Author message:

Deprecated in favor of 'fjl' (install version '1.1.0-beta' for version containing 'range' method (also look at included docs for changes to range implementation)).

fjl-range

1.0.4 • Public • Published

fjl-range

Range function (returns array of values in range).

Usage

Node

Both es6 modules and common-js modules supported by default.

import {range} from 'fjl-range';

const testRange = [-3, -4, -5, 1, 2, 3, 99, 98, 97];

range(-3, -5, -1).concat(range(1, 3), range(99, 97, -1))
    .every((x, ind) => x === testRange[ind]) === true // true  

or

const {range} = require('fjl-range');

// ...

or use one of 'amd', 'umd', 'iife', or 'commonjs' builds included in './dist' folder: Example:

<!-- If imported globally ('iife') exported as `fjlRange` globally -->
<script src="js/vendor/fjl-range/dist/iife/fjl-range.js"></script>

In the browser

Same as above or look/include files directly from './dist' folder for your module loading type (amd, umd, iife, commonjs, and/or module).

Exports

range(from, to, step = 1):Array<Number>

Returns an array of numbers generated from the given 'range' (from -> to) and step values:

    // Positve direction range 
    shallowCompare(range(1, 5), [1, 2, 3, 4, 5]) === true // true
    shallowCompare(range(1, 5, 1), [1, 2, 3, 4, 5]) === true // true
    
    // Negative numbers range
    shallowCompare(range(-5, -1, 1), [-5, -4, -3, -2, -1]) === true // true
    
    // Negative direction
    shallowCompare(range(-3, -5, -1), [-3, -4, -5]) === true // true
    
    // Auto normalize step for given range
    shallowCompare(range$(-3, -5), [-3, -4, -5]) === true // true
    // Note here that we are not passing a `step` and that the default `step` is `1`
    //  hence our step is invalid though this version of `range` normalizes 
    //  the step for us if it is invalid.  Also note that we are using `range$` here
    //  instead of `range` (for this functionality)

Haskell type: range :: Number a => a -> a -> a -> [a]

range$(from, to, step = 1):Array<Number>

Same as range except normalizes step variable to be valid; E.g.,

range$(-3, -5)  // Still produces a valid range despite the default `step` being `1`
                //  This version of range looks at the `from` and `to` variables
                //  and checks if `from` is greater than `to` and if so return a negative version of step
                //  else does the opposite. 

Development

  1. npm install
  2. Look at node scripts in package.json.

Testing

  1. npm test (after npm install).

Docs

JsDocs here: https://functional-jslib.github.io/fjl-range

License

GNU v2, v3

Keywords

none

Install

npm i fjl-range

DownloadsWeekly Downloads

8

Version

1.0.4

License

BSD-3-Clause

Last publish

Collaborators

  • avatar