@anephenix/event-emitter 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,6 @@
1
- event-emitter
1
+ # Event Emitter
2
+
3
+ [![npm version](https://badge.fury.io/js/%40anephenix%2Fevent-emitter.svg)](https://badge.fury.io/js/%40anephenix%2Fevent-emitter) ![example workflow](https://github.com/anephenix/event-emitter/actions/workflows/main.yml/badge.svg) [![Socket Badge](https://socket.dev/api/badge/npm/package/@anephenix/event-emitter)](https://socket.dev/npm/package/@anephenix/event-emitter)
2
4
 
3
5
  A small event emitter library, designed for use in front-end applications
4
6
  like Svelte applications.
@@ -15,7 +17,7 @@ npm i @anephenix/event-emitter
15
17
  ## Usage
16
18
 
17
19
  ```typescript
18
- // Load the dependency class
20
+ // Load the dependency class for TypeScript usage
19
21
  import EventEmitter from "@anephenix/event-emitter";
20
22
 
21
23
  // Create an instance of the event emitter class with type safety
@@ -76,11 +78,11 @@ You may find that you'll want to add some type safety to the list of event
76
78
  names that are used in your application, as well as the data payloads that
77
79
  they emit and pass to handler functions.
78
80
 
79
- The library allows you to define that by using a Type that is passed to the
81
+ The library allows you to define that by using a type that is passed to the
80
82
  setup of the EventEmitter instance, like this:
81
83
 
82
84
  ```typescript
83
- interface MyEvents {
85
+ type MyEvents = {
84
86
  message: (data: string) => void;
85
87
  join: (username: string) => void;
86
88
  leave: (username: string) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anephenix/event-emitter",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "A small EventEmitter library",
5
5
  "author": "Paul Jensen <paul@anephenix.com>",
6
6
  "maintainers": [
@@ -22,8 +22,14 @@
22
22
  },
23
23
  "license": "MIT",
24
24
  "type": "module",
25
- "main": "dist/index.js",
26
- "typings": "dist/index.d.ts",
25
+ "main": ".dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "import": "./dist/index.js",
30
+ "types": "./dist/index.d.ts"
31
+ }
32
+ },
27
33
  "files": [
28
34
  "dist",
29
35
  "src"
@@ -1,8 +1,8 @@
1
1
  // Generic type for an event map where each key has a listener signature
2
- type EventMap = Record<string, (...args: any[]) => void>;
2
+ type EventMap = Record<string, (...args: unknown[]) => void>;
3
3
 
4
4
  class EventEmitter<T extends EventMap> {
5
- private events: { [K in keyof T]?: T[K][] } = {};
5
+ events: { [K in keyof T]?: T[K][] } = {};
6
6
  enableLogging = false;
7
7
 
8
8
  log(...args: unknown[]) {
@@ -15,7 +15,7 @@ class EventEmitter<T extends EventMap> {
15
15
  if (!this.events[event]) {
16
16
  this.events[event] = [];
17
17
  }
18
- this.events[event]!.push(listener);
18
+ this.events[event].push(listener);
19
19
  }
20
20
 
21
21
  off<K extends keyof T>(event: K, listener: T[K]): void {
package/src/index.ts CHANGED
@@ -1,2 +1 @@
1
- import EventEmitter from "./EventEmitter";
2
- export default EventEmitter;
1
+ export { default } from "./EventEmitter";