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

clocker-js

v1.0.2

Published

clocker-js 是计时器,有 正计时 和 倒计时 功能

Downloads

24

Readme

目录

一.简介
二.安装方式
三、正计时器的使用方式
四、倒计时器的使用方式
五、计时状态
六、接口文档

内容

一、简介

clocker-js 是计时器,有 正计时 和 倒计时 的功能,并且支持计时超时;

如果您在使用该库的过程中有遇到了问题,或者有好的建议和想法,您都可以通过以下方式联系我,期待与您的交流:

二、安装方式

目前,安装方式有以下几种:

方式1:通过 npm 安装

npm install --save clocker-js

方式2:直接下载原代码

您可直接从 本项目的Git仓库 下载,此仓库里包含了 clocker 和 下文的示例代码;clocker 库是 本项目的Git仓库 项目中的 clocker/Clocker.js 文件,您可以直接把该文件拷贝到您的项目中去;然后使用如下代码在您的项目中引入 Clocker

import { Clocker } from "path/to/package/Clocker.js";

或者

import Clocker from "path/to/package/Clocker.js";

三、正计时器的使用方式

  1. 创建 目标时间 对象:

    let targetDate = new Date();
  2. 用目标时间对象初始化计时器实例:

    let clocker = new Clocker(targetDate);  // 创建 计时器对象

    也可以先创建定时器,再更改 目标时间,如下:

    let clocker = new Clocker();  // 创建 计时器对象
    clocker.targetDate = targetDate;  // 更改 目标时间
  3. 在你需要的时候获取定时器实例的相关计时信息;

    let year = clocker.year;
    let month = clocker.month;
    let date = clocker.date;
    let hours = clocker.hours;
    let minutes = clocker.minutes;
    let seconds = clocker.seconds;
       
    console.log(year,month,date,hours,minutes,seconds);

四、倒计时器的使用方式

  1. 创建 目标时间 对象:

    let targetDate = new Date(2020,2,3,13,0,0);
  2. 用目标时间对象初始化计时器实例:

    let clocker = new Clocker(targetDate,true);  // 创建 计时器对象

    也可以先创建定时器,再更改 目标时间,如下:

    let clocker = new Clocker();  // 创建 计时器对象;
    clocker.targetDate = targetDate;  // 更改 目标时间
    clocker.countDown = true;  // 设置 计时器 为倒计时器;
  3. 在你需要的时候获取定时器实例的相关计时信息;

    let year = clocker.year;
    let month = clocker.month;
    let date = clocker.date;
    let hours = clocker.hours;
    let minutes = clocker.minutes;
    let seconds = clocker.seconds;
       
    console.log(year,month,date,hours,minutes,seconds);

五、计时状态

计时器实例有个只读属性 isCounting ,表示计时器的状态;

当 isCounting 的值为 true 时,表示目前正在正常地计时; 当 isCounting 的值为 false 时,表示目处于非正在正常计时状态,具体的含义如下:

  • 在正计时中表示:还未到达开始计时时间;
  • 在倒计时中表示:已经到达结束时间;

并且,当 isCounting 的值为 false 时,实例的 year、month、date、hours、minutes、seconds、milliseconds 均是负值;

六、接口文档

constructor

constructor(targetDate, countDown)

  • @param targetDate : Date 目标时间,在正计时中,目标时间是计时的起始时间;在倒计时中,目标时间为结束时间;默认为当前时间
  • @param countDown : boolean 是否是倒计时,默认为 false

isCounting

  • @readonly : boolean

说明:
计时是否正在正常地进行中

注意:

  • 在正计时中,返回 false 表示:还未到达开始计时时间;
  • 在倒计时中,返回 false 表示:已经到达结束时间;

dateObj

  • @readonly : Date

说明:
获得计时的 Date 对象 (以世界标准时间(UTC)计时)

year

  • @readonly : number

说明:
获得计时的年数

month

  • @readonly : number

说明:
获得计时的月数

date

  • @readonly : number

说明:
获得计时的天数

hours

@readonly : number

说明:
获得计时的小时数

minutes

  • @readonly : number

说明:
获得计时的分钟数

seconds

  • @readonly : number

说明:
获得计时的秒钟数

milliseconds

  • @readonly : number

说明:
获得计时的毫秒数