0.3.3 • Published 7 years ago
nextperiod v0.3.3
nextperiod
Use this package to easily get the next time period in a series.
Install
npm install nextperiod --save
const series = {
MORNING: 10,
AFTERNOON: 15,
EVENING: 19
}
const nextperiod = require('nextperiod')
Examples
nextperiod(series, 10) // 15
nextperiod(series, 19) // 10
nextperiod(series, 'MORNING') // 'AFTERNOON'
nextperiod(series, 'evening') // 'MORNING'
nextperiod(series, { MORNING: 10 }) // 'AFTERNOON'
Pretty Output
nextperiod(series, 'afternoon', { pretty: true }) // 'Evening'
nextperiod(series, 15, { pretty: true }) // 'Evening'
Custom Wrapping
nextperiod(series, 19, { wrap: false }) // false
nextperiod(series, 15, { wrap: false }) // 19
nextperiod(series, 'MORNING', { wrap: false }) // 'AFTERNOON'
Return an Object
nextperiod(series, 19, { object: true }) // { MORNING: 10 }
nextperiod(series, 15, { object: true }) // { EVENING: 19 }
nextperiod(series, 'MORNING', { object: true }) // { AFTERNOON: 15 }
Defaults
nextperiod([], 'NOT_IN_SERIES') // false
nextperiod([], '', { pretty: true, wrap: true, object: false }) // false
Features
- Works both in Node.js and in the browser