single-file-core 1.2.16 → 1.2.17

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/core/index.js CHANGED
@@ -109,6 +109,7 @@ const STAGES = [{
109
109
  { action: "replaceStyleContents" },
110
110
  { action: "replaceInvalidElements" },
111
111
  { action: "resetCharsetMeta" },
112
+ { action: "resetReferrerMeta" },
112
113
  { option: "saveFavicon", action: "saveFavicon" },
113
114
  { action: "insertFonts" },
114
115
  { action: "insertShadowRootContents" },
@@ -866,6 +867,14 @@ class Processor {
866
867
  }
867
868
  }
868
869
 
870
+ resetReferrerMeta() {
871
+ this.doc.querySelectorAll("meta[name=referrer]").forEach(element => element.remove());
872
+ const metaElement = this.doc.createElement("meta");
873
+ metaElement.setAttribute("name", "referrer");
874
+ metaElement.setAttribute("content", "no-referrer");
875
+ this.doc.head.appendChild(metaElement);
876
+ }
877
+
869
878
  setInputValues() {
870
879
  this.doc.querySelectorAll("input:not([type=radio]):not([type=checkbox])").forEach(input => {
871
880
  const value = input.getAttribute(util.INPUT_VALUE_ATTRIBUTE_NAME);
@@ -16883,7 +16883,7 @@ async function formatFilename(content, doc, options, util) {
16883
16883
  if (!filename) {
16884
16884
  filename = "Unnamed page";
16885
16885
  }
16886
- return filename;
16886
+ return filename.trim();
16887
16887
  }
16888
16888
 
16889
16889
  async function evalTemplate(template = "", options, util, content, doc, dontReplaceSlash) {
@@ -16954,27 +16954,49 @@ async function evalTemplate(template = "", options, util, content, doc, dontRepl
16954
16954
  const foundValue = values.find(value => value);
16955
16955
  return foundValue ? foundValue : defaultValue;
16956
16956
  },
16957
- "if-not-empty": (values) => {
16957
+ "if-not-empty": (...values) => {
16958
16958
  const defaultValue = values.pop();
16959
16959
  const foundValue = values.find(value => value);
16960
16960
  return foundValue ? defaultValue : foundValue;
16961
16961
  },
16962
+ "if-equals": (value, otherValue, trueValue, falseValue) => value == otherValue ? trueValue : falseValue,
16963
+ "if-not-equals": (value, otherValue, trueValue, falseValue) => value != otherValue ? trueValue : falseValue,
16964
+ "if-contains": (value, otherValue, trueValue, falseValue) => otherValue && value.includes(otherValue) ? trueValue : falseValue,
16965
+ "if-not-contains": (value, otherValue, trueValue, falseValue) => otherValue && !value.includes(otherValue) ? trueValue : falseValue,
16962
16966
  "substring": (value, start, end) => value.substring(start, end),
16963
16967
  "lowercase": value => value.toLowerCase(),
16964
16968
  "uppercase": value => value.toUpperCase(),
16965
- "capitalize": value => value.replace(/(?:^|\s)\S/g, a => a.toUpperCase()),
16966
- "replace": (value, searchValue, replaceValue) => value.replaceAll(searchValue, replaceValue),
16969
+ "replace": (value, searchValue, replaceValue) => searchValue && replaceValue ? value.replaceAll(searchValue, replaceValue) : value,
16967
16970
  "trim": value => value.trim(),
16968
16971
  "trim-left": value => value.trimLeft(),
16969
16972
  "trim-right": value => value.trimRight(),
16970
- "pad-left": (value, length, padString) => value.padStart(length, padString),
16971
- "pad-right": (value, length, padString) => value.padEnd(length, padString),
16973
+ "pad-left": (value, length, padString) => length > 0 ? value.padStart(length, padString) : value,
16974
+ "pad-right": (value, length, padString) => length > 0 ? value.padEnd(length, padString) : value,
16975
+ "repeat": (value, count) => count > 0 ? value.repeat(count) : "",
16976
+ "index-of": (value, searchValue) => value.indexOf(searchValue),
16977
+ "last-index-of": (value, searchValue) => value.lastIndexOf(searchValue),
16978
+ "length": value => value.length,
16972
16979
  "url-search-name": (index = 0) => params[index] && params[index][0],
16973
16980
  "url-search-value": (index = 0) => params[index] && params[index][1],
16974
16981
  "url-search": name => {
16975
16982
  const param = params.find(param => param[0] == name);
16976
- return param && param[1];
16977
- }
16983
+ return (param && param[1]);
16984
+ },
16985
+ "url-segment": (index = 0) => {
16986
+ const segments = decode(url.pathname).split("/");
16987
+ segments.pop();
16988
+ segments.push(getLastSegment(url, options.filenameReplacementCharacter));
16989
+ return segments[index];
16990
+ },
16991
+ "url-hostname-subdomain": (index = 0) => {
16992
+ const subdomains = urlSubDomains.split(".");
16993
+ return subdomains[subdomains.length - index - 1];
16994
+ },
16995
+ "stringify": value => JSON.stringify(value),
16996
+ "encode-uri": value => encodeURIComponent(value),
16997
+ "decode-uri": value => decodeURIComponent(value),
16998
+ "encode-uri-component": value => encodeURI(value),
16999
+ "decode-uri-component": value => decodeURI(value)
16978
17000
  };
16979
17001
  if (doc) {
16980
17002
  functions["page-element-text"] = (selector) => {
@@ -16991,12 +17013,20 @@ async function evalTemplate(template = "", options, util, content, doc, dontRepl
16991
17013
  template = template.replaceAll("\\|", "\\\\|");
16992
17014
  template = template.replaceAll("\\>", "\\\\>");
16993
17015
  const result = (await parse(template, {
16994
- callFunction(name, [argument, optionalArguments], lengthData) {
17016
+ async callFunction(name, [argument, optionalArguments], lengthData) {
16995
17017
  const fn = functions[name];
16996
17018
  if (fn) {
16997
17019
  argument = argument.replace(/\\\\(.)/g, "$1");
16998
17020
  optionalArguments = optionalArguments.map(argument => argument.replace(/\\\\(.)/g, "$1"));
16999
- return getValue(() => fn(argument, ...optionalArguments), true, options.filenameReplacementCharacter, lengthData);
17021
+ if (argument != undefined && argument != null && argument != "") {
17022
+ try {
17023
+ return await getValue(() => fn(argument, ...optionalArguments), true, options.filenameReplacementCharacter, lengthData);
17024
+ } catch (error) {
17025
+ return "";
17026
+ }
17027
+ } else {
17028
+ return "";
17029
+ }
17000
17030
  } else {
17001
17031
  return "";
17002
17032
  }
@@ -17043,7 +17073,7 @@ async function evalTemplate(template = "", options, util, content, doc, dontRepl
17043
17073
 
17044
17074
  async function getValue(valueGetter, dontReplaceSlash, replacementCharacter, lengthData) {
17045
17075
  const { maxLength, maxCharLength } = extractMaxLength(lengthData);
17046
- let value = await valueGetter();
17076
+ let value = (await valueGetter()) || "";
17047
17077
  if (!dontReplaceSlash) {
17048
17078
  value = value.replace(/\/+/g, replacementCharacter);
17049
17079
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.2.16",
3
+ "version": "1.2.17",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",