mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
refactor(ext/fetch): simplify parseContentDisposition (#16162)
Replaced `forEach`, `map`, `filter`, `map` with a single `for` loop
This commit is contained in:
parent
0b016a7fb8
commit
b487027b45
1 changed files with 11 additions and 17 deletions
|
@ -16,12 +16,9 @@
|
|||
const { Blob, BlobPrototype, File, FilePrototype } =
|
||||
globalThis.__bootstrap.file;
|
||||
const {
|
||||
ArrayPrototypeMap,
|
||||
ArrayPrototypePush,
|
||||
ArrayPrototypeSlice,
|
||||
ArrayPrototypeSplice,
|
||||
ArrayPrototypeFilter,
|
||||
ArrayPrototypeForEach,
|
||||
Map,
|
||||
MapPrototypeGet,
|
||||
MapPrototypeSet,
|
||||
|
@ -335,20 +332,17 @@
|
|||
/** @type {Map<string, string>} */
|
||||
const params = new Map();
|
||||
// Forced to do so for some Map constructor param mismatch
|
||||
ArrayPrototypeForEach(
|
||||
ArrayPrototypeMap(
|
||||
ArrayPrototypeFilter(
|
||||
ArrayPrototypeMap(
|
||||
ArrayPrototypeSlice(StringPrototypeSplit(value, ";"), 1),
|
||||
(s) => StringPrototypeSplit(StringPrototypeTrim(s), "="),
|
||||
),
|
||||
(arr) => arr.length > 1,
|
||||
),
|
||||
([k, v]) => [k, StringPrototypeReplace(v, /^"([^"]*)"$/, "$1")],
|
||||
),
|
||||
([k, v]) => MapPrototypeSet(params, k, v),
|
||||
);
|
||||
|
||||
const values = ArrayPrototypeSlice(StringPrototypeSplit(value, ";"), 1);
|
||||
for (let i = 0; i < values.length; i++) {
|
||||
const entries = StringPrototypeSplit(StringPrototypeTrim(values[i]), "=");
|
||||
if (entries.length > 1) {
|
||||
MapPrototypeSet(
|
||||
params,
|
||||
entries[0],
|
||||
StringPrototypeReplace(entries[1], /^"([^"]*)"$/, "$1"),
|
||||
);
|
||||
}
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue