Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@reecem/clockworks
Advanced tools
Using timers and intervals in the webworkers
You can install the package via npm:
npm i @reecem/clockworks
Or use jsDelivr:
...
<script src="https://unpkg.com/@reecem/clockworks?umd"></script>
...
If you are customising the styling and overriding it with your own styling then you will also need an instance of your css or a tailwindcss file installed as only the classes needed are packaged with clockworks
With ClockWorks you can create a new instance of it and specify an array of timers to install in the worker.
Each timer has a set of define values as an object and a callback. These definitions can be added at when instantiating the class or via the push
/pull
methods on the class once it has been created.
/**
* Create a new instance of the class and then print the time to the console.
*
* We will also remove the clock after 5 seconds, by counting a variable.
*/
let triggers = 0;
let clockWorks = new ClockWorks([
{
name: 'clock',
time: 1000,
callback: () => {
console.log((new Date()).toLocaleString())
}
},
{
name: 'remove-clock',
time: 1000,
callback: () => {
if (++triggers >= 5) {
$clock.pull('clock')
$clock.pull('remove-clock')
}
}
}
])
The above example will print the time to the terminal, then it will remove itself and the timer printing the time to the console;
The package installs it's own Web Worker that has been bundled, so there is no need to worry about the specifics of the web worker or it conflicting with other workers that you may have on the webpage. See it here worker.js
The ClockWorks library takes a standard style of interval or timer definition, this allows it to track them to be able to clear them or add them.
{
/**
* A unique name for the timer being created.
*
* This name is used to track the timer.
*/
name: 'Timer',
/**
* The interval of the timer that should be firing in ms
*/
time: 1000,
/**
* The callback function is fired when the timer or interval triggers.
*/
callback: () => {
console.log((new Date()).toLocaleString())
}
}
To add a single timer you will use the instance of the class that you have created and call the push
method with a timer object.
const clockWorks = new ClockWorks();
clockWorks.push({
name: 'new-timer',
time: 5000,
callback: () => {
console.log('New interval has fired at [%s]', (new Date()).toLocaleString());
}
})
Important An error will be thrown when you try to add a timer with the same name twice to the same instance.
push Method
/**
* Add timers to the list.
*
* @param {Object} timer
* @param {String} timer.name
* @param {Number} timer.time
* @param {Function} timer.callback
*
* @return {Number} the index of the timer on the stack
*/
push(timer)
To remove a timer, you will use the name that you have defined when pushing it onto the timer stack.
const clockWorks = new ClockWorks();
// timer that has been defined
clockWorks.push({ name: 'new-timer', ... })
/**
* Removing the timer you will use the name that you assigned the timer.
*/
clockWorks.pull('new-timer');
pull Method
/**
* Remove timer from the stack
*
* @param {String} timer this is the timer name
*/
pull(timer)
setIntervals
Definable from the main class on constructionPENDING...
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email zsh.rce@gmail.com instead of using the issue tracker. You can also use the SECURITY doc.
I enjoy building things and making all manner of programs and helping in open-source projects. If it has been really useful to you and you appreciate it you can leave a star on the repo.
If you have the means, a simple coffee would be also appreciated too.
The MIT License (MIT). Please see License File for more information.
FAQs
Using timers and intervals in the webworker
We found that @reecem/clockworks demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.