@wcstack/fetch 3.5.4 → 4.0.0-rc.2
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.ja.md +1 -1
- package/README.md +1 -1
- package/dist/auto.min.js +1 -1
- package/dist/auto.min.js.map +1 -1
- package/dist/index.esm.js +25 -37
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -34,49 +34,37 @@ function getConfig() {
|
|
|
34
34
|
}
|
|
35
35
|
return frozenConfig;
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
/** A misspelt option would otherwise do nothing: `bootstrapFetch` refuses it. */
|
|
38
|
+
function invalid(key) {
|
|
39
|
+
throw new Error(`[@wcstack/fetch] bootstrapFetch: "${key}" is not one of its options, or not of the option's type.`);
|
|
40
|
+
}
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* undefined value is left out, as in 4.0. It only warns: setConfig then goes on exactly as in 3.x.
|
|
46
|
-
* Bootstrap-time only, never on a hot path.
|
|
42
|
+
* Applies the options given; an undefined value is left out. An option this package does not
|
|
43
|
+
* have, a value of another type than its default (null, or an array for an object, included) or
|
|
44
|
+
* a tag name it does not define throws, and then nothing is applied.
|
|
47
45
|
*/
|
|
48
|
-
function warnInvalid(given, known, path = "") {
|
|
49
|
-
for (const [key, value] of Object.entries(given)) {
|
|
50
|
-
const name = path + key;
|
|
51
|
-
const current = known[key];
|
|
52
|
-
if (value === undefined) {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
if (!Object.prototype.hasOwnProperty.call(known, key) ||
|
|
56
|
-
value === null ||
|
|
57
|
-
typeof value !== typeof current ||
|
|
58
|
-
Array.isArray(value) !== Array.isArray(current)) {
|
|
59
|
-
if (!warned.has(name)) {
|
|
60
|
-
warned.add(name);
|
|
61
|
-
console.warn(`[@wcstack/fetch] bootstrapFetch: "${name}" is not one of its options, or not of the option's type. 3.x ignores it or applies it unchecked; 4.0 throws on it.`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else if (name === "tagNames") {
|
|
65
|
-
warnInvalid(value, current, "tagNames.");
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
46
|
function setConfig(partialConfig) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
47
|
+
const options = _config;
|
|
48
|
+
const tags = _config.tagNames;
|
|
49
|
+
const given = Object.entries(partialConfig).filter(([, value]) => value !== undefined);
|
|
50
|
+
const givenTags = Object.entries(partialConfig.tagNames ?? {}).filter(([, tag]) => tag !== undefined);
|
|
51
|
+
for (const [key, value] of given) {
|
|
52
|
+
const current = options[key];
|
|
53
|
+
if (!Object.hasOwn(options, key) || value === null || typeof value !== typeof current || Array.isArray(value) !== Array.isArray(current)) {
|
|
54
|
+
invalid(key);
|
|
55
|
+
}
|
|
73
56
|
}
|
|
74
|
-
|
|
75
|
-
|
|
57
|
+
for (const [name, tag] of givenTags) {
|
|
58
|
+
if (!Object.hasOwn(tags, name) || typeof tag !== "string")
|
|
59
|
+
invalid(`tagNames.${name}`);
|
|
76
60
|
}
|
|
77
|
-
|
|
78
|
-
|
|
61
|
+
for (const [key, value] of given) {
|
|
62
|
+
if (key !== "tagNames") {
|
|
63
|
+
options[key] = value;
|
|
64
|
+
}
|
|
79
65
|
}
|
|
66
|
+
for (const [name, tag] of givenTags)
|
|
67
|
+
tags[name] = tag;
|
|
80
68
|
frozenConfig = null;
|
|
81
69
|
}
|
|
82
70
|
|