1.0.11 • Published 4 years ago

high-res-timeout v1.0.11

Weekly downloads
6
License
ISC
Repository
github
Last release
4 years ago

High Res Timeout

A high-resolution, object-oriented replacement for setTimeout() and setInterval(). Good for animations, progress indicators, carousels, you name it.

Installation

npm install --save-dev high-res-timeout

Usage

Simple timeout

import HighResTimeout from "high-res-timeout"
const timeout = new HighResTimeout(250)

Repeating timeout (setInterval)

import HighResTimeout from "high-res-timeout"
const interval = new HighResTimeout(250, true)

Lifecycle callbacks

As a Promise

timeout
    .start()
    .then(() => console.log("I am complete!"))
    .catch(() => console.log("I've been stopped!"))

Events

timeout.start()
    .on('complete', () => console.log('I am complete!'))
    .on('stop', () => console.log("I've stopped!"))
    .on('start', () => console.log("I've started!"))
    .on('reset', () => console.log("I've been reset!"))
    .on('tick', () => {
    	console.log(`I'm ${(timeout.progress * 100).toFixed(0))}% done`)
    });

Methods and properties

Instance methods

MethodChainableDescription
start()Starts the timeout. Takes into account time elapsed between previous calls to start() and stop().
stop()Stops the timeout.
reset()Resets the timeout.
complete()Completes the timeout as if it had completed organically.
then()Attach a callback that will be called when the timeout completes. Returns a Promise.

Instance properties

PropertyReadableWritableDescription
durationGet/set timeout duration.
progressFloat between 0 and 1 indicating how much of the timeout's duration has elapsed.
runningWhether the timeout is currently counting down.

Development

Use the following commands to perform code coverage after each change and to open a Browsersync tab to the coverage reports.

npm run watch
npm run serve
1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

5 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago