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

timer-countdown-mini

v1.0.8

Published

A JavaScript SDK providing both timer and countdown capabilities. Designed for use in web applications that need precise timing functionalities, with easy-to-use methods for starting, pausing, and resetting timers or countdowns.

Downloads

307

Readme

timer-countdown-mini

imer-countdown-mini 是一个支持计时和倒计时功能的 JavaScript SDK,适用于需要时间控制的前端项目。

安装

可以通过 npm 安装 timer-countdown:

npm install timer-countdown

使用方法

引入 SDK

在项目中引入 TimerSDK,即可使用计时器和倒计时功能。

import { TimerSDK } from 'timer-countdown';

计时器示例

以下是一个使用 Timer 计时器功能的示例:

const timer = TimerSDK.createTimer();
timer.start(); // 开始计时

setTimeout(() => {
  timer.stop(); // 停止计时
  console.log("计时持续时间(秒):", timer.getDuration());
}, 5000); // 5秒后停止

倒计时示例

使用 Countdown 进行倒计时。倒计时结束后,调用指定的回调函数。

const countdown = TimerSDK.createCountdown(0, 0, 10, () => {
  console.log("倒计时结束!");
});

countdown.start(); // 开始倒计时

// 暂停、恢复、取消倒计时
setTimeout(() => countdown.pause(), 5000); // 5秒后暂停
setTimeout(() => countdown.resume(), 7000); // 2秒后恢复
setTimeout(() => countdown.cancel(), 12000); // 12秒后取消

方法列表

TimerSDK

  • createTimer(): 创建一个新的计时器实例。
  • createCountdown(hours, minutes, seconds, onEndCallback): 创建一个倒计时实例,支持设置小时、分钟、秒,并在倒计时结束时触发 onEndCallback。

Timer

  • start(): 开始计时。
  • stop(): 停止计时。
  • pause(): 暂停计时。
  • resume(): 恢复计时。
  • reset(): 重置计时器。
  • lap(): 记录计次时间。
  • getLapTimes(): 获取所有的计次时间。
  • getDuration(): 获取计时总时长。
  • getElapsedDurationInSeconds(): 获取已过去的时间(秒)。

Countdown

  • start(): 开始倒计时。
  • pause(): 暂停倒计时。
  • resume(): 恢复倒计时。
  • cancel(): 取消倒计时。

常见问题

  1. 如何安装依赖?
  • 直接使用 npm install timer-countdown 安装即可。
  1. 是否支持在 Node.js 环境中运行?
  • 本 SDK 主要为前端应用设计,但在 Node.js 环境中也能正常运行。