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 🙏

© 2025 – Pkg Stats / Ryan Hefner

real-interval

v0.0.6

Published

a not sleep interval timer.

Downloads

15

Readme

real-interval

如果你用setTimeoutsetInterval实现过网页倒计时功能,你就会发现:

当电脑或者APP休眠了一段时间后,倒计时会出现问题:它比正确的时间慢了。

real-interval能解决这个问题。

当休眠的电脑被唤醒后,它会计算出正确的运行时间,你的回调函数可以据此显示正确的剩余时间,或者判断何时应该停止倒计时。

安装

你可以通过npm安装real-interval

npm install real-interval

OR通过脚本引入它:

<script src="./build/interval.js"></script>

usage 1

var timer = new Interval(function(pass){
    
    console.log(pass);
    
    // stop after 24 hours
    if(pass == 60*60*24){
        this.stop();
    };

}, 1000);

// 1
// 2
// 3
// 4
// 5
// 6
// ...
// 86400

这个例子中的 pass 是一个计数器, 表示当前经过了多少个1000毫秒。

usage 2

// automatic stop after 6 seconds
var timer = new Interval(function(pass){

    console.log(pass);

}, 1000, 6);

// 1
// 2
// 3
// 4
// 5
// 6

这个例子中的定时器会在6秒后自动停止。

usage 3

var timer = new Interval(function(pass, surplus){

    console.log('stop after ' + surplus + ' seconds');

}, 1000, 6);

// stop after 5 seconds
// stop after 4 seconds
// stop after 3 seconds
// stop after 2 seconds
// stop after 1 seconds
// stop after 0 seconds

这个例子会显示距离停止还有多少秒。

usage 4

var timer = new Interval(function(pass, surplus){

    console.log('stop after ' + surplus + ' seconds');

}, 1000, 6, true);

// stop after 6 seconds
// stop after 5 seconds
// stop after 4 seconds
// stop after 3 seconds
// stop after 2 seconds
// stop after 1 seconds
// stop after 0 seconds

这个例子与上个例子不同的地方在于, 回调函数会立即被调用, 而不是1秒之后。