mirror of
https://github.com/bcomnes/deploy-to-neocities.git
synced 2026-01-17 15:06:29 +00:00
35 lines
584 B
JavaScript
35 lines
584 B
JavaScript
/**
|
|
* Simple timer lets you record start and stop times, with an elapsed time getter.
|
|
*/
|
|
class SimpleTimer {
|
|
constructor (startTime) {
|
|
this.start = startTime || Date.now()
|
|
this.end = null
|
|
this.stopped = false
|
|
}
|
|
|
|
get elapsed () {
|
|
if (this.stopped) {
|
|
return this.end - this.start
|
|
} else {
|
|
return Date.now() - this.start
|
|
}
|
|
}
|
|
|
|
stop () {
|
|
if (this.stopped) return
|
|
this.stopped = true
|
|
this.end = Date.now()
|
|
}
|
|
|
|
toString () {
|
|
return this.elapsed
|
|
}
|
|
|
|
toJSON () {
|
|
return this.elapsed
|
|
}
|
|
}
|
|
|
|
module.exports = SimpleTimer
|