-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fc21b97
Showing
9 changed files
with
16,897 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
dist/ | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", () => {}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
Oops, something went wrong.