emitochondria 1.2.0 → 1.2.1

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
@@ -256,35 +256,6 @@ const events = createEmitochondria<MyEvents>({
256
256
  });
257
257
  ```
258
258
 
259
- ## ⚡ Biological API (Alternative Naming)
260
-
261
- Emitochondria offers biologically-themed aliases for all methods. Use whichever style fits your project:
262
-
263
- | Standard API | Biological Alias | Description |
264
- |--------------|------------------|-------------|
265
- | `.on()` | `.bind()` | Bind a receptor to a signal |
266
- | `.off()` | `.release()` | Release a receptor |
267
- | `.emit()` | `.pulse()` | Pulse energy through the system |
268
- | `.emitAsync()` | `.cascade()` | Trigger a signal cascade |
269
- | `.once()` | `.spike()` | Single spike of energy |
270
- | `.onAny()` | `.membrane()` | Membrane catches all signals |
271
- | `.clear()` | `.apoptosis()` | Programmed cell death |
272
- | `.listenerCount()` | `.receptors()` | Count of receptors |
273
-
274
- ```typescript
275
- // Standard API
276
- events.on('user:login', handler);
277
- events.emit('user:login', data);
278
-
279
- // Biological API - same functionality, different style
280
- events.bind('user:login', handler);
281
- events.pulse('user:login', data);
282
-
283
- // Mix and match freely
284
- events.bind('save', async (data) => await saveToDatabase(data));
285
- await events.cascade('save', { id: '123' });
286
- ```
287
-
288
259
  ## TypeScript Magic
289
260
 
290
261
  The type system prevents mistakes at compile time:
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Import the compiled CLI
4
+ require('../dist/cli/index.cjs');
@@ -0,0 +1,258 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __commonJS = (cb, mod) => function __require() {
10
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+
29
+ // package.json
30
+ var require_package = __commonJS({
31
+ "package.json"(exports2, module2) {
32
+ module2.exports = {
33
+ name: "emitochondria",
34
+ version: "1.2.1",
35
+ type: "module",
36
+ description: "The powerhouse of your events \u2014 A tiny, fully-typed event emitter for TypeScript with built-in error handling and memory leak detection",
37
+ author: "Pablo D\xEDaz A.K.A exudev",
38
+ license: "MIT",
39
+ bin: {
40
+ emitochondria: "./bin/emitochondria.cjs"
41
+ },
42
+ keywords: [
43
+ "events",
44
+ "emitter",
45
+ "event-emitter",
46
+ "typescript",
47
+ "typed",
48
+ "pubsub",
49
+ "pub-sub",
50
+ "subscribe",
51
+ "publish",
52
+ "error-handling",
53
+ "memory-leak-detection",
54
+ "async",
55
+ "type-safe"
56
+ ],
57
+ repository: {
58
+ type: "git",
59
+ url: "https://github.com/Exudev/emitochondria.git"
60
+ },
61
+ main: "./dist/index.js",
62
+ module: "./dist/index.mjs",
63
+ types: "./dist/index.d.ts",
64
+ exports: {
65
+ ".": {
66
+ import: {
67
+ types: "./dist/index.d.mts",
68
+ default: "./dist/index.mjs"
69
+ },
70
+ require: {
71
+ types: "./dist/index.d.ts",
72
+ default: "./dist/index.js"
73
+ }
74
+ },
75
+ "./schema.json": "./schema.json"
76
+ },
77
+ files: [
78
+ "dist",
79
+ "bin",
80
+ "schema.json"
81
+ ],
82
+ sideEffects: false,
83
+ scripts: {
84
+ build: "tsup",
85
+ test: "vitest",
86
+ "test:run": "vitest run",
87
+ "test:coverage": "vitest run --coverage",
88
+ prepublishOnly: "npm run test:run && npm run build"
89
+ },
90
+ devDependencies: {
91
+ "@types/node": "^25.0.3",
92
+ tsup: "^8.5.1",
93
+ typescript: "^5.9.3",
94
+ vitest: "^4.0.16"
95
+ }
96
+ };
97
+ }
98
+ });
99
+
100
+ // src/cli/index.ts
101
+ var fs = __toESM(require("fs"), 1);
102
+ var path = __toESM(require("path"), 1);
103
+ var readline = __toESM(require("readline"), 1);
104
+ var CONFIG_FILENAME = "emitochondria.config.json";
105
+ var SCHEMA_URL = "https://unpkg.com/emitochondria/schema.json";
106
+ var DEFAULT_CONFIG = {
107
+ $schema: SCHEMA_URL,
108
+ maxListeners: 10,
109
+ logging: {
110
+ timestamps: false,
111
+ timestampFormat: "iso",
112
+ timezone: "utc",
113
+ persist: false,
114
+ path: "./logs/emitochondria.log",
115
+ format: "text",
116
+ maxSize: "10MB",
117
+ logEvents: false,
118
+ logErrors: true,
119
+ logWarnings: true
120
+ }
121
+ };
122
+ var c = {
123
+ reset: "\x1B[0m",
124
+ bold: "\x1B[1m",
125
+ green: "\x1B[32m",
126
+ yellow: "\x1B[33m",
127
+ blue: "\x1B[34m",
128
+ cyan: "\x1B[36m",
129
+ red: "\x1B[31m",
130
+ dim: "\x1B[2m"
131
+ };
132
+ function log(icon, color, msg) {
133
+ console.log(`${color}${icon}${c.reset} ${msg}`);
134
+ }
135
+ var info = (msg) => log("\u2139", c.blue, msg);
136
+ var success = (msg) => log("\u2713", c.green, msg);
137
+ var warn = (msg) => log("\u26A0 ", c.yellow, msg);
138
+ var error = (msg) => log("\u2717", c.red, msg);
139
+ function prompt(question) {
140
+ const rl = readline.createInterface({
141
+ input: process.stdin,
142
+ output: process.stdout
143
+ });
144
+ return new Promise((resolve) => {
145
+ rl.question(question, (answer) => {
146
+ rl.close();
147
+ resolve(answer.trim().toLowerCase());
148
+ });
149
+ });
150
+ }
151
+ function printHelp() {
152
+ console.log(`
153
+ ${c.bold}\u{1F9EC} Emitochondria CLI${c.reset}
154
+ ${c.dim}The powerhouse of your events${c.reset}
155
+
156
+ ${c.bold}Usage:${c.reset}
157
+ npx emitochondria <command>
158
+
159
+ ${c.bold}Commands:${c.reset}
160
+ init Create emitochondria.config.json
161
+ init --force Overwrite existing config file
162
+ help Show this help message
163
+
164
+ ${c.bold}Examples:${c.reset}
165
+ ${c.dim}# Create config file${c.reset}
166
+ npx emitochondria init
167
+
168
+ ${c.dim}# Overwrite existing config${c.reset}
169
+ npx emitochondria init --force
170
+
171
+ ${c.bold}Documentation:${c.reset}
172
+ https://github.com/Exudev/emitochondria
173
+ `);
174
+ }
175
+ function printVersion() {
176
+ try {
177
+ const pkg = require_package();
178
+ console.log(`v${pkg.version}`);
179
+ } catch {
180
+ console.log("unknown");
181
+ }
182
+ }
183
+ async function initCommand(force) {
184
+ const configPath = path.join(process.cwd(), CONFIG_FILENAME);
185
+ console.log(`
186
+ ${c.bold}\u{1F9EC} Emitochondria${c.reset}
187
+ `);
188
+ if (fs.existsSync(configPath)) {
189
+ if (!force) {
190
+ warn(`${CONFIG_FILENAME} already exists.`);
191
+ const answer = await prompt(` Overwrite? ${c.dim}(y/N)${c.reset} `);
192
+ if (answer !== "y" && answer !== "yes") {
193
+ info("Aborted. No changes made.");
194
+ process.exit(0);
195
+ }
196
+ } else {
197
+ warn("Overwriting existing config file.");
198
+ }
199
+ }
200
+ try {
201
+ const content = JSON.stringify(DEFAULT_CONFIG, null, 2);
202
+ fs.writeFileSync(configPath, content + "\n", "utf8");
203
+ success(`Created ${c.bold}${CONFIG_FILENAME}${c.reset}`);
204
+ console.log(`
205
+ ${c.dim} Location: ${configPath}${c.reset}`);
206
+ console.log(`
207
+ ${c.bold}Next steps:${c.reset}
208
+
209
+ 1. Edit the config file to match your needs
210
+ 2. Import and use emitochondria:
211
+
212
+ ${c.cyan}import { createEmitochondria } from 'emitochondria';${c.reset}
213
+
214
+ ${c.cyan}type MyEvents = {${c.reset}
215
+ ${c.cyan}'user:login': { userId: string };${c.reset}
216
+ ${c.cyan}};${c.reset}
217
+
218
+ ${c.cyan}const events = createEmitochondria<MyEvents>();${c.reset}
219
+
220
+ ${c.dim}\u{1F4D6} Docs: https://github.com/Exudev/emitochondria${c.reset}
221
+ `);
222
+ } catch (err) {
223
+ error(`Failed to create config file: ${err}`);
224
+ process.exit(1);
225
+ }
226
+ }
227
+ async function main() {
228
+ const args = process.argv.slice(2);
229
+ const command = args[0];
230
+ const flags = args.slice(1);
231
+ const hasForce = flags.includes("--force") || flags.includes("-f");
232
+ switch (command) {
233
+ case "init":
234
+ await initCommand(hasForce);
235
+ break;
236
+ case "help":
237
+ case "--help":
238
+ case "-h":
239
+ case void 0:
240
+ printHelp();
241
+ break;
242
+ case "version":
243
+ case "--version":
244
+ case "-v":
245
+ printVersion();
246
+ break;
247
+ default:
248
+ error(`Unknown command: ${command}`);
249
+ console.log(`
250
+ Run ${c.cyan}npx emitochondria help${c.reset} for usage.
251
+ `);
252
+ process.exit(1);
253
+ }
254
+ }
255
+ main().catch((err) => {
256
+ error(`Unexpected error: ${err}`);
257
+ process.exit(1);
258
+ });
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "emitochondria",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "type": "module",
5
5
  "description": "The powerhouse of your events — A tiny, fully-typed event emitter for TypeScript with built-in error handling and memory leak detection",
6
6
  "author": "Pablo Díaz A.K.A exudev",
7
7
  "license": "MIT",
8
+ "bin": {
9
+ "emitochondria": "./bin/emitochondria.cjs"
10
+ },
8
11
  "keywords": [
9
12
  "events",
10
13
  "emitter",
@@ -42,6 +45,7 @@
42
45
  },
43
46
  "files": [
44
47
  "dist",
48
+ "bin",
45
49
  "schema.json"
46
50
  ],
47
51
  "sideEffects": false,