@pirxpilot/nanohref 2.0.0 → 2.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.
Files changed (3) hide show
  1. package/README.md +5 -1
  2. package/index.js +2 -1
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -36,15 +36,19 @@ following conditions:
36
36
  - the link's href starts with protocol handler such as `mailto:` or `dat:`
37
37
  - the link points to a different host
38
38
  - the link has a `download` attribute
39
+ - the link's pathname does not start with the specified `prefix` (if provided)
39
40
 
40
41
  :warning: Note that we only handle `target=_blank` if they also have
41
42
  `rel="noopener"` on them. This is needed to [properly sandbox web
42
43
  pages](https://mathiasbynens.github.io/rel-noopener/).
43
44
 
44
45
  ## API
45
- ### `nanohref(handler(location))`
46
+ ### `nanohref(handler(location), { prefix })`
46
47
  Create a new anchor click handler.
47
48
 
49
+ - `handler(location)` - callback invoked with the new location on anchor click
50
+ - `prefix` - optional pathname prefix; when provided, only links whose pathname starts with the prefix are handled
51
+
48
52
  ## See Also
49
53
  - [MDN/link-types](https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types)
50
54
  - [caniuse/rel=noopener](http://caniuse.com/#feat=rel-noopener)
package/index.js CHANGED
@@ -3,7 +3,7 @@ import assert from 'assert';
3
3
  const safeExternalLink = /noopener/;
4
4
  const protocolLink = /^[\w-_]+:/;
5
5
 
6
- export default function href(cb) {
6
+ export default function href(cb, { prefix }) {
7
7
  assert(typeof cb === 'function', 'nanohref: cb should be type function');
8
8
 
9
9
  window.addEventListener('click', e => {
@@ -16,6 +16,7 @@ export default function href(cb) {
16
16
  window.location.protocol !== anchor.protocol ||
17
17
  window.location.hostname !== anchor.hostname ||
18
18
  window.location.port !== anchor.port ||
19
+ (prefix && !anchor.pathname.startsWith(prefix)) ||
19
20
  anchor.hasAttribute('data-nanohref-ignore') ||
20
21
  anchor.hasAttribute('download') ||
21
22
  (anchor.getAttribute('target') === '_blank' && safeExternalLink.test(anchor.getAttribute('rel'))) ||
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/pirxpilot/nanohref.git"
7
7
  },
8
- "version": "2.0.0",
8
+ "version": "2.1.0",
9
9
  "scripts": {
10
10
  "test": "make check"
11
11
  },
@@ -18,7 +18,7 @@
18
18
  "@pirxpilot/nanoassert": "~1"
19
19
  },
20
20
  "devDependencies": {
21
- "@biomejs/biome": "^1.9.4"
21
+ "@biomejs/biome": "2.4.11"
22
22
  },
23
23
  "keywords": [
24
24
  "nano",