@irrelon/emitter 6.0.0 → 6.1.0

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.
@@ -0,0 +1,42 @@
1
+ import globals from "globals";
2
+ import pluginJs from "@eslint/js";
3
+ import tseslint from "typescript-eslint";
4
+
5
+
6
+ export default [
7
+ { files: ["**/*.{js,mjs,cjs,ts}"] },
8
+ { languageOptions: { globals: globals.browser } },
9
+ pluginJs.configs.recommended,
10
+ ...tseslint.configs.recommended,
11
+ {
12
+ rules: {
13
+ "@typescript-eslint/no-unnecessary-type-assertion": "off",
14
+ "@typescript-eslint/consistent-type-definitions": "off",
15
+ "@typescript-eslint/no-empty-interface": "off",
16
+ "@typescript-eslint/no-empty-arrow-function": "off",
17
+ "@typescript-eslint/no-empty-function": "off",
18
+ "@typescript-eslint/no-inferrable-types": "off",
19
+ "@typescript-eslint/no-non-null-assertion": "off",
20
+ "@typescript-eslint/strict-boolean-expressions": "off",
21
+ "@typescript-eslint/ban-ts-comment": "off",
22
+ "@typescript-eslint/no-this-alias": "off",
23
+ "@typescript-eslint/no-explicit-any": "off",
24
+ "@typescript-eslint/no-shadow": "error",
25
+ "indent": ["error", "tab"],
26
+ "space-before-function-paren": [
27
+ "error",
28
+ "always"
29
+ ],
30
+ "no-shadow": "off",
31
+ "complexity": [
32
+ "warn",
33
+ 20
34
+ ],
35
+ "max-depth": [
36
+ "warn",
37
+ 4
38
+ ],
39
+ "prefer-rest-params": "off"
40
+ }
41
+ }
42
+ ];
package/jest.config.js ADDED
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ preset: 'ts-jest',
3
+ testEnvironment: 'node',
4
+ moduleNameMapper: {
5
+ "^@/(.*)$": '<rootDir>/$1'
6
+ }
7
+ };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Rob Evans - Irrelon Software Limited",
3
3
  "name": "@irrelon/emitter",
4
4
  "description": "Simple JavaScript event emitter with some powerful features.",
5
- "version": "6.0.0",
5
+ "version": "6.1.0",
6
6
  "keywords": [
7
7
  "javascript",
8
8
  "browser",
@@ -17,30 +17,19 @@
17
17
  "listener"
18
18
  ],
19
19
  "devDependencies": {
20
- "@babel/polyfill": "^7.2.5",
21
- "@babel/runtime": "^7.3.1",
22
- "@types/jest": "^29.5.0",
20
+ "@eslint/js": "^9.5.0",
21
+ "@trivago/prettier-plugin-sort-imports": "^4.3.0",
22
+ "@types/jest": "^29.5.12",
23
23
  "@types/node": "^18.7.23",
24
- "@typescript-eslint/eslint-plugin": "^5.38.1",
25
- "@typescript-eslint/parser": "^5.38.1",
26
24
  "chokidar": "^3.5.3",
27
- "eslint": "8.22.0",
28
- "eslint-config-prettier": "^8.5.0",
29
- "eslint-config-standard-with-typescript": "^23.0.0",
30
- "eslint-plugin-import": "^2.26.0",
31
- "eslint-plugin-jest": "^27.0.4",
32
- "eslint-plugin-node": "^11.1.0",
33
- "eslint-plugin-prettier": "^4.2.1",
34
- "eslint-plugin-promise": "^6.0.1",
35
- "eslint-plugin-standard": "^5.0.0",
36
- "eslint-plugin-tree-shaking": "^1.10.0",
37
- "eslint-plugin-unused-imports": "^2.0.0",
38
- "jest": "^29.1.1",
25
+ "eslint": "^9.5.0",
26
+ "globals": "^15.6.0",
27
+ "jest": "^29.7.0",
39
28
  "minimatch": "^7.4.2",
40
- "prettier": "^2.7.1",
41
- "ts-jest": "^29.0.2",
42
- "typescript": "^5.3.2",
43
- "@trivago/prettier-plugin-sort-imports": "^4.3.0"
29
+ "prettier": "^3.3.2",
30
+ "ts-jest": "^29.1.5",
31
+ "typescript": "^5.5.2",
32
+ "typescript-eslint": "^7.14.1"
44
33
  },
45
34
  "engines": {
46
35
  "node": "*"
@@ -48,9 +37,9 @@
48
37
  "scripts": {
49
38
  "build": "tsc -p tsconfig-esm.json && tsc -p tsconfig-cjs.json && sh ./fixup.sh",
50
39
  "build-watch": "tsc --watch",
51
- "fixPaths": "node fixPaths.cjs",
52
- "test": "NODE_OPTIONS=--experimental-vm-modules npx jest --testMatch \"**/*.test.js\"",
53
- "test-watch": "NODE_OPTIONS=--experimental-vm-modules npx jest --testMatch \"**/*.test.js\" --watchAll"
40
+ "fixPaths": "npx @irrelon/fix-paths --write",
41
+ "test": "NODE_OPTIONS=--experimental-vm-modules npx jest --testMatch \"**/*.test.(js|ts)\"",
42
+ "test-watch": "NODE_OPTIONS=--experimental-vm-modules npx jest --testMatch \"**/*.test.(js|ts)\" --watchAll"
54
43
  },
55
44
  "repository": {
56
45
  "type": "git",
package/readme.md CHANGED
@@ -11,12 +11,22 @@ const emitter = new Emitter();
11
11
  // example this listener will be called with
12
12
  // `isEnabled = true` and `id = "1234"`. You can pass
13
13
  // any number of arguments when calling emit() and
14
- // they will be recieved in order by your listeners
14
+ // they will be recieved in the same order by your
15
+ // event listeners
15
16
  emitter.on("someEvent", (isEnabled, id) => {
16
- return;
17
+ return "someReturnValue1";
17
18
  });
18
19
 
19
- emitter.emit("someEvent", true, "1234");
20
+ // Lets register another listener on the same event
21
+ // that returns a slightly different value
22
+ emitter.on("someEvent", (isEnabled, id) => {
23
+ return "someReturnValue2";
24
+ });
25
+
26
+ // The `results` will contain the return values from
27
+ // all the event listeners registered for the event
28
+ // so in this case ["someReturnValue1", "someReturnValue2"]
29
+ const results = emitter.emit("someEvent", true, "1234");
20
30
  ```
21
31
 
22
32
  ### TypeScript Compatibility
@@ -54,6 +64,11 @@ emitter.emit("event1");
54
64
  // This will not error as you are passing the
55
65
  // expected string argument
56
66
  emitter.emit("event1", "John Smith");
67
+
68
+ // This will correctly infer the type of `result`
69
+ // as a number since the return type was defined
70
+ // in the MyEvents.event1 interface
71
+ const result = emitter.emit("event1", "John Smith");
57
72
  ```
58
73
 
59
74
  ### Extending The Emitter Class
@@ -84,6 +99,8 @@ Your class now inherits the emitter methods:
84
99
  * cancelStatic
85
100
  * deferEmit
86
101
  * willEmit
102
+ * rpc
103
+ * rpcId
87
104
 
88
105
  ### EcmaScript Modules and CommonJS Modules
89
106
  > The package includes both ESM and CJS modules for ease of use.