1.0.1 • Published 3 years ago

@caleb1248/timerjs v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Timerjs: Simplifing online timers

How to

First link to the script

Regular javascript

<script src="https://cdn.jsdelivr.net/gh/caleb1248/timerjs@master/dist/timer.min.js"></script>

Or

<script src="https://cdn.jsdelivr.net/gh/caleb1248/timerjs@master/dist/timer.js"></script>

ES Javascript

// import the minified version
import Timer from 'https://cdn.jsdelivr.net/gh/caleb1248/timerjs@master/dist/timer.esm.min.js'
// Or the regular version
import Timer from 'https://cdn.jsdelivr.net/gh/caleb1248/timerjs@master/dist/timer.esm.js'

Usage:

const timer = new Timer();

Methods:

Start the timer

timer.start()

Stop the timer

timer.stop()

Set the time on the timer (stops the timer as well)

timer.setTime(hours, minutes, seconds)

Handle events...

on(event, callback)

Events that are fired:

start

Usage

timer.on('start', function() {
  console.log('timer started');
});
// Or
timer.onstart = function() {
  console.log('timer started');
}

stop

timer.on('stop', function() {
  console.log('timer stopped');
})
// Or
timer.onstop = function() {
  console.log('timer stopped');
}

update

timer.on('update', function(hours, minutes, seconds) {
  console.log('timer updated', hours, minutes, seconds);
})
// Or
timer.onupdate = function(hours, minutes, seconds) {
  console.log('timer updated', hours, minutes, seconds);
}

timerend

timer.on('timerend', function() {
  console.log('event fired');
})
// Or
timer.ontimerend = function() {
  alert('Times up!');
}

View an example here

View the source code for the example here

You can install this as an npm package too at https://www.npmjs.com/package/npmtimerjs. A nodejs example is at https://www.npmjs.com/package/npmtimerjs-example