Convenient duration time utility
npm install rsup-duration
import duration from 'rsup-duration'
const d = duration()
console.log(d.isPast) // => false
console.log(d.isDuring) // => false
d.start(1000)
console.log(d.isPast) // => false
console.log(d.isDuring) // => true
await d.onStop() // Resolved after 1 second.
console.log(d.isPast) // => true
console.log(d.isDuring) // => false
d.start(1000)
console.log(d.isPast) // => false
console.log(d.isDuring) // => true
delay(200).then(()=> d.stop())
await d.onStop() // Resolved after 200ms.
Create a duration instance.
Returns whether the duration has passed.
Returns whether the duration is in progress.
Start time. If already in progress, this call is ignored.
-
ms
- duration time. If not, it is specified asdefaultMs
. -
force
- Ifforce
is true, stop and new start when time is in progress.
const d = duration(1000)
d.start() // ms = 1000, force = false
d.start(500) // ms = 500, force = false
d.start({ms: 500}) // ms = 500, force = false
d.start({ms: 1000, force: true}) // // ms = 1000, force = true
Returns the promise that waits until stop.
console.log(d.isPast) // => false
await d.start(1000) // Resolved after 1 second.
console.log(d.isPast) // => true
Stop time.
d.start(1000)
delay(200).then(()=> d.stop())
await d.onStop() // Resolved after 200ms.
Returns the promise that waits until stop.
MIT