• Stars
    star
    123
  • Rank 290,145 (Top 6 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 10 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An implementation of WHATWG EventTarget interface, plus few extensions.

event-target-shim

npm version Downloads/month Build Status Coverage Status Dependency Status

An implementation of WHATWG EventTarget interface and WHATWG Event interface. This implementation supports constructor, passive, once, and signal.

This implementation is designed ...

  • Working fine on both browsers and Node.js.
  • TypeScript friendly.

Native Support Information:

Feature IE Edge Firefox Chrome Safari Node.js
Event constructor โŒ 12 11 15 6 15.4.0
EventTarget constructor โŒ 87 84 87 14 15.4.0
passive option โŒ 16 49 51 10 15.4.0
once option โŒ 16 50 55 10 15.4.0
signal option โŒ โŒ โŒ โŒ โŒ โŒ

๐Ÿ’ฟ Installation

Use npm or a compatible tool.

npm install event-target-shim

๐Ÿ“– Getting started

import { EventTarget, Event } from "event-target-shim";

// constructor (was added to the standard on 8 Jul 2017)
const myNode = new EventTarget();

// passive flag (was added to the standard on 6 Jan 2016)
myNode.addEventListener(
  "hello",
  (e) => {
    e.preventDefault(); // ignored and print warning on console.
  },
  { passive: true }
);

// once flag (was added to the standard on 15 Apr 2016)
myNode.addEventListener("hello", listener, { once: true });
myNode.dispatchEvent(new Event("hello")); // remove the listener after call.

// signal (was added to the standard on 4 Dec 2020)
const ac = new AbortController();
myNode.addEventListener("hello", listener, { signal: ac.signal });
ac.abort(); // remove the listener.
  • For browsers, there are two ways:
    • use a bundler such as Webpack to bundle. If you want to support IE11, use import {} from "event-target-shim/es5" instead. It's a transpiled code by babel. It depends on @baebl/runtime (^7.12.0) package.
    • use CDN such as unpkg.com. For example, <script src="https://unpkg.com/[email protected]"></script> will define EventTargetShim global variable.
  • The AbortController class was added to the standard on 14 Jul 2017. If you want the shim of that, use abort-controller package.

Runnable Examples

๐Ÿ“š API Reference

See docs/reference.md.

๐Ÿ’ฅ Migrating to v6

See docs/migrating-to-v6.md.

๐Ÿ“ฐ Changelog

See GitHub releases.

๐Ÿป Contributing

Contributing is welcome โค๏ธ

Please use GitHub issues/PRs.

Development tools

  • npm install installs dependencies for development.
  • npm test runs tests and measures code coverage.
  • npm run watch:mocha runs tests on each file change.

More Repositories

1

npm-run-all

A CLI tool to run multiple npm-scripts in parallel or sequential.
JavaScript
5,679
star
2

eslint-plugin-node

Additional ESLint's rules for Node.js
JavaScript
958
star
3

cpx

A cli tool to watch and copy file globs.
JavaScript
524
star
4

eslint-plugin-eslint-comments

Additional ESLint rules for directive comments of ESLint.
JavaScript
359
star
5

abort-controller

An implementation of WHATWG AbortController interface.
TypeScript
301
star
6

regexpp

The regular expression parser for ECMAScript.
TypeScript
150
star
7

eslint-plugin-es

ESLint plugin about ECMAScript syntactic features.
JavaScript
106
star
8

eslint-plugin-vue-trial

Experimental ESLint plugin for Vue.js.
JavaScript
90
star
9

eslint-utils

Utilities for ESLint plugins and custom rules.
JavaScript
74
star
10

eslint-gitignore

A utility for ESLint respecting `.gitignore` files.
TypeScript
39
star
11

eslint4b

ESLint which works in browsers.
JavaScript
37
star
12

vue-eslint-editor

A code editor component to play ESLint.
Vue
35
star
13

vue-eslint-demo

The online demo to check `eslint-plugin-vue`.
JavaScript
31
star
14

react-helix

A small library for immutable design and React.
JavaScript
26
star
15

appcache-manifest

A CLI tool to generate HTML5 Application Cache Manifest.
JavaScript
26
star
16

eslint-plugin

ESLint configurations and additional rules for me
JavaScript
25
star
17

eslint-plugin-dprint

An ESLint plugin that fixes code with dprint
TypeScript
24
star
18

template-eslint-plugin

A repository template for ESLint plugins.
JavaScript
17
star
19

if-node-version

Run a shell command if it's on the node of specified versions.
JavaScript
14
star
20

eslint-plugin-ja

ESLint ใฎใ‚จใƒฉใƒผใƒกใƒƒใ‚ปใƒผใ‚ธใ‚’ๆ—ฅๆœฌ่ชžๅŒ–ใ™ใ‚‹้žๅ…ฌๅผใฎๅฎŸ้จ“็š„ใชใƒ—ใƒฉใ‚ฐใ‚คใƒณใงใ™ใ€‚
JavaScript
12
star
21

bre

A Binary-Object Mapper for JavaScript
TypeScript
10
star
22

eaw

The Node.js module to calculate the width of east Asian characters.
JavaScript
10
star
23

eslint-config

Shareable configurations of ESLint for me.
JavaScript
8
star
24

eslint-evaluating-issues

ESLint evaluating feature issues
JavaScript
8
star
25

spy

Just a spy library.
TypeScript
8
star
26

uptodate

A CLI tool to update dependencies in your package.json.
JavaScript
7
star
27

validia

An object validator library that is TypeScript friendly
TypeScript
7
star
28

eslint-ast

The Extensible Type Definition of ESLint AST
TypeScript
6
star
29

Yammer-for-Developers

[Chrome Extension] The code formater and highlighter in Yammer's messages.
JavaScript
5
star
30

typescript-eslint-demo

A playground for @typescript-eslint.
JavaScript
4
star
31

mocha-assert-snapshot

Snapshot test utilities for Mocha.
TypeScript
4
star
32

warun

CLI tool which does Watch and Run.
JavaScript
4
star
33

type-tester

A tester to check expected type errors
TypeScript
4
star
34

eslint-custom-rule-tutorial

JavaScript
3
star
35

event-source-shim

An implementation for `EventSource` of Server-sent events standard.
TypeScript
2
star
36

run-all

CLI tool to execute multiple commands parallelly.
JavaScript
2
star
37

eslint-plugin-utils

Tools to maintain ESLint plugins
2
star
38

react-helix-examples

Examples for react-helix library.
JavaScript
2
star
39

github-actions-sandbox

JavaScript
2
star
40

hetemel

A HTML parser to make AST which fits for linting.
1
star
41

tools

My tools
TypeScript
1
star
42

fs-watcher

Lightweight file system watchers.
TypeScript
1
star
43

webkit-test

HTML
1
star
44

simple-vue-app

A CLI command to build a simple Vue.js SPA with almost no configuration.
JavaScript
1
star
45

.github

1
star
46

ajx

Simple fetch library for me.
JavaScript
1
star
47

string-replace-unexpected-behavior

Is this a bug?
JavaScript
1
star