]> Lady’s Gitweb - Pisces/blob - i·r·i.js
089221326cedaa1b1115a9a322224eb94e678113
[Pisces] / i·r·i.js
1 // ♓🌟 Piscēs ∷ i·r·i.js
2 // ====================================================================
3 //
4 // Copyright © 2020, 2022 Lady [@ Lady’s Computer].
5 //
6 // This Source Code Form is subject to the terms of the Mozilla Public
7 // License, v. 2.0. If a copy of the MPL was not distributed with this
8 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
9
10 //deno-lint-ignore-file no-unused-vars
11
12 const sub·delims = String.raw`[!\$&'()*+,;=]`;
13 const gen·delims = String.raw`[:/?#\[\]@]`;
14 const reserved = String.raw`${gen·delims}|${sub·delims}`;
15 const unreserved = String.raw`[A-Za-z0-9\-\._~]`;
16 const pct·encoded = String.raw`%[0-9A-Fa-f][0-9A-Fa-f]`;
17 const dec·octet = String.raw
18 `[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]`;
19 const IPv4address = String.raw
20 `(?:${dec·octet})\.(?:${dec·octet})\.(?:${dec·octet})\.(?:${dec·octet})`;
21 const h16 = String.raw`[0-9A-Fa-f]{1,4}`;
22 const ls32 = String.raw`(?:${h16}):(?:${h16})|${IPv4address}`;
23 const IPv6address = String.raw
24 `(?:(?:${h16}):){6}(?:${ls32})|::(?:(?:${h16}):){5}(?:${ls32})|(?:${h16})?::(?:(?:${h16}):){4}(?:${ls32})|(?:(?:(?:${h16}):){0,1}(?:${h16}))?::(?:(?:${h16}):){3}(?:${ls32})|(?:(?:(?:${h16}):){0,2}(?:${h16}))?::(?:(?:${h16}):){2}(?:${ls32})|(?:(?:(?:${h16}):){0,3}(?:${h16}))?::(?:${h16}):(?:${ls32})|(?:(?:(?:${h16}):){0,4}(?:${h16}))?::(?:${ls32})|(?:(?:(?:${h16}):){0,5}(?:${h16}))?::(?:${h16})|(?:(?:(?:${h16}):){0,6}(?:${h16}))?::`;
25 const IPvFuture = String.raw
26 `v[0-9A-Fa-f]{1,}\.(?:${unreserved}|${sub·delims}|:)`;
27 const IP·literal = String.raw`\[(?:${IPv6address}|${IPvFuture})\]`;
28 const port = String.raw`[0-9]*`;
29 const scheme = String.raw`[A-Za-z][A-Za-z0-9+\-\.]*`;
30 const iprivate = String.raw
31 `[\u{E000}-\u{F8FF}\u{F0000}-\u{FFFFD}\u{100000}-\u{10FFFD}]`;
32 const ucschar = String.raw
33 `[\u{A0}-\u{D7FF}\u{F900}-\u{FDCF}\u{FDF0}-\u{FFEF}\u{10000}-\u{1FFFD}\u{20000}-\u{2FFFD}\u{30000}-\u{3FFFD}\u{40000}-\u{4FFFD}\u{50000}-\u{5FFFD}\u{60000}-\u{6FFFD}\u{70000}-\u{7FFFD}\u{80000}-\u{8FFFD}\u{90000}-\u{9FFFD}\u{A0000}-\u{AFFFD}\u{B0000}-\u{BFFFD}\u{C0000}-\u{CFFFD}\u{D0000}-\u{DFFFD}\u{E0000}-\u{EFFFD}]`;
34 const iunreserved = String.raw`[A-Za-z0-9\-\._~]|${ucschar}`;
35 const ipchar = String.raw
36 `${iunreserved}|${pct·encoded}|${sub·delims}|[:@]`;
37 const ifragment = String.raw`(?:${ipchar}|[/?])*`;
38 const iquery = String.raw`(?:${ipchar}|${iprivate}|[/?])*`;
39 const isegment·nz·nc = String.raw
40 `(?:${iunreserved}|${pct·encoded}|${sub·delims}|@)+`;
41 const isegment·nz = String.raw`(?:${ipchar})+`;
42 const isegment = String.raw`(?:${ipchar})*`;
43 const ipath·empty = String.raw``;
44 const ipath·rootless = String.raw
45 `(?:${isegment·nz})(?:/(?:${isegment}))*`;
46 const ipath·noscheme = String.raw
47 `(?:${isegment·nz·nc})(?:/(?:${isegment}))*`;
48 const ipath·absolute = String.raw
49 `/(?:(?:${isegment·nz})(?:/(?:${isegment}))*)?`;
50 const ipath·abempty = String.raw`(?:/(?:${isegment}))*`;
51 const ipath = String.raw
52 `${ipath·abempty}|${ipath·absolute}|${ipath·noscheme}|${ipath·rootless}|${ipath·empty}`;
53 const ireg·name = String.raw
54 `(?:${iunreserved}|${pct·encoded}|${sub·delims})*`;
55 const ihost = String.raw`${IP·literal}|${IPv4address}|${ireg·name}`;
56 const iuserinfo = String.raw
57 `(?:${iunreserved}|${pct·encoded}|${sub·delims}|:)*`;
58 const iauthority = String.raw
59 `(?:(${iuserinfo})@)?(${ihost})(?::(${port}))?`;
60 const irelative·part = String.raw
61 `//(${iauthority})(${ipath·abempty})|(${ipath·absolute})|(${ipath·noscheme})|(${ipath·empty})`;
62 const irelative·ref = String.raw
63 `(${irelative·part})(?:\?(${iquery}))?(?:#(${ifragment}))?`;
64 const ihier·part = String.raw
65 `//(${iauthority})(${ipath·abempty})|(${ipath·absolute})|(${ipath·rootless})|(${ipath·empty})`;
66 const absolute·IRI = String.raw
67 `(${scheme}):(${ihier·part})(?:\?(${iquery}))?`;
68 const IRI = String.raw
69 `(${scheme}):(${ihier·part})(?:\?(${iquery}))?(?:#(${ifragment}))?`;
70 const IRI·reference = String.raw`(${IRI})|(${irelative·ref})`;
71
72 export const isI·R·I = ($) =>
73 typeof $ == "string" && isI·R·I.regExp.test($);
74 Object.defineProperty(isI·R·I, "regExp", {
75 configurable: true,
76 enumerable: false,
77 get: () => new RegExp(`^(?:${IRI})$`, "u"),
78 });
This page took 0.048878 seconds and 3 git commands to generate.