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

@definejs/timer

v1.0.1

Published

计时器

Readme

Timer.js

计时器。

示例

const Timer = require('@definejs/timer');
const timer = new Timer();

timer.start();

setTimeout(() => {
    //等同于:
    //let info = timer.stop('ms');
    let info = timer.stop();        //停止计时,并以毫秒为单位对耗时进行转换。
    

    console.log(info);

}, 3000);


setTimeout(() => {
    let info = timer.stop('m'); //停止计时,并以分钟为单位对耗时进行转换。
    let list = timer.list();    //获取所有的计时历史,返回一个数组。

    console.log(info);
    console.log(list);  

}, 61*1000);

方法

start()

开始计时。

stop(unit = 'ms')

停止计时,返回计时的相关信息,并保存到计时历史列表中。

参数

unit

类型:string。
对时间差进行转换的单位,可取的值为:

  • ms: 毫秒(默认值)。
  • s: 秒。
  • m: 分。
  • h: 小时。
  • d: 天。

返回值

返回的计时信息结构为:

{ 
    t0: Date,       //开始时间,Date 实例。
    t1: Date,       //结束时间,Date 实例。
    dt: Number,     //时间差,即耗时,单位为毫秒。
    value: Number,  //针对参数 unit 传入的单位转换后的时间差值向上取整的整数。 
    unit: string,   //参数 unit 传入的值。
}

reset()

重置计时器,回到创建时的状态,会清空计时历史列表。

list()

获取所有的历史计时列表信息,返回一个数组。