shelving 1.167.2 → 1.168.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/util/link.js DELETED
@@ -1,44 +0,0 @@
1
- import { RequiredError } from "../error/RequiredError.js";
2
- import { getURL, isURL } from "./url.js";
3
- /** Default whitelist for URL schemes. */
4
- const SCHEMES = ["http:", "https:"];
5
- /**
6
- * Is an unknown value a link URL?
7
- * - A valid link URL is a `URL` instance with a scheme matching the `schemes` array, and `host` matching the optional `hosts` array.
8
- */
9
- export function isLinkURL(value, schemes = SCHEMES, hosts) {
10
- return isURL(value) && schemes.includes(value.protocol) && (!hosts || hosts.includes(value.host));
11
- }
12
- /**
13
- * Convert a possible URL to a link URL, or return `undefined` if conversion fails.
14
- * - A valid link URL is a `URL` instance with a scheme matching the `schemes` array, and `host` matching the optional `hosts` array.
15
- */
16
- export function getLinkURL(value, base, schemes = SCHEMES, hosts) {
17
- const url = getURL(value, base);
18
- if (isLinkURL(url, schemes, hosts))
19
- return url;
20
- }
21
- /**
22
- * Convert a possible URL to a link URL, or throw `RequiredError` if conversion fails.
23
- * - A valid link URL is a `URL` instance with a scheme matching the `schemes` array, and `host` matching the optional `hosts` array.
24
- */
25
- export function requireLinkURL(value, base, schemes, hosts, caller = requireLinkURL) {
26
- const url = getLinkURL(value, base, schemes, hosts);
27
- if (!url)
28
- throw new RequiredError("Invalid link", { received: value, base, schemes, hosts, caller });
29
- return url;
30
- }
31
- /**
32
- * Convert a possible URL to an link URL string, or return `undefined` if conversion fails.
33
- * - A valid link URL string is an absolute URL string with a scheme matching the `schemes` array, and `host` matching the optional `hosts` array.
34
- */
35
- export function getLink(value, base, schemes = SCHEMES, hosts) {
36
- return getLinkURL(value, base, schemes, hosts)?.href;
37
- }
38
- /**
39
- * Convert a possible URL to an link URL string, or throw `RequiredError` if conversion fails.
40
- * - A valid link URL string is an absolute URL string with a scheme matching the `schemes` array, and `host` matching the optional `hosts` array.
41
- */
42
- export function requireLink(value, base, schemes, hosts, caller = requireLink) {
43
- return requireLinkURL(value, base, schemes, hosts, caller).href;
44
- }
File without changes
File without changes
File without changes