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

btwn

v1.2.0

Published

Check if a number or date is in your min-max bounds.

Downloads

13

Readme

btwn npm npm Build Status

Check if a number is in your min-max bounds.

  • Lightweight
  • Builds into the Number prototype
  • 100% code coverage

Install

npm install btwn

...or...

yarn add btwn

Usage

Checking a number

var btwn = require('btwn');

var x = 12; // a normal Number type variable

if(x.btwn(1, 13)){
	console.log("This number is under or equals to 13, and greater than or equals to 1.");
} else {
	console.log("This number is under 1 or greater than 13.");
}

Checking a date

var btwn = require('btwn');

// Bounds are 09:00-09:59 (inclusive)
var minDate = new Date(2017, 00, 01, 09, 00, 00, 00);
var maxDate = new Date(2017, 00, 01, 09, 59, 59, 00);
var min = new btwn.BoundDate(minDate, false, false, false, true, true, false, false); //See the usage of these booleans in the docs below
var max = new btwn.BoundDate(maxDate, false, false, false, true, true, true, false); //See the usage of these booleans in the docs below

var d = new Date(); //Current date & time

if(d.btwn(min, max)){
	console.log("It's after 8:59:59 and before 10:00:00!");
} else {
	console.log("It's before 9:00:00 or after 9:59:59.");
}

Use in browser

Download the latest btwn.js from here, and follow the instructions above without the require line.

Docs

BoundDate(date, year, month, day, hours, minutes, seconds, [ms])

  • date - Input date.
  • year - Should the year be included as a bound?
  • month - Should the month be included as a bound?
  • day - Should the day ("date" in the Date object) be included as a bound?
  • hours - Should the hours be included as a bound?
  • minutes - Should the minutes be included as a bound?
  • seconds - Should the seconds be included as a bound?
  • ms - Should the milliseconds be included as a bound? (Default: false)

Number.btwn(min, max, [inclusive])

  • min - Minimum value.
  • max - Maximum value.
  • inclusive - Are min and max inclusive. (Default: true)

Date.btwn(min, max, [inclusive])

  • min - Minimum DateBound.
  • max - Maximum DateBound.
  • inclusive - Are min and max inclusive (Default: true)

To-do

  • [ ] Integrate into dates

Tests

Run mocha.