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 🙏

© 2025 – Pkg Stats / Ryan Hefner

rangerjs

v0.1.1

Published

A lightweight JS library for defining an array of ranges.

Downloads

44

Readme

ranger.js

A lightweight JS library for defining an array of ranges. Stores the ranges in an array of range objects.

note: upper limit is always non-inclusive

var ranger = require('rangerjs');
var newRanger = new ranger();
var existingRanger = new ranger(array);

####ranger.Range(Type) //Returns: { start: Type, end: Type
}

In order to save the array to db (in this case MongoDB), use the following Schema type:

{
    ...
    ranges: {
        type: ranger.Range(Type), //Type can be Number, Date, etc.
        get: function(data) {
            return new ranger(data);
        },
        set: function(data) {
            return data.ranges || data;
        }
    }
}

Keep in mind that MongoDB does not listen for changes in individual array elements so after performing an operation (such as addRange or removeRange) make sure to markModified('ranges')

####newRanger.addRange(from, to); newRanger.addRange(1, 4);

####newRanger.removeRange(from, to); newRanger.removeRange(2, 3);

####newRanger.check(value); newRanger.check(1); //true newRanger.check(2); //false newRanger.check(3); //true newRanger.check(4); //false newRanger.check(5); //false

####newRanger.checkRange(from, to); newRanger.checkRange(1, 5); //false newRanger.checkRange(2, 4); //false newRanger.checkRange(2, 3); //false newRanger.checkRange(3, 4); //true

####newRanger.nextRange(now); newRanger.nextRange(1); // { start: 1, end: 2 } newRanger.nextRange(2); // { start: 3, end: 4 } newRanger.nextRange(5); // undefined newRanger.nextRange(); // undefined

####newRanger.addRecuringRange(from, to, interval, count, finish); Either count (of reptitions) or finish (final upper limit) must be set. If using finish, set count to null or < 1.

//These will create the same ranges:
newRanger.addRecuringRange(1, 2, 2, 3);
newRanger.addRecuringRange(1, 2, 2, 0, 7);
//Result:
newRanger.check(1); //true
newRanger.check(2); //false
newRanger.check(3); //true
newRanger.check(4); //false
newRanger.check(5); //true
newRanger.check(6); //false
newRanger.check(7); //false

####newRanger.removeRecuringRange(from, to, interval, count, finish); Either count (of reptitions) or finish (final upper limit) must be set. If using finish, set count to null or < 1.

newRanger.addRange(1, 8);
//These will remove the same ranges:
newRanger.removeRecuringRange(1, 2, 2, 3);
newRanger.removeRecuringRange(1, 2, 2, 0, 7);
//Result:
newRanger.check(1); //false
newRanger.check(2); //true
newRanger.check(3); //false
newRanger.check(4); //true
newRanger.check(5); //false
newRanger.check(6); //true
newRanger.check(7); //true