crosshook 1.0.7 → 1.2.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.
Files changed (3) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +37 -6
  3. package/package.json +1 -1
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Manu Mohan
3
+ Copyright (c) 2026 Devfied
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -196,16 +196,47 @@ Use React state / Zustand / Redux instead.
196
196
 
197
197
  ## 🔷 TypeScript Usage (Optional)
198
198
 
199
- You can strongly type events:
199
+ crosshook supports global event typing via module augmentation.
200
+
201
+ This provides:
202
+
203
+ ✅ Event name autocomplete
204
+ ✅ Payload type safety
205
+ ✅ No generics required
206
+
207
+ ✅ 1. Create crosshook.d.ts
208
+
209
+ Place anywhere TypeScript can see (recommended: src/):
200
210
 
201
211
  ``` ts
202
- type Events = {
203
- "toast.show": { message: string };
204
- "modal.open": void;
205
- };
212
+ // src/crosshook.d.ts
213
+ import "crosshook";
214
+
215
+ declare module "crosshook" {
216
+ interface CrosshookEvents {
217
+ "toast.show": { message: string };
218
+ "modal.open": { id: string };
219
+ "user.login": { userId: number };
220
+ }
221
+ }
222
+ ```
223
+
224
+ ✅ 2. Use normally
225
+
226
+ ``` ts
227
+ import { useRegister, call } from "crosshook";
228
+
229
+ // Listener
230
+ useRegister("toast.show", (payload) => {
231
+ // payload is typed as { message: string }
232
+ console.log(payload.message);
233
+ });
234
+
235
+ // Caller
236
+ call("toast.show", { message: "Hello!" });
237
+ // 👆 TypeScript error if payload wrong
206
238
  ```
207
239
 
208
- (Advanced typed helpers coming soon)
209
240
 
210
241
  ------------------------------------------------------------------------
211
242
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crosshook",
3
- "version": "1.0.7",
3
+ "version": "1.2.0",
4
4
  "main": "dist/index.cjs",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",