slimevents 0.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.
- package/LICENSE +0 -0
- package/README.md +23 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.esm.js +1 -0
- package/dist/index.umd.js +1 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
File without changes
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# slimevents
|
|
2
|
+
|
|
3
|
+
A lightweight event emitter library with batch event listening support, built on top of nanoevents.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ๐ **Ultra lightweight** (< 1KB gzipped)
|
|
8
|
+
- ๐ฆ **Zero dependencies** (only nanoevents as peer dependency)
|
|
9
|
+
- ๐ง **Full TypeScript support**
|
|
10
|
+
- ๐ฏ **Batch event listening** with `onMany` and `onAll`
|
|
11
|
+
- ๐ช **Wildcard event matching** with `onWildcard`
|
|
12
|
+
- ๐งน **Automatic cleanup** with unsubscribe functions
|
|
13
|
+
- ๐ช **Multiple module formats** (ESM, CJS, UMD)
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install slimevents
|
|
19
|
+
|
|
20
|
+
yarn add slimevents
|
|
21
|
+
|
|
22
|
+
pnpm add slimevents
|
|
23
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function t(){const t=Object.create(null);return{on(e,n){const o=String(e);return(t[o]||(t[o]=[])).push(n),()=>{const e=t[o];if(e){const r=e.indexOf(n);r>-1&&e.splice(r,1),0===e.length&&delete t[o]}}},emit(e,...n){const o=t[String(e)]||[];if(o)for(let t=0;t<o.length;t++)try{o[t](...n)}catch(t){}},onMany(t){const e=[];for(const n in t){const o=t[n];"function"==typeof o&&e.push(this.on(n,o))}return()=>{for(let t=0;t<e.length;t++)e[t]()}},onAll(t,e){const n=[];for(let o=0;o<t.length;o++)n.push(this.on(t[o],e));return()=>{for(let t=0;t<n.length;t++)n[t]()}}}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.createSlimEvents=t,exports.default=t;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type Unsubscribe = () => void;
|
|
2
|
+
interface EventMap {
|
|
3
|
+
[key: string]: unknown[];
|
|
4
|
+
}
|
|
5
|
+
interface SlimEvents<Events extends EventMap> {
|
|
6
|
+
on<Event extends keyof Events>(event: Event, callback: (...args: Events[Event]) => void): Unsubscribe;
|
|
7
|
+
emit<Event extends keyof Events>(event: Event, ...args: Events[Event]): void;
|
|
8
|
+
onMany<EventMap extends Partial<Record<keyof Events, (...args: any[]) => void>>>(events: EventMap): Unsubscribe;
|
|
9
|
+
onAll<Event extends keyof Events>(eventNames: Event[], callback: (...args: Events[Event]) => void): Unsubscribe;
|
|
10
|
+
}
|
|
11
|
+
declare function createSlimEvents<Events extends Record<string, unknown[]>>(): SlimEvents<Events>;
|
|
12
|
+
|
|
13
|
+
export { createSlimEvents, createSlimEvents as default };
|
|
14
|
+
export type { EventMap, SlimEvents, Unsubscribe };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function t(){const t=Object.create(null);return{on(n,e){const o=String(n);return(t[o]||(t[o]=[])).push(e),()=>{const n=t[o];if(n){const r=n.indexOf(e);r>-1&&n.splice(r,1),0===n.length&&delete t[o]}}},emit(n,...e){const o=t[String(n)]||[];if(o)for(let t=0;t<o.length;t++)try{o[t](...e)}catch(t){}},onMany(t){const n=[];for(const e in t){const o=t[e];"function"==typeof o&&n.push(this.on(e,o))}return()=>{for(let t=0;t<n.length;t++)n[t]()}},onAll(t,n){const e=[];for(let o=0;o<t.length;o++)e.push(this.on(t[o],n));return()=>{for(let t=0;t<e.length;t++)e[t]()}}}}export{t as createSlimEvents,t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).slimevents={})}(this,function(e){"use strict";function t(){const e=Object.create(null);return{on(t,n){const o=String(t);return(e[o]||(e[o]=[])).push(n),()=>{const t=e[o];if(t){const s=t.indexOf(n);s>-1&&t.splice(s,1),0===t.length&&delete e[o]}}},emit(t,...n){const o=e[String(t)]||[];if(o)for(let e=0;e<o.length;e++)try{o[e](...n)}catch(e){}},onMany(e){const t=[];for(const n in e){const o=e[n];"function"==typeof o&&t.push(this.on(n,o))}return()=>{for(let e=0;e<t.length;e++)t[e]()}},onAll(e,t){const n=[];for(let o=0;o<e.length;o++)n.push(this.on(e[o],t));return()=>{for(let e=0;e<n.length;e++)n[e]()}}}}e.createSlimEvents=t,e.default=t,Object.defineProperty(e,"__esModule",{value:!0})});
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "slimevents",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A lightweight event emitter with batch event listening support (zero dependencies)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs.js",
|
|
7
|
+
"module": "./dist/index.esm.js",
|
|
8
|
+
"browser": "./dist/index.umd.js",
|
|
9
|
+
"unpkg": "./dist/index.umd.js",
|
|
10
|
+
"jsdelivr": "./dist/index.umd.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.esm.js",
|
|
16
|
+
"require": "./dist/index.cjs.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"clean": "rimraf dist",
|
|
24
|
+
"build": "npm run clean && rollup -c",
|
|
25
|
+
"dev": "rollup -c -w",
|
|
26
|
+
"test": "vitest",
|
|
27
|
+
"test:run": "vitest run",
|
|
28
|
+
"size": "echo 'Gzipped sizes:' && gzip-size dist/index.esm.js dist/index.cjs.js dist/index.umd.js",
|
|
29
|
+
"prepublishOnly": "npm run test && npm run build"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"events",
|
|
33
|
+
"emitter",
|
|
34
|
+
"lightweight"
|
|
35
|
+
],
|
|
36
|
+
"author": "yangxinyuan",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
40
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
41
|
+
"rimraf": "^5.0.5",
|
|
42
|
+
"rollup": "^4.9.5",
|
|
43
|
+
"rollup-plugin-dts": "^6.1.0",
|
|
44
|
+
"tslib": "^2.6.2",
|
|
45
|
+
"typescript": "^5.3.3",
|
|
46
|
+
"vitest": "^1.2.2"
|
|
47
|
+
},
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=20"
|
|
50
|
+
}
|
|
51
|
+
}
|