Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fjl-range

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fjl-range

Range function (returns array of values in range).

  • 1.0.3
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 20 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc