@fedify/vocab-runtime 2.0.0-dev.1908 → 2.0.0-dev.196
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/LICENSE +1 -1
- package/README.md +2 -1
- package/deno.json +7 -1
- package/dist/chunk-DWy1uDak.cjs +39 -0
- package/dist/docloader.test.cjs +5851 -0
- package/dist/docloader.test.d.cts +1 -0
- package/dist/docloader.test.d.ts +1 -0
- package/dist/docloader.test.js +5877 -0
- package/dist/key.test.cjs +272 -0
- package/dist/key.test.d.cts +1 -0
- package/dist/key.test.d.ts +1 -0
- package/dist/key.test.js +271 -0
- package/dist/langstr.test.cjs +51 -0
- package/dist/langstr.test.d.cts +1 -0
- package/dist/langstr.test.d.ts +1 -0
- package/dist/langstr.test.js +50 -0
- package/dist/link-CdFPEo9O.cjs +189 -0
- package/dist/link-Ck2yj4dH.js +183 -0
- package/dist/link.test.cjs +56 -0
- package/dist/link.test.d.cts +1 -0
- package/dist/link.test.d.ts +1 -0
- package/dist/link.test.js +55 -0
- package/dist/mod.cjs +102 -63
- package/dist/mod.js +102 -63
- package/dist/multibase/multibase.test.cjs +346 -0
- package/dist/multibase/multibase.test.d.cts +1 -0
- package/dist/multibase/multibase.test.d.ts +1 -0
- package/dist/multibase/multibase.test.js +345 -0
- package/dist/multibase-BFbBiaPE.cjs +347 -0
- package/dist/multibase-DStmqni9.js +311 -0
- package/dist/request-BPQb2VYj.cjs +138 -0
- package/dist/request-SuYiIZUu.js +108 -0
- package/dist/request.test.cjs +44 -0
- package/dist/request.test.d.cts +1 -0
- package/dist/request.test.d.ts +1 -0
- package/dist/request.test.js +43 -0
- package/dist/url-C5Vs9nYh.cjs +93 -0
- package/dist/url-fW_DHbih.js +63 -0
- package/dist/url.test.cjs +37 -0
- package/dist/url.test.d.cts +1 -0
- package/dist/url.test.d.ts +1 -0
- package/dist/url.test.js +36 -0
- package/package.json +4 -3
- package/src/docloader.test.ts +29 -1
- package/src/docloader.ts +101 -45
- package/tsdown.config.ts +18 -7
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/link.ts
|
|
3
|
+
const parametersNeedLowerCase = ["rel", "type"];
|
|
4
|
+
const regexpLinkWhitespace = /[\n\r\s\t]/;
|
|
5
|
+
function validateURI(uri) {
|
|
6
|
+
if (uri.includes("\n") || regexpLinkWhitespace.test(uri)) throw new SyntaxError(`\`${uri}\` is not a valid URI!`);
|
|
7
|
+
}
|
|
8
|
+
function* parseLinkFromString(input) {
|
|
9
|
+
const inputFmt = input.replaceAll("\xA0", "").replaceAll("", "");
|
|
10
|
+
for (let cursor = 0; cursor < inputFmt.length; cursor += 1) {
|
|
11
|
+
while (regexpLinkWhitespace.test(inputFmt.charAt(cursor))) cursor += 1;
|
|
12
|
+
if (inputFmt.charAt(cursor) !== "<") throw new SyntaxError(`Unexpected character \`${inputFmt.charAt(cursor)}\` at position ${cursor}; Expect character \`<\`!`);
|
|
13
|
+
cursor += 1;
|
|
14
|
+
const cursorEndUri = inputFmt.indexOf(">", cursor);
|
|
15
|
+
if (cursorEndUri === -1) throw new SyntaxError(`Missing end of URI delimiter character \`>\` after position ${cursor}!`);
|
|
16
|
+
if (cursorEndUri === cursor) throw new SyntaxError(`Missing URI at position ${cursor}!`);
|
|
17
|
+
const uriSlice = inputFmt.slice(cursor, cursorEndUri);
|
|
18
|
+
validateURI(uriSlice);
|
|
19
|
+
const uri = decodeURI(uriSlice);
|
|
20
|
+
const parameters = {};
|
|
21
|
+
cursor = cursorEndUri + 1;
|
|
22
|
+
while (regexpLinkWhitespace.test(inputFmt.charAt(cursor))) cursor += 1;
|
|
23
|
+
if (cursor === inputFmt.length || inputFmt.charAt(cursor) === ",") {
|
|
24
|
+
yield [uri, parameters];
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (inputFmt.charAt(cursor) !== ";") throw new SyntaxError(`Unexpected character \`${inputFmt.charAt(cursor)}\` at position ${cursor}; Expect character \`;\`!`);
|
|
28
|
+
cursor += 1;
|
|
29
|
+
while (cursor < inputFmt.length) {
|
|
30
|
+
while (regexpLinkWhitespace.test(inputFmt.charAt(cursor))) cursor += 1;
|
|
31
|
+
const parameterKey = inputFmt.slice(cursor).match(/^[\w-]+\*?/)?.[0].toLowerCase();
|
|
32
|
+
if (typeof parameterKey === "undefined") throw new SyntaxError(`Unexpected character \`${inputFmt.charAt(cursor)}\` at position ${cursor}; Expect a valid parameter key!`);
|
|
33
|
+
cursor += parameterKey.length;
|
|
34
|
+
while (regexpLinkWhitespace.test(inputFmt.charAt(cursor))) cursor += 1;
|
|
35
|
+
if (cursor === inputFmt.length || inputFmt.charAt(cursor) === ",") {
|
|
36
|
+
parameters[parameterKey] = "";
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
if (inputFmt.charAt(cursor) === ";") {
|
|
40
|
+
parameters[parameterKey] = "";
|
|
41
|
+
cursor += 1;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (inputFmt.charAt(cursor) !== "=") throw new SyntaxError(`Unexpected character \`${inputFmt.charAt(cursor)}\` at position ${cursor}; Expect character \`=\`!`);
|
|
45
|
+
cursor += 1;
|
|
46
|
+
while (regexpLinkWhitespace.test(inputFmt.charAt(cursor))) cursor += 1;
|
|
47
|
+
let parameterValue = "";
|
|
48
|
+
if (inputFmt.charAt(cursor) === "\"") {
|
|
49
|
+
cursor += 1;
|
|
50
|
+
while (cursor < inputFmt.length) {
|
|
51
|
+
if (inputFmt.charAt(cursor) === "\"") {
|
|
52
|
+
cursor += 1;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
if (inputFmt.charAt(cursor) === "\\") cursor += 1;
|
|
56
|
+
parameterValue += inputFmt.charAt(cursor);
|
|
57
|
+
cursor += 1;
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
const cursorDiffParameterValue = inputFmt.slice(cursor).search(/[\s;,]/);
|
|
61
|
+
if (cursorDiffParameterValue === -1) {
|
|
62
|
+
parameterValue += inputFmt.slice(cursor);
|
|
63
|
+
cursor += parameterValue.length;
|
|
64
|
+
} else {
|
|
65
|
+
parameterValue += inputFmt.slice(cursor, cursorDiffParameterValue);
|
|
66
|
+
cursor += cursorDiffParameterValue;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
parameters[parameterKey] = parametersNeedLowerCase.includes(parameterKey) ? parameterValue.toLowerCase() : parameterValue;
|
|
70
|
+
while (regexpLinkWhitespace.test(inputFmt.charAt(cursor))) cursor += 1;
|
|
71
|
+
if (cursor === inputFmt.length || inputFmt.charAt(cursor) === ",") break;
|
|
72
|
+
if (inputFmt.charAt(cursor) === ";") {
|
|
73
|
+
cursor += 1;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
throw new SyntaxError(`Unexpected character \`${inputFmt.charAt(cursor)}\` at position ${cursor}; Expect character \`,\`, character \`;\`, or end of the string!`);
|
|
77
|
+
}
|
|
78
|
+
yield [uri, parameters];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Handle the HTTP header `Link` according to the specification RFC 8288.
|
|
83
|
+
*/
|
|
84
|
+
var HttpHeaderLink = class HttpHeaderLink {
|
|
85
|
+
get [Symbol.toStringTag]() {
|
|
86
|
+
return "HTTPHeaderLink";
|
|
87
|
+
}
|
|
88
|
+
#entries = [];
|
|
89
|
+
/**
|
|
90
|
+
* Handle the HTTP header `Link` according to the specification RFC 8288.
|
|
91
|
+
* @param {...(string | Headers | HttpHeaderLink | HttpHeaderLinkEntry[] | Response)} inputs Input.
|
|
92
|
+
*/
|
|
93
|
+
constructor(...inputs) {
|
|
94
|
+
if (inputs.length > 0) this.add(...inputs);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Add entries.
|
|
98
|
+
* @param {...(string | Headers | HttpHeaderLink | HttpHeaderLinkEntry[] | Response)} inputs Input.
|
|
99
|
+
* @returns {this}
|
|
100
|
+
*/
|
|
101
|
+
add(...inputs) {
|
|
102
|
+
for (const input of inputs) if (input instanceof HttpHeaderLink) this.#entries.push(...structuredClone(input.#entries));
|
|
103
|
+
else if (Array.isArray(input)) this.#entries.push(...input.map(([uri, parameters]) => {
|
|
104
|
+
validateURI(uri);
|
|
105
|
+
Object.entries(parameters).forEach(([key, value]) => {
|
|
106
|
+
if (key !== key.toLowerCase() || !/^[\w-]+\*?$/.test(key)) throw new SyntaxError(`\`${key}\` is not a valid parameter key!`);
|
|
107
|
+
if (parametersNeedLowerCase.includes(key) && value !== value.toLowerCase()) throw new SyntaxError(`\`${value}\` is not a valid parameter value!`);
|
|
108
|
+
});
|
|
109
|
+
return [uri, structuredClone(parameters)];
|
|
110
|
+
}));
|
|
111
|
+
else for (const entry of parseLinkFromString((input instanceof Headers || input instanceof Response ? (input instanceof Headers ? input : input.headers).get("Link") : input) ?? "")) this.#entries.push(entry);
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Return all of the entries.
|
|
116
|
+
* @returns {HttpHeaderLinkEntry[]} Entries.
|
|
117
|
+
*/
|
|
118
|
+
entries() {
|
|
119
|
+
return structuredClone(this.#entries);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get entries by parameter.
|
|
123
|
+
* @param {string} key Key of the parameter.
|
|
124
|
+
* @param {string} value Value of the parameter.
|
|
125
|
+
* @returns {HttpHeaderLinkEntry[]} Entries which match the parameter.
|
|
126
|
+
*/
|
|
127
|
+
getByParameter(key, value) {
|
|
128
|
+
if (key !== key.toLowerCase()) throw new SyntaxError(`\`${key}\` is not a valid parameter key!`);
|
|
129
|
+
if (key === "rel") return this.getByRel(value);
|
|
130
|
+
return structuredClone(this.#entries.filter((entry) => {
|
|
131
|
+
return entry[1][key] === value;
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Get entries by parameter `rel`.
|
|
136
|
+
* @param {string} value Value of the parameter `rel`.
|
|
137
|
+
* @returns {HttpHeaderLinkEntry[]} Entries which match the parameter.
|
|
138
|
+
*/
|
|
139
|
+
getByRel(value) {
|
|
140
|
+
if (value !== value.toLowerCase()) throw new SyntaxError(`\`${value}\` is not a valid parameter \`rel\` value!`);
|
|
141
|
+
return structuredClone(this.#entries.filter((entity) => {
|
|
142
|
+
return entity[1].rel?.toLowerCase() === value;
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Whether have entries that match parameter.
|
|
147
|
+
* @param {string} key Key of the parameter.
|
|
148
|
+
* @param {string} value Value of the parameter.
|
|
149
|
+
* @returns {boolean} Determine result.
|
|
150
|
+
*/
|
|
151
|
+
hasParameter(key, value) {
|
|
152
|
+
return this.getByParameter(key, value).length > 0;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Stringify entries.
|
|
156
|
+
* @returns {string} Stringified entries.
|
|
157
|
+
*/
|
|
158
|
+
toString() {
|
|
159
|
+
return this.#entries.map(([uri, parameters]) => {
|
|
160
|
+
return [`<${encodeURI(uri)}>`, ...Object.entries(parameters).map(([key, value]) => {
|
|
161
|
+
return value.length > 0 ? `${key}="${value.replaceAll("\"", "\\\"")}"` : key;
|
|
162
|
+
})].join("; ");
|
|
163
|
+
}).join(", ");
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Parse the HTTP header `Link` according to the specification RFC 8288.
|
|
167
|
+
* @param {...(string | Headers | HttpHeaderLink | HttpHeaderLinkEntry[] | Response)} inputs Input.
|
|
168
|
+
* @returns {HttpHeaderLink}
|
|
169
|
+
*/
|
|
170
|
+
static parse(...inputs) {
|
|
171
|
+
return new this(...inputs);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Stringify as the HTTP header `Link` according to the specification RFC 8288.
|
|
175
|
+
* @param {...(string | Headers | HttpHeaderLink | HttpHeaderLinkEntry[] | Response)} inputs Input.
|
|
176
|
+
* @returns {string}
|
|
177
|
+
*/
|
|
178
|
+
static stringify(...inputs) {
|
|
179
|
+
return new this(...inputs).toString();
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
//#endregion
|
|
184
|
+
Object.defineProperty(exports, 'HttpHeaderLink', {
|
|
185
|
+
enumerable: true,
|
|
186
|
+
get: function () {
|
|
187
|
+
return HttpHeaderLink;
|
|
188
|
+
}
|
|
189
|
+
});
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
//#region src/link.ts
|
|
2
|
+
const parametersNeedLowerCase = ["rel", "type"];
|
|
3
|
+
const regexpLinkWhitespace = /[\n\r\s\t]/;
|
|
4
|
+
function validateURI(uri) {
|
|
5
|
+
if (uri.includes("\n") || regexpLinkWhitespace.test(uri)) throw new SyntaxError(`\`${uri}\` is not a valid URI!`);
|
|
6
|
+
}
|
|
7
|
+
function* parseLinkFromString(input) {
|
|
8
|
+
const inputFmt = input.replaceAll("\xA0", "").replaceAll("", "");
|
|
9
|
+
for (let cursor = 0; cursor < inputFmt.length; cursor += 1) {
|
|
10
|
+
while (regexpLinkWhitespace.test(inputFmt.charAt(cursor))) cursor += 1;
|
|
11
|
+
if (inputFmt.charAt(cursor) !== "<") throw new SyntaxError(`Unexpected character \`${inputFmt.charAt(cursor)}\` at position ${cursor}; Expect character \`<\`!`);
|
|
12
|
+
cursor += 1;
|
|
13
|
+
const cursorEndUri = inputFmt.indexOf(">", cursor);
|
|
14
|
+
if (cursorEndUri === -1) throw new SyntaxError(`Missing end of URI delimiter character \`>\` after position ${cursor}!`);
|
|
15
|
+
if (cursorEndUri === cursor) throw new SyntaxError(`Missing URI at position ${cursor}!`);
|
|
16
|
+
const uriSlice = inputFmt.slice(cursor, cursorEndUri);
|
|
17
|
+
validateURI(uriSlice);
|
|
18
|
+
const uri = decodeURI(uriSlice);
|
|
19
|
+
const parameters = {};
|
|
20
|
+
cursor = cursorEndUri + 1;
|
|
21
|
+
while (regexpLinkWhitespace.test(inputFmt.charAt(cursor))) cursor += 1;
|
|
22
|
+
if (cursor === inputFmt.length || inputFmt.charAt(cursor) === ",") {
|
|
23
|
+
yield [uri, parameters];
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (inputFmt.charAt(cursor) !== ";") throw new SyntaxError(`Unexpected character \`${inputFmt.charAt(cursor)}\` at position ${cursor}; Expect character \`;\`!`);
|
|
27
|
+
cursor += 1;
|
|
28
|
+
while (cursor < inputFmt.length) {
|
|
29
|
+
while (regexpLinkWhitespace.test(inputFmt.charAt(cursor))) cursor += 1;
|
|
30
|
+
const parameterKey = inputFmt.slice(cursor).match(/^[\w-]+\*?/)?.[0].toLowerCase();
|
|
31
|
+
if (typeof parameterKey === "undefined") throw new SyntaxError(`Unexpected character \`${inputFmt.charAt(cursor)}\` at position ${cursor}; Expect a valid parameter key!`);
|
|
32
|
+
cursor += parameterKey.length;
|
|
33
|
+
while (regexpLinkWhitespace.test(inputFmt.charAt(cursor))) cursor += 1;
|
|
34
|
+
if (cursor === inputFmt.length || inputFmt.charAt(cursor) === ",") {
|
|
35
|
+
parameters[parameterKey] = "";
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
if (inputFmt.charAt(cursor) === ";") {
|
|
39
|
+
parameters[parameterKey] = "";
|
|
40
|
+
cursor += 1;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (inputFmt.charAt(cursor) !== "=") throw new SyntaxError(`Unexpected character \`${inputFmt.charAt(cursor)}\` at position ${cursor}; Expect character \`=\`!`);
|
|
44
|
+
cursor += 1;
|
|
45
|
+
while (regexpLinkWhitespace.test(inputFmt.charAt(cursor))) cursor += 1;
|
|
46
|
+
let parameterValue = "";
|
|
47
|
+
if (inputFmt.charAt(cursor) === "\"") {
|
|
48
|
+
cursor += 1;
|
|
49
|
+
while (cursor < inputFmt.length) {
|
|
50
|
+
if (inputFmt.charAt(cursor) === "\"") {
|
|
51
|
+
cursor += 1;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
if (inputFmt.charAt(cursor) === "\\") cursor += 1;
|
|
55
|
+
parameterValue += inputFmt.charAt(cursor);
|
|
56
|
+
cursor += 1;
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
const cursorDiffParameterValue = inputFmt.slice(cursor).search(/[\s;,]/);
|
|
60
|
+
if (cursorDiffParameterValue === -1) {
|
|
61
|
+
parameterValue += inputFmt.slice(cursor);
|
|
62
|
+
cursor += parameterValue.length;
|
|
63
|
+
} else {
|
|
64
|
+
parameterValue += inputFmt.slice(cursor, cursorDiffParameterValue);
|
|
65
|
+
cursor += cursorDiffParameterValue;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
parameters[parameterKey] = parametersNeedLowerCase.includes(parameterKey) ? parameterValue.toLowerCase() : parameterValue;
|
|
69
|
+
while (regexpLinkWhitespace.test(inputFmt.charAt(cursor))) cursor += 1;
|
|
70
|
+
if (cursor === inputFmt.length || inputFmt.charAt(cursor) === ",") break;
|
|
71
|
+
if (inputFmt.charAt(cursor) === ";") {
|
|
72
|
+
cursor += 1;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
throw new SyntaxError(`Unexpected character \`${inputFmt.charAt(cursor)}\` at position ${cursor}; Expect character \`,\`, character \`;\`, or end of the string!`);
|
|
76
|
+
}
|
|
77
|
+
yield [uri, parameters];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Handle the HTTP header `Link` according to the specification RFC 8288.
|
|
82
|
+
*/
|
|
83
|
+
var HttpHeaderLink = class HttpHeaderLink {
|
|
84
|
+
get [Symbol.toStringTag]() {
|
|
85
|
+
return "HTTPHeaderLink";
|
|
86
|
+
}
|
|
87
|
+
#entries = [];
|
|
88
|
+
/**
|
|
89
|
+
* Handle the HTTP header `Link` according to the specification RFC 8288.
|
|
90
|
+
* @param {...(string | Headers | HttpHeaderLink | HttpHeaderLinkEntry[] | Response)} inputs Input.
|
|
91
|
+
*/
|
|
92
|
+
constructor(...inputs) {
|
|
93
|
+
if (inputs.length > 0) this.add(...inputs);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Add entries.
|
|
97
|
+
* @param {...(string | Headers | HttpHeaderLink | HttpHeaderLinkEntry[] | Response)} inputs Input.
|
|
98
|
+
* @returns {this}
|
|
99
|
+
*/
|
|
100
|
+
add(...inputs) {
|
|
101
|
+
for (const input of inputs) if (input instanceof HttpHeaderLink) this.#entries.push(...structuredClone(input.#entries));
|
|
102
|
+
else if (Array.isArray(input)) this.#entries.push(...input.map(([uri, parameters]) => {
|
|
103
|
+
validateURI(uri);
|
|
104
|
+
Object.entries(parameters).forEach(([key, value]) => {
|
|
105
|
+
if (key !== key.toLowerCase() || !/^[\w-]+\*?$/.test(key)) throw new SyntaxError(`\`${key}\` is not a valid parameter key!`);
|
|
106
|
+
if (parametersNeedLowerCase.includes(key) && value !== value.toLowerCase()) throw new SyntaxError(`\`${value}\` is not a valid parameter value!`);
|
|
107
|
+
});
|
|
108
|
+
return [uri, structuredClone(parameters)];
|
|
109
|
+
}));
|
|
110
|
+
else for (const entry of parseLinkFromString((input instanceof Headers || input instanceof Response ? (input instanceof Headers ? input : input.headers).get("Link") : input) ?? "")) this.#entries.push(entry);
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Return all of the entries.
|
|
115
|
+
* @returns {HttpHeaderLinkEntry[]} Entries.
|
|
116
|
+
*/
|
|
117
|
+
entries() {
|
|
118
|
+
return structuredClone(this.#entries);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get entries by parameter.
|
|
122
|
+
* @param {string} key Key of the parameter.
|
|
123
|
+
* @param {string} value Value of the parameter.
|
|
124
|
+
* @returns {HttpHeaderLinkEntry[]} Entries which match the parameter.
|
|
125
|
+
*/
|
|
126
|
+
getByParameter(key, value) {
|
|
127
|
+
if (key !== key.toLowerCase()) throw new SyntaxError(`\`${key}\` is not a valid parameter key!`);
|
|
128
|
+
if (key === "rel") return this.getByRel(value);
|
|
129
|
+
return structuredClone(this.#entries.filter((entry) => {
|
|
130
|
+
return entry[1][key] === value;
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Get entries by parameter `rel`.
|
|
135
|
+
* @param {string} value Value of the parameter `rel`.
|
|
136
|
+
* @returns {HttpHeaderLinkEntry[]} Entries which match the parameter.
|
|
137
|
+
*/
|
|
138
|
+
getByRel(value) {
|
|
139
|
+
if (value !== value.toLowerCase()) throw new SyntaxError(`\`${value}\` is not a valid parameter \`rel\` value!`);
|
|
140
|
+
return structuredClone(this.#entries.filter((entity) => {
|
|
141
|
+
return entity[1].rel?.toLowerCase() === value;
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Whether have entries that match parameter.
|
|
146
|
+
* @param {string} key Key of the parameter.
|
|
147
|
+
* @param {string} value Value of the parameter.
|
|
148
|
+
* @returns {boolean} Determine result.
|
|
149
|
+
*/
|
|
150
|
+
hasParameter(key, value) {
|
|
151
|
+
return this.getByParameter(key, value).length > 0;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Stringify entries.
|
|
155
|
+
* @returns {string} Stringified entries.
|
|
156
|
+
*/
|
|
157
|
+
toString() {
|
|
158
|
+
return this.#entries.map(([uri, parameters]) => {
|
|
159
|
+
return [`<${encodeURI(uri)}>`, ...Object.entries(parameters).map(([key, value]) => {
|
|
160
|
+
return value.length > 0 ? `${key}="${value.replaceAll("\"", "\\\"")}"` : key;
|
|
161
|
+
})].join("; ");
|
|
162
|
+
}).join(", ");
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Parse the HTTP header `Link` according to the specification RFC 8288.
|
|
166
|
+
* @param {...(string | Headers | HttpHeaderLink | HttpHeaderLinkEntry[] | Response)} inputs Input.
|
|
167
|
+
* @returns {HttpHeaderLink}
|
|
168
|
+
*/
|
|
169
|
+
static parse(...inputs) {
|
|
170
|
+
return new this(...inputs);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Stringify as the HTTP header `Link` according to the specification RFC 8288.
|
|
174
|
+
* @param {...(string | Headers | HttpHeaderLink | HttpHeaderLinkEntry[] | Response)} inputs Input.
|
|
175
|
+
* @returns {string}
|
|
176
|
+
*/
|
|
177
|
+
static stringify(...inputs) {
|
|
178
|
+
return new this(...inputs).toString();
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
//#endregion
|
|
183
|
+
export { HttpHeaderLink };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-DWy1uDak.cjs');
|
|
2
|
+
const require_link = require('./link-CdFPEo9O.cjs');
|
|
3
|
+
const node_assert = require_chunk.__toESM(require("node:assert"));
|
|
4
|
+
const node_test = require_chunk.__toESM(require("node:test"));
|
|
5
|
+
|
|
6
|
+
//#region src/link.test.ts
|
|
7
|
+
(0, node_test.test)("String Good 1", () => {
|
|
8
|
+
const instance = new require_link.HttpHeaderLink(`<https://example.com>; rel="preconnect"`);
|
|
9
|
+
(0, node_assert.deepStrictEqual)(instance.hasParameter("rel", "preconnect"), true);
|
|
10
|
+
(0, node_assert.deepStrictEqual)(instance.hasParameter("rel", "connect"), false);
|
|
11
|
+
(0, node_assert.deepStrictEqual)(instance.hasParameter("rel", "postconnect"), false);
|
|
12
|
+
(0, node_assert.deepStrictEqual)(instance.getByRel("preconnect")[0][0], "https://example.com");
|
|
13
|
+
});
|
|
14
|
+
(0, node_test.test)("String Good 2", () => {
|
|
15
|
+
const instance = new require_link.HttpHeaderLink(`<https://example.com>; rel=preconnect`);
|
|
16
|
+
(0, node_assert.deepStrictEqual)(instance.hasParameter("rel", "preconnect"), true);
|
|
17
|
+
(0, node_assert.deepStrictEqual)(instance.hasParameter("rel", "connect"), false);
|
|
18
|
+
(0, node_assert.deepStrictEqual)(instance.hasParameter("rel", "postconnect"), false);
|
|
19
|
+
(0, node_assert.deepStrictEqual)(instance.getByRel("preconnect")[0][0], "https://example.com");
|
|
20
|
+
});
|
|
21
|
+
(0, node_test.test)("String Good 3", () => {
|
|
22
|
+
const instance = new require_link.HttpHeaderLink(`<https://example.com/%E8%8B%97%E6%9D%A1>; rel="preconnect"`);
|
|
23
|
+
(0, node_assert.deepStrictEqual)(instance.hasParameter("rel", "preconnect"), true);
|
|
24
|
+
(0, node_assert.deepStrictEqual)(instance.hasParameter("rel", "connect"), false);
|
|
25
|
+
(0, node_assert.deepStrictEqual)(instance.hasParameter("rel", "postconnect"), false);
|
|
26
|
+
(0, node_assert.deepStrictEqual)(instance.getByRel("preconnect")[0][0], "https://example.com/苗条");
|
|
27
|
+
});
|
|
28
|
+
(0, node_test.test)("String Good 4", () => {
|
|
29
|
+
const instance = new require_link.HttpHeaderLink(`<https://one.example.com>; rel="preconnect", <https://two.example.com>; rel="preconnect", <https://three.example.com>; rel="preconnect"`);
|
|
30
|
+
(0, node_assert.deepStrictEqual)(instance.hasParameter("rel", "preconnect"), true);
|
|
31
|
+
(0, node_assert.deepStrictEqual)(instance.hasParameter("rel", "connect"), false);
|
|
32
|
+
(0, node_assert.deepStrictEqual)(instance.hasParameter("rel", "postconnect"), false);
|
|
33
|
+
(0, node_assert.deepStrictEqual)(instance.getByRel("preconnect")[0][0], "https://one.example.com");
|
|
34
|
+
(0, node_assert.deepStrictEqual)(instance.getByRel("preconnect")[1][0], "https://two.example.com");
|
|
35
|
+
(0, node_assert.deepStrictEqual)(instance.getByRel("preconnect")[2][0], "https://three.example.com");
|
|
36
|
+
});
|
|
37
|
+
(0, node_test.test)("String Good 5", () => {
|
|
38
|
+
const instance = new require_link.HttpHeaderLink();
|
|
39
|
+
(0, node_assert.deepStrictEqual)(instance.hasParameter("rel", "preconnect"), false);
|
|
40
|
+
(0, node_assert.deepStrictEqual)(instance.hasParameter("rel", "connect"), false);
|
|
41
|
+
(0, node_assert.deepStrictEqual)(instance.hasParameter("rel", "postconnect"), false);
|
|
42
|
+
(0, node_assert.deepStrictEqual)(instance.entries().length, 0);
|
|
43
|
+
});
|
|
44
|
+
(0, node_test.test)("Entries Good 1", () => {
|
|
45
|
+
const instance = new require_link.HttpHeaderLink([["https://one.example.com", { rel: "preconnect" }]]);
|
|
46
|
+
(0, node_assert.deepStrictEqual)(instance.hasParameter("rel", "preconnect"), true);
|
|
47
|
+
(0, node_assert.deepStrictEqual)(instance.entries().length, 1);
|
|
48
|
+
(0, node_assert.deepStrictEqual)(instance.toString(), `<https://one.example.com>; rel="preconnect"`);
|
|
49
|
+
});
|
|
50
|
+
(0, node_test.test)("String Bad 1", () => {
|
|
51
|
+
(0, node_assert.throws)(() => {
|
|
52
|
+
new require_link.HttpHeaderLink(`https://bad.example; rel="preconnect"`);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { HttpHeaderLink } from "./link-Ck2yj4dH.js";
|
|
2
|
+
import { deepStrictEqual, throws } from "node:assert";
|
|
3
|
+
import { test } from "node:test";
|
|
4
|
+
|
|
5
|
+
//#region src/link.test.ts
|
|
6
|
+
test("String Good 1", () => {
|
|
7
|
+
const instance = new HttpHeaderLink(`<https://example.com>; rel="preconnect"`);
|
|
8
|
+
deepStrictEqual(instance.hasParameter("rel", "preconnect"), true);
|
|
9
|
+
deepStrictEqual(instance.hasParameter("rel", "connect"), false);
|
|
10
|
+
deepStrictEqual(instance.hasParameter("rel", "postconnect"), false);
|
|
11
|
+
deepStrictEqual(instance.getByRel("preconnect")[0][0], "https://example.com");
|
|
12
|
+
});
|
|
13
|
+
test("String Good 2", () => {
|
|
14
|
+
const instance = new HttpHeaderLink(`<https://example.com>; rel=preconnect`);
|
|
15
|
+
deepStrictEqual(instance.hasParameter("rel", "preconnect"), true);
|
|
16
|
+
deepStrictEqual(instance.hasParameter("rel", "connect"), false);
|
|
17
|
+
deepStrictEqual(instance.hasParameter("rel", "postconnect"), false);
|
|
18
|
+
deepStrictEqual(instance.getByRel("preconnect")[0][0], "https://example.com");
|
|
19
|
+
});
|
|
20
|
+
test("String Good 3", () => {
|
|
21
|
+
const instance = new HttpHeaderLink(`<https://example.com/%E8%8B%97%E6%9D%A1>; rel="preconnect"`);
|
|
22
|
+
deepStrictEqual(instance.hasParameter("rel", "preconnect"), true);
|
|
23
|
+
deepStrictEqual(instance.hasParameter("rel", "connect"), false);
|
|
24
|
+
deepStrictEqual(instance.hasParameter("rel", "postconnect"), false);
|
|
25
|
+
deepStrictEqual(instance.getByRel("preconnect")[0][0], "https://example.com/苗条");
|
|
26
|
+
});
|
|
27
|
+
test("String Good 4", () => {
|
|
28
|
+
const instance = new HttpHeaderLink(`<https://one.example.com>; rel="preconnect", <https://two.example.com>; rel="preconnect", <https://three.example.com>; rel="preconnect"`);
|
|
29
|
+
deepStrictEqual(instance.hasParameter("rel", "preconnect"), true);
|
|
30
|
+
deepStrictEqual(instance.hasParameter("rel", "connect"), false);
|
|
31
|
+
deepStrictEqual(instance.hasParameter("rel", "postconnect"), false);
|
|
32
|
+
deepStrictEqual(instance.getByRel("preconnect")[0][0], "https://one.example.com");
|
|
33
|
+
deepStrictEqual(instance.getByRel("preconnect")[1][0], "https://two.example.com");
|
|
34
|
+
deepStrictEqual(instance.getByRel("preconnect")[2][0], "https://three.example.com");
|
|
35
|
+
});
|
|
36
|
+
test("String Good 5", () => {
|
|
37
|
+
const instance = new HttpHeaderLink();
|
|
38
|
+
deepStrictEqual(instance.hasParameter("rel", "preconnect"), false);
|
|
39
|
+
deepStrictEqual(instance.hasParameter("rel", "connect"), false);
|
|
40
|
+
deepStrictEqual(instance.hasParameter("rel", "postconnect"), false);
|
|
41
|
+
deepStrictEqual(instance.entries().length, 0);
|
|
42
|
+
});
|
|
43
|
+
test("Entries Good 1", () => {
|
|
44
|
+
const instance = new HttpHeaderLink([["https://one.example.com", { rel: "preconnect" }]]);
|
|
45
|
+
deepStrictEqual(instance.hasParameter("rel", "preconnect"), true);
|
|
46
|
+
deepStrictEqual(instance.entries().length, 1);
|
|
47
|
+
deepStrictEqual(instance.toString(), `<https://one.example.com>; rel="preconnect"`);
|
|
48
|
+
});
|
|
49
|
+
test("String Bad 1", () => {
|
|
50
|
+
throws(() => {
|
|
51
|
+
new HttpHeaderLink(`https://bad.example; rel="preconnect"`);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
//#endregion
|