Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

event-target-shim

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

event-target-shim

An implementation of W3C EventTarget interface.

  • 1.0.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
19M
decreased by-8.76%
Maintainers
1
Weekly downloads
 
Created

What is event-target-shim?

The event-target-shim npm package provides a cross-platform, shim implementation of the EventTarget interface, allowing developers to use a consistent API for event handling across different environments. It supports the standard addEventListener, removeEventListener, and dispatchEvent methods, along with custom event types. This makes it useful for projects that need to handle events in both browser and non-browser environments, such as Node.js applications or web components.

What are event-target-shim's main functionalities?

Basic Event Handling

This demonstrates how to create an instance of EventTarget, add an event listener for a custom event type, and then dispatch an event of that type. It's the basic usage for handling custom events.

const EventTargetShim = require('event-target-shim');
const myEventTarget = new EventTargetShim();

myEventTarget.addEventListener('customEvent', function(event) {
  console.log(`Received: ${event.type}`);
});

myEventTarget.dispatchEvent(new EventTargetShim.Event('customEvent'));

Using Options for addEventListener

This example shows how to use the `once` option with `addEventListener` to automatically remove the event listener after it has been invoked once, demonstrating the package's support for event listener options.

const EventTargetShim = require('event-target-shim');
const myEventTarget = new EventTargetShim();

myEventTarget.addEventListener('customEvent', function(event) {
  console.log(`Received: ${event.type}`);
}, { once: true });

myEventTarget.dispatchEvent(new EventTargetShim.Event('customEvent'));
myEventTarget.dispatchEvent(new EventTargetShim.Event('customEvent'));

Other packages similar to event-target-shim

Keywords

FAQs

Package last updated on 30 Nov 2015

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc