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 🙏

© 2026 – Pkg Stats / Ryan Hefner

kountdown

v0.1.2

Published

kountdown - 倒计时 -----------------

Readme

kountdown - 倒计时

最新版本 v0.1.0

使用 Usage

<script type="text/javascript" src="http://g.tbcdn.cn/mtb/lib-countdown/1.0.0/countdown.js"></script>
<script type="text/javascript">
//初始化倒计时
var cd = lib.countdown(options);
//启动倒计时
cd.start();
//停止倒计时
cd.stop();
</script>

lib.countdown(options)返回一个倒计时CountDown对象,此对象为内部对象,无法直接实例化。

参数 Options

  • endDate - 倒计时的结束时间点。倒计时必需有此属性,否则会抛错。此属性可以是:

    • Date - 标准值。
    • Number - 表示结束时间点相对于January 1, 1970, 00:00:00 UTC的绝对值,单位是。比如:new Date('2014-12-30 23:00:00').getTime() / 1000。
    • String - 当为字符串时,则:
      • 若以+-开始,则结束时间点以当前时间即new Date()为相对时间点,再加上减去字符串后半部分所表示的时长。后半部分,若是一个数值则为秒数,或为字符串,则会按照日:小时:分钟:秒的格式进行解析。
      • 其他,则尝试直接通过new Date(endDate)转换为Date
    • 其他情况,则尝试直接通过new Date(endDate)转换为Date
  • stringFormatter - 倒计时数据的字符串格式。跟大多数语言的日期格式化类似,比如:dd:hh:mm:ss。 此字串中的特殊字符有:

    • d - 天数。
    • h - 小时。
    • m - 分钟。
    • s - 秒。

    其中,多个相同的字符表示数值的位数,若最高位不够,则用0补齐。注意:若要格式字串里加入特殊字符,需要用\\进行转义。比如:d\\day\\s, hh\\hour\\s, mm\\minute\\s, ss\\secon\\d\\s。 默认值为:d天hh时mm分ss秒

  • interval - 倒计时更新的间隔频率。单位为毫秒。 默认值为:1000,即1秒。

  • correctDateOffset - 修正倒计时的时间偏差值。单位为。此属性可用来修正服务端与客户端的时间差。

  • onUpdate - 倒计时每次更新的回调函数。它接收一个参数data,包含倒计时相关数据:

    • stringValue - 通过stringFormatter格式化后的倒计时字符串值
    • totalSeconds - 倒计时的总秒数
    • days - 倒计时的天数部分。
    • hours - 倒计时的小时部分。
    • minutes - 倒计时的分钟部分。
    • seconds - 倒计时的秒数部分。
  • updateElement - 倒计时的更新元素。可快捷的把倒计时结果通过innerHTML更新到此元素中。

  • onEnd - 倒计时结束的回调函数。

方法 APIs

  • start - 启动倒计时。
  • stop - 停止倒计时。
  • setEndDate(date) - 设置结束时间。

示例 Examples

var cd = lib.countdown({
    endDate: '2014/12/30 23:00:00',
    stringFormatter: 'd天 hh小时mm分ss秒',
    onUpdate: function(data){
        elem.innerHTML = data.stringValue;
    },
    onEnd: function(){
        console.log('countdown ended');
    }
}).start();
var cd = lib.countdown({
    endDate: '+3600',
    correctDateOffset: 10*60, //服务端时间比客户端时间快10分钟
    stringFormatter: 'hh:mm:ss',
    onUpdate: function(data){
        elem.innerHTML = data.stringValue;
    },
    onEnd: function(){
        console.log('countdown ended');
    }
}).start();
var cd = lib.countdown({
    endDate: '+1:20:13:45',
    stringFormatter: 'd\\day\\s, hh\\hour\\s, mm\\minute\\s, ss\\secon\\d\\s',
    onUpdate: function(data){
        elem.innerHTML = data.stringValue;
    },
    onEnd: function(){
        console.log('countdown ended');
    }
}).start();