rsup-duration
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

rsup-duration

Convenient duration time utility

npm travis

Install

npm install rsup-duration
import duration from 'rsup-duration'

Example

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.

API

duration(defaultMs = 0)

Create a duration instance.

d.isPast

Returns whether the duration has passed.

d.isDuring

Returns whether the duration is in progress.

d.start(options)

Start time. If already in progress, this call is ignored.

options
  • ms - duration time. If not, it is specified as defaultMs.
  • force - If force 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

d.stop()

Stop time.

d.start(1000)
delay(200).then(()=> d.stop())
await d.onStop() // Resolved after 200ms.

d.onStop()

Returns the promise that waits until stop.

License

MIT

Dependencies (1)

Dev Dependencies (6)

Package Sidebar

Install

npm i rsup-duration

Weekly Downloads

9

Version

1.0.0

License

MIT

Unpacked Size

5.79 kB

Total Files

6

Last publish

Collaborators

  • skt-t1-byungi