Skip to content

Commit

Permalink
initialized repository
Browse files Browse the repository at this point in the history
  • Loading branch information
hornta committed Oct 16, 2021
0 parents commit fc21b97
Show file tree
Hide file tree
Showing 9 changed files with 16,897 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
dist/
coverage/
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Event emitter

![npm (scoped)](https://img.shields.io/npm/v/@hornta/event-emitter) ![npm bundle size (scoped)](https://img.shields.io/bundlephobia/minzip/@hornta/event-emitter)

- Works in Node.JS and the browser
- Zero dependencies
- ESM, CJS & UMD
- Strongly typed events
- Fully tested

## Install

```
npm install @hornta/event-emitter
```

## Usage

```ts
import { EventEmitter } from "@hornta/event-emitter";

interface Events {
message: (message: string) => void;
}

const emitter = new EventEmitter<Events>();

emitter.addListener("message", (message) => {
console.log(message);
});

emitter.emit("message", "👋 🌍!"); // Will log '👋 🌍!' to the console

/* These will trigger TypeScript compilation errors */
emitter.emit("unknown");
emitter.emit("message", { message: "👋 🌍!" });
emitter.addListener("unknown", () => {});
```
6 changes: 6 additions & 0 deletions babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
presets: [
["@babel/preset-env", { targets: { node: "current" } }],
"@babel/preset-typescript",
],
};
8 changes: 8 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* For a detailed explanation regarding each configuration property and type check, visit:
* https://jestjs.io/docs/configuration
*/

module.exports = {
collectCoverage: true,
};

0 comments on commit fc21b97

Please sign in to comment.