link-interceptor 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/README.md +55 -0
  2. package/package.json +3 -2
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # link-interceptor
2
+
3
+ Framework-agnostic core for intercepting all `<a>` tag clicks in your SPA. Provides callbacks for internal and external links with URL mutation support.
4
+
5
+ For framework-specific wrappers, see:
6
+ - [vue-link-interceptor](https://www.npmjs.com/package/vue-link-interceptor) — Vue 3 plugin
7
+ - [react-link-interceptor](https://www.npmjs.com/package/react-link-interceptor) — React hook
8
+ - [svelte-link-interceptor](https://www.npmjs.com/package/svelte-link-interceptor) — Svelte action
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install link-interceptor
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```ts
19
+ import { interceptLinks } from 'link-interceptor'
20
+
21
+ const cleanup = interceptLinks({
22
+ onInternalLink(ctx) {
23
+ ctx.preventDefault()
24
+ history.pushState(null, '', ctx.path)
25
+ },
26
+ onExternalLink(ctx) {
27
+ ctx.url.searchParams.set('utm_source', 'myapp')
28
+ },
29
+ })
30
+
31
+ // When done:
32
+ cleanup()
33
+ ```
34
+
35
+ ## API
36
+
37
+ ### `interceptLinks(options): () => void`
38
+
39
+ Registers a capture-phase click listener on `document`. Returns a cleanup function.
40
+
41
+ ### LinkContext
42
+
43
+ | Property | Type | Description |
44
+ |----------|------|-------------|
45
+ | `url` | `URL` | Parsed URL (mutable — changes reflected on `anchor.href`) |
46
+ | `anchor` | `HTMLAnchorElement` | The clicked `<a>` element |
47
+ | `event` | `MouseEvent` | The original click event |
48
+ | `path` | `string` | `url.pathname + url.search + url.hash` |
49
+ | `isExternal` | `boolean` | Whether the link is external |
50
+ | `isModifierClick` | `boolean` | Whether Ctrl/Meta/Shift/Alt was held |
51
+ | `preventDefault()` | `() => void` | Cancel the default navigation |
52
+
53
+ ## License
54
+
55
+ [MIT](https://github.com/babu-ch/link-interceptor/blob/main/LICENSE)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "link-interceptor",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Intercept all <a> tag clicks in your SPA — framework-agnostic core for handling internal and external link navigation.",
5
5
  "keywords": [
6
6
  "anchor",
@@ -13,7 +13,7 @@
13
13
  ],
14
14
  "author": "babu-ch",
15
15
  "license": "MIT",
16
- "homepage": "https://github.com/babu-ch/link-interceptor/tree/main/packages/core",
16
+ "homepage": "https://babu-ch.github.io/link-interceptor/",
17
17
  "repository": {
18
18
  "type": "git",
19
19
  "url": "git+https://github.com/babu-ch/link-interceptor.git",
@@ -27,6 +27,7 @@
27
27
  "node": ">=18.0.0"
28
28
  },
29
29
  "files": [
30
+ "README.md",
30
31
  "dist"
31
32
  ],
32
33
  "type": "module",