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
const timeout = 250
Repeating timeout (setInterval)
const interval = 250 true
Lifecycle callbacks
As a Promise
timeout start
Events
timeoutstart ;
Methods and properties
Instance methods
Method | Chainable | Description |
---|---|---|
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
Property | Readable | Writable | Description |
---|---|---|---|
duration | ✓ | ✓ | Get/set timeout duration. |
progress | ✓ | ✗ | Float between 0 and 1 indicating how much of the timeout's duration has elapsed. |
running | ✓ | ✗ | Whether 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 watchnpm run serve