Test whether a number, english alphabet character or a date is between two others.
Augmented version of in-range made by Sindre Sorhus with a more functional taste
$ npm install in-between
With numbers:
const between = require('in-between')
const between1and10 = between(1, 10)
between1and10(10) //=> false
between1and10(3) //=> true
betweenAandZ('*') //=> throws error
between1and10(1) //=> false
between(100, 200)(101) //=> true
Works with alphabet characters:
const between = require('in-between')
const betweenAandD = between('a', 'd')
betweenAandD('b') //=> true
betweenAandD('z') //=> false
Works with Dates as well:
const between = require('in-between')
let myGraduation = new Date("October 13, 2014 11:13:00")
let myFirstJob = new Date("September 1, 2015 11:13:00")
let myBirthDay = new Date("January 10, 2015 10:11:03")
between(myGraduation, myFirstJob)(myBirthDay) //=> true
You can include the boundaries:
const between = require('in-between')
between(3, 4, true)(3) //=> true
between('a', 'b', true)('a') // => true
between(number | string | date, number | string | date, boolean) => function(number | string | date) => boolean
MIT © Alvaro Bernal