npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

clockwarp

v1.0.3

Published

JavaScript alternative to setTimeout offering time manipulation features

Downloads

3

Readme

npm version

ClockWrap

ClockWarp is an alternative to the built-in setTimeout and setInterval functions. This library provides time manipulation capabilities that allow you to adjust the timing of events in your code. ClockWarp has a time multiplier which can be used to make all events run faster or slower, and it also has a fastForward method that can be used to move time forward.

Installation

To install the latest version on npm locally and save it in your package's package.json file:

npm i --save clockwarp

Example

const clock = new ClockWrap()

clock.setTimeout(() => console.log("Hello World"), 5000);
clock.setTimeout(() => console.log("This is another message"), 5500);

clock.fastForward(5000)
// console output: Hello World

// wait another 500ms
await new Promise((done) => setTimeout(done, 500));
// console output: This is another message

API Documentation

ClockWarp

Handle events execution on the timeline allowing time manipulation

Kind: global class

new ClockWarp()

Constructor

clockWarp.timeScale

Time multiplier for the clock. For example, when setting the value to 2, all events are going to be executed twice faster than usual.

Kind: instance property of ClockWarp

clockWarp.now

equivalent of performance.now(). The value reflects all time manipulations by fastForward or timeScale

Kind: instance property of ClockWarp

clockWarp.fastForward(dt)

Move time of the clock by specified duration. This operation will execute all events scheduled for that duration

Kind: instance method of ClockWarp

| Param | Type | Description | | --- | --- | --- | | dt | Number | amount of miliseconds to fast forward |

clockWarp.setTimeout(callback, duration, [repeat]) ⇒ Object

sets a timer which executes a function once the timer expires.

Kind: instance method of ClockWarp
Returns: Object - scheduled event object

| Param | Type | Default | Description | | --- | --- | --- | --- | | callback | function | | A function to be executed after the timer expires. | | duration | Number | | The time, in milliseconds that the timer should wait before the specified function or code is executed. | | [repeat] | Boolean | false | internal. cause function to work as setInterval |

clockWarp.setInterval(callback, duration) ⇒ Object

repeatedly calls a function, with a fixed time delay between each call.

Kind: instance method of ClockWarp
Returns: Object - scheduled event object

| Param | Type | Description | | --- | --- | --- | | callback | function | A function to be executed every duration milliseconds. The first execution happens after delay milliseconds. | | duration | Number | The time, in milliseconds that the timer should wait before the specified function or code is executed. |

clockWarp.clear(event)

cancels an event previously established by calling setTimeout or setInterval

Kind: instance method of ClockWarp

| Param | Type | Description | | --- | --- | --- | | event | Object | event object to be canceled |