
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
@thednp/event-listener
Advanced tools
Modern event listener for efficient applications based on subscribe-publish pattern.
Modern event listener for efficient applications based on the subscribe-publish pattern.
EventListener is less than 900 bytes when minified, but packs a surprising amount of power.
/dist
folder;globalListener
to call them all at once when event is triggered;once
, meaning that when the option is true
, the listener is automatically un-subscribed and detached from target;npm install @thednp/event-listener
<script src="https://cdn.jsdelivr.net/npm/@thednp/event-listener/dist/event-listener.min.js"></script>
import EventListener from '@thednp/event-listener';
// execute a listener once
EventListener.on(document, 'DOMContentLoaded', () => {
console.log('document is now loaded');
}, { once: true });
// add a listener with `useCapture: false`
function handleMyClick(e) {
if (e.target.tagName === 'button') {
e.preventDefault();
e.stopImmediatePropagation();
}
console.log('do something else instead');
}
EventListener.on(document, 'click', handleMyClick, false);
// remove a listener, `EventListener` will get listener options from registry
EventListener.off(document, 'click', handleMyClick);
// add listener to `window`, this listener has no name and cannot be removed
EventListener.on(window, 'scroll', () => console.log(window.scrollY));
Since we're implementing Map
, you can make use of its prototype to access registry:
// get element listener registry
const documentClickListeners = EventListener.registry['click'].get(document);
// returns
Map(1) {
Entries(Array) => [
0: {
key: handleMyClick() // listener
value: false // listener options
}
],
size: 1, // size of the Map
prototype: [Prototype(Object)]
}
// check if element has listener
if (documentClickListeners && documentClickListeners.has(handleMyClick)) {
// do something about it
}
// get listener options
const myListenerOptions = documentClickListeners && documentClickListeners.get(handleMyClick));
// returns false, which is the `useCapture` option value added for `handleMyClick`
You can also make use of "tree shaking" to import only the module you want, for instance:
import { on } from '@thednp/event-listener';
on(document, handleMyClick, true);
Same applies to:
import { addListener } from '@thednp/event-listener/src/event-listener';
addListener(document, handleMyClick, true);
For more advanced use, check out the demo, showcasing the EventListener usage with a demo component.
EventListener is released under the MIT License.
FAQs
🚅 Modern event listener for efficient web applications based on subscribe-publish pattern.
The npm package @thednp/event-listener receives a total of 241,943 weekly downloads. As such, @thednp/event-listener popularity was classified as popular.
We found that @thednp/event-listener demonstrated a healthy version release cadence and project activity because the last version was released less than 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
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.