1.0.1 • Published 6 years ago

streaky-util v1.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

streaky-util

Utility functions to calculate streak related values.

Install

  $ npm install streaky-util

API

All dates passed should be ISO 8601 dates.

streakyUtil.getCurrentStreak(entries, options)

  • entries can be an array of dates, or an object where the keys are dates and the values are boolean:
  let entries = ['2018-02-08', '2018-02-09', '2018-02-10']
  streakyUtils.getCurrentStreak(entries, {initialDate: '2018-02-10'}) // -> 3

  // or

  entries = {
    '2018-02-08': false,
    '2018-02-09': true,
    '2018-02-10': true
  }

  streakyUtils.getCurrentStreak(entries, {initialDate: '2018-02-10'}) // => 2
  • options is an object that can have a initialDate property, to change the date to start counting from. If not passed, the current day is considered.

streakyUtil.getLongestStreak(entries, options)

  • entries can be an array of dates, or an object where the keys are dates and the values are boolean.
  • options is an object that can have a initialDate property, to change the date to start counting from. If not passed, the current day is considered.