1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

refactor(ext) Decrease of StringPrototypeReplace recurrent usage (#15058)

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
sevenwithawp 2022-07-09 21:28:02 +03:00 committed by GitHub
parent 132c761e87
commit 213d831ae3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 32 deletions

View file

@ -720,27 +720,20 @@
// Replace escape sequences that can modify output.
function replaceEscapeSequences(string) {
const escapeMap = {
"\b": "\\b",
"\f": "\\f",
"\n": "\\n",
"\r": "\\r",
"\t": "\\t",
"\v": "\\v",
};
return StringPrototypeReplace(
StringPrototypeReplace(
StringPrototypeReplace(
StringPrototypeReplace(
StringPrototypeReplace(
StringPrototypeReplace(
StringPrototypeReplace(string, /[\b]/g, "\\b"),
/\f/g,
"\\f",
),
/\n/g,
"\\n",
),
/\r/g,
"\\r",
),
/\t/g,
"\\t",
),
/\v/g,
"\\v",
string,
/([\b\f\n\r\t\v])/g,
(c) => escapeMap[c],
),
// deno-lint-ignore no-control-regex
/[\x00-\x1f\x7f-\x9f]/g,

View file

@ -271,20 +271,19 @@
webidl.configurePrototype(FormData);
const FormDataPrototype = FormData.prototype;
const escape = (str, isFilename) =>
StringPrototypeReplace(
StringPrototypeReplace(
StringPrototypeReplace(
const escape = (str, isFilename) => {
const escapeMap = {
"\n": "%0A",
"\r": "%0D",
'"': "%22",
};
return StringPrototypeReplace(
isFilename ? str : StringPrototypeReplace(str, /\r?\n|\r/g, "\r\n"),
/\n/g,
"%0A",
),
/\r/g,
"%0D",
),
/"/g,
"%22",
/([\n\r"])/g,
(c) => escapeMap[c],
);
};
/**
* convert FormData to a Blob synchronous without reading all of the files