timerpro
v1.0.2
Published
Manage intervals and timeouts like a pro
Downloads
2
Readme
Since intervals and timeouts lists are not saved on the browser. This package helps you to manage them.
Add “TimerPro” to your project:
NodeJs
const timerPro = require("timerpro");
Browser:
<script src="https://cdn.jsdelivr.net/npm/timerpro/dist/timerpro.min.js"></script>
Methods:
Create new timeout (setTimeout)
- name: Timeout name
- func: Code to run
- delay: Run code after ms
- args: Array of arguments to pass inside the func
- reset: Auto reset before next run
timerPro.new.timeout(name, func, delay, args = [], reset = false);
Example:
timerPro.new.timeout("MyTimeout", (i, msg) => {
console.log(`${i} - ${msg}`);
}, 5000, [1, "Hello World !"]);
Create new interval (setInterval)
- name: Interval name
- func: Code to run
- delay: Run code after ms
- args: Array of arguments to pass inside the func
- reset: Auto reset before next run
timerPro.new.interval(name, func, delay, args = [], reset = false);
Example:
timerPro.new.interval("MyInterval", (i, msg) => {
console.log(`${i} - ${msg}`);
}, 5000, [1, "Hello World !"]);
Get all timers
Get all the timers (timeout and interval) in a Object.
timerPro.timerAll();
Example:
console.log(timerPro.timerAll());
Clear timers
Clear timers by name. Use all to clear all the timers.
timerPro.clear.timeout(name)
timerPro.clear.interval(name)
timerPro.clear.all()
Clean timers
Clean and reorder finished timers by name. Use all to clean and reorder all the timers.
timerPro.clean.timeout(name)
timerPro.clean.interval(name)
timerPro.clean.all()
Reset timers
Automatically clear and clean the timers.
timerPro.reset.timeout(name)
timerPro.reset.interval(name)