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

countdown-pro

v2.0.1

Published

A simple countdown.

Downloads

163

Readme

CountDown

npm npm GitHub

一个简单的倒计时。

查看示例

使用

npmyarn 安装

npm install countdown-pro
yarn add countdown-pro

浏览器引入

在浏览器中使用 script 标签直接引入文件,并使用全局变量 CountDown

  • 该仓库的 dist 目录下提供了 countdown.umd.js 以及 countdown.umd.min.js
  • npm 包的 countdown-pro/dist 目录下也提供了 countdown.umd.js 以及 countdown.umd.min.js
  • 你也可以通过 UNPKG 进行下载。

示例

import CountDown from 'countdown-pro';

const countdown = new CountDown({
  time: 60 * 1000,
  interval: 1000,
  onChange: (time) => {
    console.log(time);
  },
  onEnd: () => {
    console.log('结束');
  }
});

countdown.start();

配置项

| 参数 | 说明 | 类型 | 必填 | 默认值 | | -------- | ------------------ | ----------------------- | ---- | ------ | | time | 倒计时,单位毫秒 | number | Y | 0 | | interval | 时间间隔,单位毫秒 | number | - | 1000 | | onChange | 每次时间间隔时触发 | (currentTime) => void | - | - | | onEnd | 倒计时结束时触发 | () => void | - | - |

实例方法

| 方法名 | 说明 | | ------ | ---------- | | start | 开始倒计时 | | pause | 暂停倒计时 | | reset | 重置倒计时 |

静态方法

内置一些简单日期格式方法,通过 CountDown.方法名 直接调用。

CountDown.format(timestamp, pattern='HH:mm:ss')

格式化时间,返回格式化后的时间字符串

CountDown.format(2 * 60 * 60 * 1000); // "02:00:00"
CountDown.format(2 * 60 * 60 * 1000, 'mm:ss'); // "120:00"

| 参数 | 说明 | 类型 | 必填 | 默认值 | | --------- | ---------------------------------------------- | -------- | ---- | ---------- | | timestamp | 时间戳,单位毫秒 | number | Y | - | | pattern | 时间格式,DD-日,HH-时,mm-分,ss-秒,SSS-毫秒 | string | - | HH:mm:ss |

CountDown.padZero(num, targetLength=2)

前置补零,返回补零后的值

CountDown.padZero(2); // "02"

CountDown.parseTimeData(timestamp)

解析时间戳,返回的时间对象格式 timeData

interface TimeData {
  days: number; // 天数
  hours: number; // 小时
  minutes: number; // 分钟
  seconds: number; // 秒数
  milliseconds: number; // 毫秒
}
CountDown.parseTimeData(2 * 60 * 60 * 1000); // {days: 0, hours: 2, minutes: 0, seconds: 0, milliseconds: 0}