A simple to use countdown library
npm install cntdwn.js
- start()
- cancel()
- pause()
- resume()
- getTimeleft()
- getTimeFrom()
- getTimeTo()
- isPaused()
- isRunning()
- setTimeFrom()
- setTimeTo()
- setOnTick()
- setOnStart()
- setOnCancel()
- setOnFinish()
- setOnPause()
- setOnResume()
Sets up the new countdown.
None
The current object instance.
const cntdwn = new Cntdwn({
from: 5000,
to: 0,
});
cntdwn.start();
Stops the countdown.
None
The current object instance.
const cntdwn = new Cntdwn({
from: 5000,
to: 0,
});
cntdwn.start();
cntdwn.cancel();
Pauses the countdown.
None
The current object instance.
const cntdwn = new Cntdwn({
from: 5000,
to: 0,
});
cntdwn.start();
cntdwn.pause();
Resumes the countdown.
None
The current object instance.
const cntdwn = new Cntdwn({
from: 5000,
to: 0,
});
cntdwn.start();
cntdwn.pause();
cntdwn.resume();
Checks how much time is left before the countdown ends.
None
The current time of the countdown.
const cntdwn = new Cntdwn({
from: 5000,
to: 0,
});
cntdwn.start();
cntdwn.getTimeleft(); // 5000
Gets the start time of the countdown.
None
The start time of the countdown.
const cntdwn = new Cntdwn({
from: 5000,
to: 0,
});
cntdwn.getTimeFrom(); // 5000
Gets the end time of the countdown.
None
The end time of the countdown.
const cntdwn = new Cntdwn({
from: 5000,
to: 0,
});
cntdwn.getTimeTo(); // 0
Checks if the countdown is paused.
None
The boolean of the pause state.
const cntdwn = new Cntdwn({
from: 5000,
to: 0,
});
cntdwn.start();
cntdwn.isPaused(); // false
Checks if the countdown is running.
None
The boolean of the running state.
const cntdwn = new Cntdwn({
from: 5000,
to: 0,
});
cntdwn.start();
cntdwn.isRunning(); // true
Sets the time the countdown will start from. Using this method during the countdown results in canceling the countdown.
Time in milliseconds.
The current object instance.
const cntdwn = new Cntdwn({
from: 5000,
to: 0,
});
cntdwn.setTimeFrom(5000);
Sets the time when the countdown will end. Using this method during the countdown results in canceling the countdown.
Time in milliseconds.
The current object instance.
const cntdwn = new Cntdwn({
from: 5000,
to: 0,
});
cntdwn.setTimeTo(0);
Sets the callback function for the 'tick' event.
The callback function with no parameters.
The current object instance.
const cntdwn = new Cntdwn({
from: 5000,
to: 0,
});
cntdwn.setOnTick(() => {
console.log('Tick!');
});
Sets the callback function for the 'start' event.
The callback function with no parameters.
The current object instance.
const cntdwn = new Cntdwn({
from: 5000,
to: 0,
});
cntdwn.setOnStart(() => {
console.log('Started!');
});
Sets the callback function for the 'cancel' event.
The callback function with no parameters.
The current object instance.
const cntdwn = new Cntdwn({
from: 5000,
to: 0,
});
cntdwn.setOnCancel(() => {
console.log('Canceled!');
});
Sets the callback function for the 'finish' event.
The callback function with no parameters.
The current object instance.
const cntdwn = new Cntdwn({
from: 5000,
to: 0,
});
cntdwn.setOnFinish(() => {
console.log('Finished!');
});
Sets the callback function for the 'pause' event.
The callback function with no parameters.
The current object instance.
const cntdwn = new Cntdwn({
from: 5000,
to: 0,
});
cntdwn.setOnPause(() => {
console.log('Paused!');
});
Sets the callback function for the 'resume' event.
The callback function with no parameters.
The current object instance.
const cntdwn = new Cntdwn({
from: 5000,
to: 0,
});
cntdwn.setOnResume(() => {
console.log('Resumed!');
});
Triggers the function if set by setOnTick or in the constructor every 10ms.
Triggers the function if set by setOnStart or in the constructor after running the start() function.
Triggers the function if set by setOnFinish or in the constructor after the countdown ends.
Triggers the function if set by setOnPause or in the constructor after running the pause() function.
Triggers the function if set by setOnResume or in the constructor after running the resume() function.
Triggers the function if set by setOnCancel or in the constructor after running the cancel() function.
Options which return the current object instance can be chained together like so:
const cntdwn = new Cntdwn({
from: 5000,
to: 0,
});
cntdwn
.setOnStart(() => console.log('Started!'))
.setOnFinish(() => console.log('Finished!'))
.setOnPause(() => console.log('Paused!'))
.setOnResume(() => console.log('Resumed!'))
.setOnCancel(() => console.log('Canceled!'))
.start();
Licensed under the MIT license