js-count-module

JS COUNT MODULE

Simple countdown and countup utility for browsers and npm projects.

What It Does

Installation

npm

npm install @yama-dev/js-count-module

CDN

<script src="https://cdn.jsdelivr.net/gh/yama-dev/js-count-module@v0.5.0/dist/js-count-module.global.js"></script>

Usage

ESM

import COUNT_MODULE from '@yama-dev/js-count-module';
import { JS_COUNT_MODULE } from '@yama-dev/js-count-module';

CommonJS

const { JS_COUNT_MODULE } = require('@yama-dev/js-count-module');

Browser Global

<script src="./js-count-module.global.js"></script>
<script>
  new JS_COUNT_MODULE({
    date: '2026/12/31 23:59:59',
    onUpdate: function(data){
      console.log(data.diffObjParsed);
    }
  });
</script>

Countdown Example

new JS_COUNT_MODULE({
  date: '2026/12/31 23:59:59',
  onUpdate: function(data){
    var diff = data.diffObjParsed;
    console.log(diff.d, diff.hh, diff.mm, diff.ss);
  },
  onComplete: function(data){
    console.log('completed', data);
  }
});

Countup Example

new JS_COUNT_MODULE({
  type: 'up',
  onUpdate: function(data){
    console.log(data.elapsedTime);
  }
});

Exclude Periods

excludePeriods is available for type: 'down'.

new JS_COUNT_MODULE({
  date: '2026/12/31 23:59:59',
  excludePeriods: [
    { start: '12:00', end: '13:00' },
    { start: '03:00', end: '05:00' },
    { start: '2026/05/20 10:00:00', end: '2026/05/20 12:30:00' }
  ]
});

Rules:

Example:

Options

option type default note
type string 'down' 'down' or 'up'
date string '' target date-time for countdown
interval number 1000 update interval in ms
autostart boolean true starts automatically
nowObj Date new Date() base time for countdown
data Array [] multiple countdown targets
endstop boolean true clamps countdown to zero
excludePeriods Array [] excluded countdown periods
onUpdate function null called on every update
onComplete function null called when countdown completes

Callback Payload

onUpdate and onComplete receive:

{
  updating: true,
  date: '2026/12/31 23:59:59',
  diffObj: {},
  diffObjParsed: {
    d: 0,
    h: 0,
    hh: '00',
    m: 0,
    mm: '00',
    s: 0,
    ss: '00',
    ms: 0
  },
  diffMilliSec: 0,
  elapsedTime: 0
}

Methods

Development

npm install
npm run dev

Open http://127.0.0.1:8000/examples/.

Build

npm run build

Build output:

The build output is minified.

Test

npm test

Current tests cover:

License

MIT