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

rangz

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rangz

A beautifully overloaded range function, allowing for resounding functionality. Uses lazy evaluation for inifinte ranges.

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Rangz

How do I get started?

npm i rangz --save
const range = require("rangz");

How do I make a range?

range(30); // Range to 30

But how do I iterate over it?

for(const i of range(30)) // How pythonic!

What about start points, end points and steps?

range({
    start: 5,
    end: 30,
    step: 2
}); // [ 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29 ]

But I don't want the step to just add a number, I want it to multiply by 2.

range({
    start: 1,
    end: 1000,
    step: i => i * 2
}); //[ 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 ]

But my range needs to be INFINITE.

range(1, 2); // Infinite range inferred.

Great, but how do I get a slice of my infinite range?

range(1, 2).take(20); // [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ]

Awesome, but my range is descending, not ascending.

range(2, 1).take(5); // [ 2, 1, 0, -1, -2 ]

Cool, but what if my range is exponential?

range(2, 4, 8).take(10); // [ 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 ]

Impressive, but my range is descending AND exponential.

range(8, 4, 2).take(10); // [ 8, 4, 2, 1, 0.5, 0.25, 0.125, 0.0625, 0.03125, 0.015625 ]

Great, but I want the millionth value of the range, and I don't need the whole array.

range(1, 2).get(1000000); // 1000001

Keywords

FAQs

Package last updated on 20 May 2019

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