{"id":21513286,"url":"https://github.com/cn-tower/count-time-down","last_synced_at":"2025-09-11T11:40:54.472Z","repository":{"id":57217815,"uuid":"434482368","full_name":"CN-Tower/count-time-down","owner":"CN-Tower","description":"A helpful countdown class, 一个实用的的倒计时类","archived":false,"fork":false,"pushed_at":"2021-12-12T01:30:20.000Z","size":103,"stargazers_count":7,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-23T20:51:17.079Z","etag":null,"topics":["count-down","count-time-down","countdonw","countdown-js","countdown-pro","countdown-timer","time-countdown"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CN-Tower.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-03T05:53:06.000Z","updated_at":"2022-07-13T02:58:14.000Z","dependencies_parsed_at":"2022-08-28T21:00:32.868Z","dependency_job_id":null,"html_url":"https://github.com/CN-Tower/count-time-down","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CN-Tower%2Fcount-time-down","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CN-Tower%2Fcount-time-down/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CN-Tower%2Fcount-time-down/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CN-Tower%2Fcount-time-down/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CN-Tower","download_url":"https://codeload.github.com/CN-Tower/count-time-down/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248093504,"owners_count":21046694,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["count-down","count-time-down","countdonw","countdown-js","countdown-pro","countdown-timer","time-countdown"],"created_at":"2024-11-23T22:56:28.602Z","updated_at":"2025-04-09T18:53:20.656Z","avatar_url":"https://github.com/CN-Tower.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# count-time-down\n\n[![npm](https://img.shields.io/npm/v/count-time-down.svg)](https://www.npmjs.com/package/count-time-down) \n\n\u003e A helpful countdown class, 一个实用的的倒计时类\n\n## 1 Install \u0026 Import 安装导入\n\n### 1.1 Install\n```bash\n# Use yarn\nyarn add count-time-down\n\n# Use npm\nnpm install count-time-down\n```\n\n### 1.2 Import\n```js\n// Es Module\nimport CountDown from 'count-time-down'; \n\n// In CommonJS\nconst CountDown = require('count-time-down');\n```\n\n## 2 Quick Start 快速上手\n\n### 2.1 Create and automatically start a 24-hour countdown\n\u003e 创建并自动开启一个24小时的倒计时\n\n```js\nnew CountDown(864e5, cd =\u003e console.log(cd.hhmmss));\n```\n\n### 2.2 Create and automatically start a 60s countdown\n\u003e 创建并自动开启一个60s的倒计时\n\n```js\nnew CountDown(60000, { cdType: 's' }, cd =\u003e console.log(cd.s));\n```\n\n### 2.3 Create a countdown that accurate to milliseconds\n\u003e 创建一个可以显示毫秒的定时器\n\n```js\nnew CountDown(10000, { interval: 50 }, ({ss, SSS}) =\u003e {\n  console.log(`${ss} ${SSS}`);\n});\n```\n\n### 2.4 Create a 60s countdown and start it manually\n\u003e 创建一个60s倒计时，手动开始和结束\n\n```js\nconst cd = new CountDown(60000, { autoStart: false }, () =\u003e {\n  console.log(cd);\n});\n// A moment later\ncd.start();\n```\n\n### 2.4 Create a countdown and customize the params\n\u003e 创建一个倒计时，自定义参数再启动\n\n```js\nconst cd = new CountDown();\ncd.time = 10000;\ncd.cdType = 's';\ncd.onTick = cd =\u003e console.log(cd);\ncd.start();\n// A moment later\ncd.stop();\n// A moment later\ncd.start();\n// Destory The countdown\ncd.destory();\n```\n\n## 3 Interface 接口\n```ts\n/**\n * Time，倒计时时间\n */\ntype CountDownTime = number | null | undefined;\n\n/**\n * Initial Options, 倒计时初始化参数\n */\ninterface CountDownOptions {\n  // 倒计时步进间隔，默认: 1000\n  interval?: number;\n  // 是否自动开启，默认为: true\n  autoStart?: boolean;\n  // 倒计时类型，d: 到天，h: 到小时，m: 到分钟，s: 到秒，S: 到毫秒，默认：'h'.\n  cdType?: 'd' | 'h' | 'm' | 's' | 'S';\n}\n \n/**\n * CountDown 构造定义\n */\ndeclare class CountDown {\n  time: number | null;             // 倒计时时间\n  options: CountDownOptions;       // 初始化的参数\n  initTime: number | null;         // 初始化的时间\n  restTime: number;                // 剩余时间\n  interval: number;                // 定时间隔\n  autoStart: boolean;              // 是否自动启动\n  cdType: 'd' | 'h' | 'm' | 's';   // 倒计时类型\n  running: boolean;                // 是否运行中\n  destoryed: boolean;              // 是否已销毁\n  completed: boolean;              // 是否已结束\n  tickTimes: number;               // 步进次数\n  restDays: number | null;         // 剩余天数\n  restHours: number | null;        // 剩余小时\n  restMinuts: number | null;       // 剩余分钟\n  restSeconds: number | null;      // 剩余秒数\n  restMilliSeconds: number | null; // 剩余毫秒数\n  d: number | null;                // 天数\n  h: number | null;                // 小时\n  m: number | null;                // 分钟\n  s: number | null;                // 秒数\n  S: number | null;                // 毫秒数\n  dd: string;                      // 至少两位天数，'--'\n  hh: string;                      // 至少两位小时，'--'\n  mm: string;                      // 至少两位分钟，'--'\n  ss: string;                      // 至少两位秒数，'--'\n  SSS: string;                     // 至少三位毫秒数，'---'\n  ms: string;                      // 分秒，'-:-'\n  hms: string;                     // 时分秒，'-:-:-'\n  mmss: string;                    // 分钟秒数：'--:--'\n  hhmmss: string;                  // 小时分钟秒数：'--:--:--'\n  timerId: any;                    // 定时器ID\n  start: () =\u003e void;               // 开启倒计时\n  stop: () =\u003e void;                // 停止倒计时\n  destory: () =\u003e void;             // 销毁倒计时\n  onTick?: (cd: CountDown) =\u003e any; // 自定义步进处理函数\n  [prop: string]: any;             // 其它属性\n\n  constructor(tickHandler?: (cd: CountDown) =\u003e any);\n  constructor(time: CountDownTime, tickHandler?: (cd: CountDown) =\u003e any);\n  constructor(time: CountDownTime, options: CountDownOptions, tickHandler?: (cd: CountDown) =\u003e any);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcn-tower%2Fcount-time-down","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcn-tower%2Fcount-time-down","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcn-tower%2Fcount-time-down/lists"}