min-timer
v1.0.0
Published
simple timer for javascript without pain in setInterval
Downloads
3
Readme
min-timer
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][downloads-url] [![Dependency Status][david-image]][david-url] [npm-image]: https://img.shields.io/npm/v/min-timer.svg?style=flat-square [npm-url]: https://npmjs.org/package/min-timer [downloads-image]: http://img.shields.io/npm/dm/min-timer.svg?style=flat-square [downloads-url]: https://npmjs.org/package/min-timer [david-image]: http://img.shields.io/david/chunpu/min-timer.svg?style=flat-square [david-url]: https://david-dm.org/chunpu/min-timer
simple timer for javascript without pain in setInterval
Installation
npm i min-timer
inspired by as3 timer
var Timer = require('min-timer')
var timer = new Timer(1000, 5)
timer.start()
timer.on('timer', function() {
console.log('timer', timer.currentCount)
})
Api
Constructor
new Timer(interval, [repeatCount = Infinity])
Property
interval
interval set in constructorrepeatCount
total count set in constructorcurrentCount
current countrunning
is timer running
Method
start()
start timerstop()
stop timerreset()
stop and set currentCount = 0
Event
timer
when one interval passtimerComplete
timer complete
Static Method
sugar for timer, always auto start, and return the timer instance
Timer.interval(fn, interval, [repeatCount = Infinity])
Timer.timeout(fn, delay)
var timer = Timer.interval(function() {
console.log('timer interval', timer.currentCount)
}, 500, 5)