0.2.0 • Published 5 years ago

realtime-countdown v0.2.0

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

Realtime Countdown

Lightweight realtime countdown timer JavaScript Library

Features

  • Pure JavaScript
  • Simple use
  • Flexible parametrization

Install

npm install realtime-countdown

Default Options

    {
      timeStamp: 0, // value in milliseconds
      countStep: 1000, // value in milliseconds
      leadingZero: false, // adds leading zero before the value if it's a single digit
      onInitialize: function(eventObject) {},
      onCount: function(eventObject) {},
      onCountEnd: function(eventObject) {},
      onDestroy: function(eventObject) {},
    }

Methods

  • destroy ()

How to use

    import RealtimeCountdown from 'realtime-countdown'
    
    const timeStamp = Date.now() + 24 * 60 * 60 * 1000
    const onInitialize = (timeLeft) => console.log(timeLeft)
    const onCount = (timeLeft) => console.log(timeLeft)
    const onCountEnd = (timeLeft) => console.log(timeLeft)
    
    const Timer = new RealtimeCountdown({ timeStamp, onInitialize, onCount, onCountEnd })
    
    // output on onInitialize
    const onInitializeTimeLeft = { days: 1, hours: 0, minutes: 0, seconds: 0 }
    
    // output on every tick, will be reduced by a `countStep`
    const onCountTimeLeft = { days: 0, hours: 23, minutes: 59, seconds: 59 }
    
    // output on count end (not called when destroy)
    const onCountEndTimeLeft = { days: 0, hours: 0, minutes: 0, seconds: 0 }
    
    // destroy timer
    Timer.destroy()

Tests

npm test

Coverage

npm run coverage