Simple countdown and countup utility for browsers and npm projects.
datanpm install @yama-dev/js-count-module
<script src="https://cdn.jsdelivr.net/gh/yama-dev/js-count-module@v0.5.0/dist/js-count-module.global.js"></script>
import COUNT_MODULE from '@yama-dev/js-count-module';
import { JS_COUNT_MODULE } from '@yama-dev/js-count-module';
const { JS_COUNT_MODULE } = require('@yama-dev/js-count-module');
<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>
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);
}
});
new JS_COUNT_MODULE({
type: 'up',
onUpdate: function(data){
console.log(data.elapsedTime);
}
});
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:
HH:mm or HH:mm:ss: recurring every dayYYYY/MM/DD HH:mm:ss: specific one-off periodstart >= end is ignoredtype: 'up' ignores excludePeriodsExample:
12:00-13:00 is excluded| 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 |
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
}
start(dateObj) resumes or starts countingpause() pauses the timerstop() stops the timerdestroy() clears internal statenpm install
npm run dev
Open http://127.0.0.1:8000/examples/.
npm run build
Build output:
dist/js-count-module.cjsdist/js-count-module.mjsdist/js-count-module.global.jsThe build output is minified.
npm test
Current tests cover: