Skip to content

harrymt/nextperiod

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

nextperiod

Use this package to easily get the next time period in a series.

Install

npm i nextperiod -S
import nextperiod from 'nextperiod'

const series = {
  MORNING: 10,
  AFTERNOON: 15,
  EVENING: 19
}

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