Basic usage

Sometimes you have an enum or union type, possibly a status, that has inherint order and you need to work with values as though they’re ordered. The series function takes many values and returns an object that let’s you do ordered logic on those values.

import { series } from 'radash'

type Weekday = 'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday';

const weekdays = series<Weekday>(
  'monday',
  'tuesday',
  'wednesday',
  'thursday',
  'friday'
)

weekdays.min('tuesday', 'thursday') // => 'tuesday'
weekdays.max('wednesday', 'monday') // => 'wednesday'
weekdays.next('wednesday') // => 'thursday'
weekdays.previous('tuesday') // => 'monday'
weekdays.first() // => 'monday'
weekdays.last() // => 'friday'
weekdays.next('friday') // => null
weekdays.next('friday', weekdays.first()) // => 'monday'

Testing

This _.series function is 100% covered by tests. See them and contribute at GitHub.

Source

See the source for _.series on GitHub.