npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

inclusive-range

v0.0.1

Published

A no-frills number-range generator

Downloads

6

Readme

range

Build Status NPM Version

NAME

inclusive-range - a no-frills number-range generator

FEATURES

  • < 250 bytes minified and gzipped
  • ranges include the start and end value (inclusive)
  • ranges are iterable (no superfluous forEach, toArray etc. methods)
  • optional step parameter
  • ascending or descending ranges
  • infinite ranges
  • developer-friendly (TypeScript)

INSTALLATION

$ npm install inclusive-range

SYNOPSIS

import range from 'inclusive-range'

for (const value of range(1)) { // 1 to infinity
    console.log(value)
}

[...range(1, 5)]     // [1, 2, 3, 4, 5]
[...range(5, 1)]     // [5, 4, 3, 2, 1]
[...range(1, 10, 3)] // [1, 4, 7, 10]
[...range(10, 1, 3)] // [10, 7, 4, 1]

DESCRIPTION

This module exports a function which generates an iterable number range from the start value to the end value (inclusive) with an optional step. If the step is omitted, it defaults to 1. If the end is omitted, it defaults to Infinity. If the start is omitted, it defaults to 1.

Why?

There are dozens of range implementations on NPM, none of which DWIM.

Many return eager arrays rather than lazy iterables. Most are exclusive, e.g. range(1, 10) returns 1 to 9 rather than 1 to 10. Some are inclusive, but bolt on other features such as map or forEach methods, which may be useful as part of a library like wu.js, but which are superfluous in a standalone range function. Most aren't typed (TypeScript).

This has all the functionality I need and none of the functionality I don't need and clocks in at ~250 bytes minified and gzipped.

EXPORTS

range (default)

Type: range(start?: number, end?: number, step?: number) → Iterable<number>

import range from 'inclusive-range'

const asc  = Array.from(range(1, 5)) // [1, 2, 3, 4, 5]
const desc = Array.from(range(5, 1)) // [5, 4, 3, 2, 1]

for (const value of range(1, 10, 3)) {
    console.log(value) // 1, 4, 7, 10
}

Returns an iterable which generates numbers from start to end inclusive. The optional step (default: 1) is added (ascending) or subtracted (descending) from the previous value to produce the next value. If end is omitted, it defaults to Infinity. If start is omitted, it defaults to 1.

COMPATIBILITY

Any platform (browser, Node.js etc.) which supports ES6 generators.

DEVELOPMENT

NPM Scripts

The following NPM scripts are available:

  • build - compile the library and save it to the target directory
  • clean - remove the target directory and its contents
  • rebuild - remove the target directory and regenerate the build
  • test - typecheck the codebase, compile the library, and run the test suite

SEE ALSO

VERSION

0.0.1

AUTHOR

chocolateboy

COPYRIGHT AND LICENSE

Copyright © 2019 by chocolateboy.

This is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.