event-target-shim

中文文档
6.0.2发布于 2021/01/07MITESM + CJS零依赖近 30 天下载 3亿

An implementation of WHATWG EventTarget interface.

原始使用文档
文档目录7 节
  1. 💿 Installation
  2. 📖 Getting started
  3. 📚 API Reference
  4. 💥 Migrating to v6
  5. 📰 Changelog
  6. 🍻 Contributing
  7. Development tools

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.

💿 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, 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.
  • The AbortController class was added to the standard on 14 Jul 2017. If you want the shim of that, use abort-controller package.

📚 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.

版本与发布记录

event-target-shim 共发布 27 个版本,首次发布于 2015/02/22;过去 12 个月发布了 0 个版本。

版本发布日期距今
6.0.2latest2021/01/075 年前
6.0.12021/01/075 年前
6.0.02021/01/065 年前
5.0.12019/02/197 年前
5.0.02019/01/217 年前
5.0.0-beta.02019/01/187 年前

关于 event-target-shim 的常见问题

event-target-shim 是什么?

An implementation of WHATWG EventTarget interface.

如何安装 event-target-shim?

在项目目录运行 npm install event-target-shim,或使用 pnpm add / yarn add / bun add。

event-target-shim 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/event-target-shim 是否存在。

event-target-shim 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

event-target-shim 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=10.13.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

event-target-shim 可以商用吗?

event-target-shim 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

event-target-shim 的下载量有多少?

根据 npm 官方下载统计,event-target-shim 在 2026/10/05 – 2026/11/03 这 30 天内被下载 296,337,159 次,日均约 9,877,905 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

event-target-shim 还在维护吗?

最新版本 6.0.2 发布于 2021/01/07(5 年前);至今共发布 27 个版本,其中过去 12 个月发布了 0 个;首次发布于 2015/02/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。