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

timer-trigger

v1.0.2

Published

Timer Trigger

Readme

timer-trigger

高精度、策略优化的浏览器端一次性定时器工具(TypeScript)。
支持按目标时间触发任务、自动修复前端定时器漂移、相同时间任务共享定时器,并提供取消和立即触发功能。


🔹 特性

  • 一次性任务触发,触发后自动销毁
  • 精确到秒,自动修复前端定时器漂移
  • 相同 targetTime 的任务共用一个定时器,性能优化
  • 支持取消任务、立即触发指定任务或所有任务
  • TypeScript 类型安全,支持浏览器环境

💿 安装

# 使用 npm
npm install timer-trigger

# 使用 yarn
yarn add timer-trigger

使用示例

import { createTimerTrigger } from 'timer-trigger';

const timeTrigger = createTimerTrigger();

// 注册 3 秒后任务
const cancel3s = timeTrigger.once(Date.now() + 3000, () => {
  console.log('3 秒后触发');
});

// 注册 5 秒后任务
timeTrigger.once(Date.now() + 5000, () => {
  console.log('5 秒后触发');
});

// 立即触发指定任务
timeTrigger.emitNow(Date.now() + 5000);

// 立即触发多个任务
timeTrigger.emitNow([Date.now() + 3000, Date.now() + 5000]);

// 取消任务
cancel3s();

// 清理所有任务
timeTrigger.clearAll();

API

createTimerTrigger()

创建一个时间触发器实例。

方法

once(targetTime, callback)

注册一次性任务。

  • 参数
    • targetTime: number | string | Date - 目标时间
    • callback: () => void - 任务回调
  • 返回值
    • () => void - 取消函数,用于取消未触发的任务

emitNow(targetTimes?)

立即触发任务。

  • 参数(可选)
    • targetTimes: number | string | Date | Array<number | string | Date>
    • 单个时间、时间数组或不传(触发所有任务)
  • 返回值
    • void

clearAll()

清理所有未触发任务。

  • 返回值
    • void