@wwawing/event-emitter 0.0.0-exe-chousa.based-on.3.12.21

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 WWA Wing Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,8 @@
1
+ import { IEventEmitter } from "../../interface";
2
+ export declare class BrowserEventEmitter implements IEventEmitter {
3
+ private target;
4
+ constructor(target?: HTMLElement);
5
+ dispatch<D>(eventName: string, data: D): void;
6
+ addListener(eventName: string, callback: (...args: any[]) => any): (event: any) => any;
7
+ removeListener(eventName: string, callback: (...args: any[]) => any): void;
8
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BrowserEventEmitter = void 0;
4
+ class BrowserEventEmitter {
5
+ constructor(target) {
6
+ this.target = target !== null && target !== void 0 ? target : document.createElement("div");
7
+ }
8
+ dispatch(eventName, data) {
9
+ const customEvent = new CustomEvent(eventName, { detail: data });
10
+ this.target.dispatchEvent(customEvent);
11
+ }
12
+ addListener(eventName, callback) {
13
+ const wrappedFunction = (event) => callback(event.detail);
14
+ this.target.addEventListener(eventName, wrappedFunction);
15
+ return wrappedFunction;
16
+ }
17
+ removeListener(eventName, callback) {
18
+ this.target.removeEventListener(eventName, callback);
19
+ }
20
+ }
21
+ exports.BrowserEventEmitter = BrowserEventEmitter;
@@ -0,0 +1,2 @@
1
+ export * from "./browser";
2
+ export * from "./node";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./browser"), exports);
18
+ __exportStar(require("./node"), exports);
@@ -0,0 +1,9 @@
1
+ import { IEventEmitter } from "../../interface";
2
+ import { EventEmitter } from "events";
3
+ export declare class NodeEventEmitter implements IEventEmitter {
4
+ private target;
5
+ constructor(target?: EventEmitter);
6
+ dispatch<D>(eventName: string, data: D): void;
7
+ addListener(eventName: string, callback: (...args: any[]) => any): (...args: any[]) => any;
8
+ removeListener(eventName: string, callback: (...args: any[]) => any): void;
9
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NodeEventEmitter = void 0;
4
+ const events_1 = require("events");
5
+ class NodeEventEmitter {
6
+ constructor(target) {
7
+ this.target = target !== null && target !== void 0 ? target : new events_1.EventEmitter();
8
+ }
9
+ dispatch(eventName, data) {
10
+ this.target.emit(eventName, data);
11
+ }
12
+ addListener(eventName, callback) {
13
+ this.target.addListener(eventName, callback);
14
+ return callback;
15
+ }
16
+ removeListener(eventName, callback) {
17
+ this.target.removeListener(eventName, callback);
18
+ }
19
+ }
20
+ exports.NodeEventEmitter = NodeEventEmitter;
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./interface";
2
+ export * from "./impl";
package/lib/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./interface"), exports);
18
+ __exportStar(require("./impl"), exports);
@@ -0,0 +1,5 @@
1
+ export interface IEventEmitter {
2
+ dispatch<D>(eventName: string, data: D): void;
3
+ addListener<N extends string, A extends Array<any>, R>(eventName: N, callback: (...args: A) => R): ((...args: any[]) => any);
4
+ removeListener<N extends string>(eventName: N, callback: (...args: any) => any): void;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ import { IEventEmitter } from "../../interface";
2
+ export declare class BrowserEventEmitter implements IEventEmitter {
3
+ private target;
4
+ constructor(target?: HTMLElement);
5
+ dispatch<D>(eventName: string, data: D): void;
6
+ addListener(eventName: string, callback: (...args: any[]) => any): (event: any) => any;
7
+ removeListener(eventName: string, callback: (...args: any[]) => any): void;
8
+ }
@@ -0,0 +1,17 @@
1
+ export class BrowserEventEmitter {
2
+ constructor(target) {
3
+ this.target = target !== null && target !== void 0 ? target : document.createElement("div");
4
+ }
5
+ dispatch(eventName, data) {
6
+ const customEvent = new CustomEvent(eventName, { detail: data });
7
+ this.target.dispatchEvent(customEvent);
8
+ }
9
+ addListener(eventName, callback) {
10
+ const wrappedFunction = (event) => callback(event.detail);
11
+ this.target.addEventListener(eventName, wrappedFunction);
12
+ return wrappedFunction;
13
+ }
14
+ removeListener(eventName, callback) {
15
+ this.target.removeEventListener(eventName, callback);
16
+ }
17
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./browser";
2
+ export * from "./node";
@@ -0,0 +1,2 @@
1
+ export * from "./browser";
2
+ export * from "./node";
@@ -0,0 +1,9 @@
1
+ import { IEventEmitter } from "../../interface";
2
+ import { EventEmitter } from "events";
3
+ export declare class NodeEventEmitter implements IEventEmitter {
4
+ private target;
5
+ constructor(target?: EventEmitter);
6
+ dispatch<D>(eventName: string, data: D): void;
7
+ addListener(eventName: string, callback: (...args: any[]) => any): (...args: any[]) => any;
8
+ removeListener(eventName: string, callback: (...args: any[]) => any): void;
9
+ }
@@ -0,0 +1,16 @@
1
+ import { EventEmitter } from "events";
2
+ export class NodeEventEmitter {
3
+ constructor(target) {
4
+ this.target = target !== null && target !== void 0 ? target : new EventEmitter();
5
+ }
6
+ dispatch(eventName, data) {
7
+ this.target.emit(eventName, data);
8
+ }
9
+ addListener(eventName, callback) {
10
+ this.target.addListener(eventName, callback);
11
+ return callback;
12
+ }
13
+ removeListener(eventName, callback) {
14
+ this.target.removeListener(eventName, callback);
15
+ }
16
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./interface";
2
+ export * from "./impl";
@@ -0,0 +1,2 @@
1
+ export * from "./interface";
2
+ export * from "./impl";
@@ -0,0 +1,5 @@
1
+ export interface IEventEmitter {
2
+ dispatch<D>(eventName: string, data: D): void;
3
+ addListener<N extends string, A extends Array<any>, R>(eventName: N, callback: (...args: A) => R): ((...args: any[]) => any);
4
+ removeListener<N extends string>(eventName: N, callback: (...args: any) => any): void;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@wwawing/event-emitter",
3
+ "version": "0.0.0-exe-chousa.based-on.3.12.21",
4
+ "description": "nodeでもモダンブラウザでもIE11でも使えるすごいEventEmitter",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/WWAWing/WWAWing.git",
8
+ "directory": "packages/event-emitter"
9
+ },
10
+ "files": [
11
+ "lib",
12
+ "module"
13
+ ],
14
+ "main": "./lib/index.js",
15
+ "module": "./module/index.js",
16
+ "typings": "./lib/index.d.ts",
17
+ "sideEffects": false,
18
+ "scripts": {
19
+ "test": "echo \"Error: no test specified\" && exit 1",
20
+ "build": "npm run clean && run-p build:*",
21
+ "build:lib": "tsc -p .",
22
+ "build:module": "tsc -p ./tsconfig.module.json",
23
+ "clean": "run-p clean:*",
24
+ "clean:lib": "shx rm -rf ./lib",
25
+ "clean:module": "shx rm -rf ./module"
26
+ },
27
+ "author": "WWA Wing Team",
28
+ "license": "MIT",
29
+ "devDependencies": {
30
+ "npm-run-all2": "^8.0.1",
31
+ "shelljs": "^0.9.2",
32
+ "shx": "^0.4.0",
33
+ "typescript": "^5.8.3"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "engines": {
39
+ "node": ">=22",
40
+ "npm": ">=11"
41
+ },
42
+ "gitHead": "b52982378576ed3ef7223fae8457a7923eba7ace"
43
+ }