@pirxpilot/nanohref 1.0.0 → 2.0.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/README.md +1 -1
- package/index.js +16 -17
- package/package.json +10 -5
package/README.md
CHANGED
|
@@ -59,7 +59,7 @@ Create a new anchor click handler.
|
|
|
59
59
|
[npm-url]: https://npmjs.org/package/@pirxpilot/nanohref
|
|
60
60
|
|
|
61
61
|
[build-url]: https://github.com/pirxpilot/nanohref/actions/workflows/check.yaml
|
|
62
|
-
[build-image]: https://img.shields.io/github/workflow/status/pirxpilot/nanohref/check
|
|
62
|
+
[build-image]: https://img.shields.io/github/actions/workflow/status/pirxpilot/nanohref/check.yaml?branch=main
|
|
63
63
|
|
|
64
64
|
[deps-image]: https://img.shields.io/librariesio/release/npm/@pirxpilot/nanohref
|
|
65
65
|
[deps-url]: https://libraries.io/npm/@pirxpilot%2Fnanohref
|
package/index.js
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
import assert from 'assert';
|
|
2
2
|
|
|
3
|
-
const safeExternalLink = /noopener
|
|
4
|
-
const protocolLink = /^[\w-_]
|
|
3
|
+
const safeExternalLink = /noopener/;
|
|
4
|
+
const protocolLink = /^[\w-_]+:/;
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function href (cb) {
|
|
9
|
-
assert(typeof cb === 'function', 'nanohref: cb should be type function')
|
|
6
|
+
export default function href(cb) {
|
|
7
|
+
assert(typeof cb === 'function', 'nanohref: cb should be type function');
|
|
10
8
|
|
|
11
9
|
window.addEventListener('click', e => {
|
|
12
|
-
if ((e.button && e.button !== 0) ||
|
|
13
|
-
e.ctrlKey || e.metaKey || e.altKey || e.shiftKey ||
|
|
14
|
-
e.defaultPrevented) return
|
|
10
|
+
if ((e.button && e.button !== 0) || e.ctrlKey || e.metaKey || e.altKey || e.shiftKey || e.defaultPrevented) return;
|
|
15
11
|
|
|
16
|
-
const anchor = e.target.closest('a[href]')
|
|
17
|
-
if (!anchor) return
|
|
12
|
+
const anchor = e.target.closest('a[href]');
|
|
13
|
+
if (!anchor) return;
|
|
18
14
|
|
|
19
|
-
if (
|
|
15
|
+
if (
|
|
16
|
+
window.location.protocol !== anchor.protocol ||
|
|
20
17
|
window.location.hostname !== anchor.hostname ||
|
|
21
18
|
window.location.port !== anchor.port ||
|
|
22
19
|
anchor.hasAttribute('data-nanohref-ignore') ||
|
|
23
20
|
anchor.hasAttribute('download') ||
|
|
24
21
|
(anchor.getAttribute('target') === '_blank' && safeExternalLink.test(anchor.getAttribute('rel'))) ||
|
|
25
|
-
protocolLink.test(anchor.getAttribute('href'))
|
|
22
|
+
protocolLink.test(anchor.getAttribute('href'))
|
|
23
|
+
)
|
|
24
|
+
return;
|
|
26
25
|
|
|
27
|
-
e.preventDefault()
|
|
28
|
-
cb(anchor)
|
|
29
|
-
})
|
|
26
|
+
e.preventDefault();
|
|
27
|
+
cb(anchor);
|
|
28
|
+
});
|
|
30
29
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pirxpilot/nanohref",
|
|
3
3
|
"description": "Tiny href click handler library",
|
|
4
|
-
"repository":
|
|
5
|
-
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/pirxpilot/nanohref.git"
|
|
7
|
+
},
|
|
8
|
+
"version": "2.0.0",
|
|
6
9
|
"scripts": {
|
|
7
|
-
"test": "
|
|
10
|
+
"test": "make check"
|
|
8
11
|
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"exports": "./index.js",
|
|
9
14
|
"browser": {
|
|
10
15
|
"assert": "@pirxpilot/nanoassert"
|
|
11
16
|
},
|
|
@@ -13,7 +18,7 @@
|
|
|
13
18
|
"@pirxpilot/nanoassert": "~1"
|
|
14
19
|
},
|
|
15
20
|
"devDependencies": {
|
|
16
|
-
"
|
|
21
|
+
"@biomejs/biome": "^1.9.4"
|
|
17
22
|
},
|
|
18
23
|
"keywords": [
|
|
19
24
|
"nano",
|
|
@@ -26,4 +31,4 @@
|
|
|
26
31
|
"files": [
|
|
27
32
|
"index.js"
|
|
28
33
|
]
|
|
29
|
-
}
|
|
34
|
+
}
|