single-file-core 1.2.25 → 1.2.27
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.
|
@@ -28,6 +28,7 @@ import { parse } from "./template-parser.js";
|
|
|
28
28
|
// eslint-disable-next-line quotes
|
|
29
29
|
const DEFAULT_REPLACED_CHARACTERS = ["~", "+", "\\\\", "?", "%", "*", ":", "|", '"', "<", ">", "\x00-\x1f", "\x7F"];
|
|
30
30
|
const DEFAULT_REPLACEMENT_CHARACTER = "_";
|
|
31
|
+
const REGEXP_ESCAPE = /([{}()^$&.*?/+|[\\\\]|\]|-)/g;
|
|
31
32
|
|
|
32
33
|
const EMOJI_NAMES = {
|
|
33
34
|
"😀": "grinning-face",
|
|
@@ -16866,8 +16867,9 @@ export { formatFilename, evalTemplate };
|
|
|
16866
16867
|
|
|
16867
16868
|
async function formatFilename(content, doc, options, util) {
|
|
16868
16869
|
let filename = (await evalTemplate(options.filenameTemplate, options, util, content, doc)) || "";
|
|
16870
|
+
filename = filename.trim();
|
|
16869
16871
|
if (options.replaceEmojisInFilename) {
|
|
16870
|
-
EMOJIS.forEach(emoji => (filename =
|
|
16872
|
+
EMOJIS.forEach(emoji => (filename = replaceAll(filename, emoji, " _" + EMOJI_NAMES[emoji] + "_ ")));
|
|
16871
16873
|
}
|
|
16872
16874
|
const replacementCharacter = options.filenameReplacementCharacter;
|
|
16873
16875
|
filename = getValidFilename(filename, options.filenameReplacedCharacters, replacementCharacter);
|
|
@@ -16970,7 +16972,7 @@ async function evalTemplate(template = "", options, util, content, doc, dontRepl
|
|
|
16970
16972
|
"lowercase": value => value.toLowerCase(),
|
|
16971
16973
|
"uppercase": value => value.toUpperCase(),
|
|
16972
16974
|
"capitalize": value => value.charAt(0).toUpperCase() + value.slice(1),
|
|
16973
|
-
"replace": (value, searchValue, replaceValue) => searchValue && replaceValue ?
|
|
16975
|
+
"replace": (value, searchValue, replaceValue) => searchValue && replaceValue ? replaceAll(value, searchValue, replaceValue) : value,
|
|
16974
16976
|
"trim": value => value.trim(),
|
|
16975
16977
|
"trim-left": value => value.trimLeft(),
|
|
16976
16978
|
"trim-right": value => value.trimRight(),
|
|
@@ -17012,10 +17014,10 @@ async function evalTemplate(template = "", options, util, content, doc, dontRepl
|
|
|
17012
17014
|
return element && element.getAttribute(attribute);
|
|
17013
17015
|
};
|
|
17014
17016
|
}
|
|
17015
|
-
template =
|
|
17016
|
-
template =
|
|
17017
|
-
template =
|
|
17018
|
-
template =
|
|
17017
|
+
template = replaceAll(template, "\\%", "\\\\%");
|
|
17018
|
+
template = replaceAll(template, "\\{", "\\\\{");
|
|
17019
|
+
template = replaceAll(template, "\\|", "\\\\|");
|
|
17020
|
+
template = replaceAll(template, "\\>", "\\\\>");
|
|
17019
17021
|
const result = (await parse(template, {
|
|
17020
17022
|
async callFunction(name, [argument, optionalArguments], lengthData) {
|
|
17021
17023
|
const fn = functions[name];
|
|
@@ -17047,10 +17049,10 @@ async function evalTemplate(template = "", options, util, content, doc, dontRepl
|
|
|
17047
17049
|
}
|
|
17048
17050
|
}));
|
|
17049
17051
|
let resultString = result.join("");
|
|
17050
|
-
resultString =
|
|
17051
|
-
resultString =
|
|
17052
|
-
resultString =
|
|
17053
|
-
resultString =
|
|
17052
|
+
resultString = replaceAll(resultString, "\\\\%", "%");
|
|
17053
|
+
resultString = replaceAll(resultString, "\\\\{", "{");
|
|
17054
|
+
resultString = replaceAll(resultString, "\\\\|", "|");
|
|
17055
|
+
resultString = replaceAll(resultString, "\\\\>", ">");
|
|
17054
17056
|
return resultString;
|
|
17055
17057
|
|
|
17056
17058
|
function addDateVariables(date, prefix = "") {
|
|
@@ -17077,6 +17079,15 @@ async function evalTemplate(template = "", options, util, content, doc, dontRepl
|
|
|
17077
17079
|
}
|
|
17078
17080
|
}
|
|
17079
17081
|
|
|
17082
|
+
function replaceAll(string, search, replacement) {
|
|
17083
|
+
if (typeof string.replaceAll == "function") {
|
|
17084
|
+
return string.replaceAll(search, replacement);
|
|
17085
|
+
} else {
|
|
17086
|
+
const searchRegExp = new RegExp(search.replace(REGEXP_ESCAPE, "\\$1"), "g");
|
|
17087
|
+
return string.replace(searchRegExp, replacement);
|
|
17088
|
+
}
|
|
17089
|
+
}
|
|
17090
|
+
|
|
17080
17091
|
async function getValue(valueGetter, dontReplaceSlash, replacementCharacter, lengthData) {
|
|
17081
17092
|
const { maxLength, maxCharLength } = extractMaxLength(lengthData);
|
|
17082
17093
|
let value = (await valueGetter()) || "";
|
package/package.json
CHANGED
|
@@ -70,6 +70,8 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
|
|
|
70
70
|
const REGEXP_MATCH_INDEX = /index\.html$/;
|
|
71
71
|
const REGEXP_MATCH_FRAMES = /frames\//;
|
|
72
72
|
const CHARSET_UTF8 = ";charset=utf-8";
|
|
73
|
+
const REGEXP_ESCAPE = /([{}()^$&.*?/+|[\\\\]|\]|-)/g;
|
|
74
|
+
|
|
73
75
|
if (Array.isArray(content)) {
|
|
74
76
|
content = new Blob([new Uint8Array(content)]);
|
|
75
77
|
}
|
|
@@ -142,7 +144,7 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
|
|
|
142
144
|
const position = textContent.indexOf(relativeFilename);
|
|
143
145
|
if (position != -1) {
|
|
144
146
|
parentResources.push(resourceFilename);
|
|
145
|
-
textContent =
|
|
147
|
+
textContent = replaceAll(textContent, relativeFilename, content);
|
|
146
148
|
}
|
|
147
149
|
}
|
|
148
150
|
}
|
|
@@ -175,4 +177,13 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
|
|
|
175
177
|
reader.onerror = reject;
|
|
176
178
|
});
|
|
177
179
|
}
|
|
180
|
+
|
|
181
|
+
function replaceAll(string, search, replacement) {
|
|
182
|
+
if (typeof string.replaceAll == "function") {
|
|
183
|
+
return string.replaceAll(search, replacement);
|
|
184
|
+
} else {
|
|
185
|
+
const searchRegExp = new RegExp(search.replace(REGEXP_ESCAPE, "\\$1"), "g");
|
|
186
|
+
return string.replace(searchRegExp, replacement);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
178
189
|
}
|