@design-edito/tools 0.1.37 → 0.1.39
Sign up to get free protection for your applications and to get access to all the features.
- package/agnostic/css/bem/index.js +2 -2
- package/agnostic/css/index.js +11 -11
- package/agnostic/errors/index.js +2 -2
- package/agnostic/html/hyper-json/cast/index.js +2 -2
- package/agnostic/html/hyper-json/index.js +3 -3
- package/agnostic/html/hyper-json/transformers/append/index.js +2 -2
- package/agnostic/html/hyper-json/transformers/classList/index.js +2 -2
- package/agnostic/html/hyper-json/transformers/index.js +2 -2
- package/agnostic/html/hyper-json/transformers/join/index.js +2 -2
- package/agnostic/html/hyper-json/transformers/length/index.js +2 -2
- package/agnostic/html/hyper-json/transformers/print/index.js +2 -2
- package/agnostic/html/hyper-json/transformers/push/index.js +2 -2
- package/agnostic/html/hyper-json/transformers/querySelector/index.js +2 -2
- package/agnostic/html/hyper-json/transformers/ref/index.js +2 -2
- package/agnostic/html/hyper-json/transformers/replace/index.js +2 -2
- package/agnostic/html/hyper-json/transformers/split/index.js +2 -2
- package/agnostic/html/hyper-json/transformers/toArray/index.js +2 -2
- package/agnostic/html/hyper-json/transformers/toBoolean/index.js +2 -2
- package/agnostic/html/hyper-json/transformers/toElement/index.js +2 -2
- package/agnostic/html/hyper-json/transformers/toNodeList/index.js +2 -2
- package/agnostic/html/hyper-json/transformers/toNull/index.js +2 -2
- package/agnostic/html/hyper-json/transformers/toNumber/index.js +2 -2
- package/agnostic/html/hyper-json/transformers/toRecord/index.js +2 -2
- package/agnostic/html/hyper-json/transformers/toRef/index.js +2 -2
- package/agnostic/html/hyper-json/transformers/toString/index.js +2 -2
- package/agnostic/html/hyper-json/transformers/toText/index.js +2 -2
- package/agnostic/html/hyper-json/transformers/toTransformer/index.js +2 -2
- package/agnostic/html/hyper-json/transformers/transformSelected/index.js +2 -2
- package/agnostic/html/hyper-json/transformers/trim/index.js +2 -2
- package/agnostic/html/hyper-json/tree/index.js +2 -2
- package/agnostic/html/hyper-json/utils/index.js +2 -2
- package/agnostic/html/index.js +20 -20
- package/agnostic/html/sanitize/index.js +6 -6
- package/agnostic/html/selector-to-element/index.js +6 -6
- package/agnostic/html/string-to-nodes/index.js +7 -7
- package/agnostic/misc/crossenv/index.js +2 -2
- package/agnostic/misc/elo/index.d.ts +31 -0
- package/agnostic/misc/elo/index.js +32 -0
- package/agnostic/misc/index.js +13 -13
- package/agnostic/misc/logs/index.js +2 -2
- package/agnostic/misc/logs/logger/index.d.ts +3 -0
- package/agnostic/misc/logs/logger/index.js +1 -1
- package/agnostic/misc/lorem-ipsum/index.js +5 -5
- package/agnostic/objects/index.js +3 -3
- package/agnostic/random/index.js +2 -2
- package/agnostic/regexps/index.d.ts +1 -0
- package/agnostic/regexps/index.js +1 -0
- package/agnostic/strings/index.js +7 -7
- package/agnostic/strings/replace-all/index.d.ts +1 -1
- package/agnostic/strings/replace-all/index.js +1 -1
- package/agnostic/time/index.js +3 -3
- package/chunks/chunk-6JRUZYTL.js +211 -0
- package/chunks/chunk-DCKTGQOX.js +29 -0
- package/chunks/chunk-GB4UQS6V.js +35 -0
- package/chunks/chunk-LOFELEU3.js +1108 -0
- package/chunks/chunk-LVXK54LL.js +27 -0
- package/chunks/chunk-MJQF3YZO.js +21 -0
- package/chunks/chunk-PPHUIOHO.js +28 -0
- package/chunks/chunk-QHGZBCFZ.js +1108 -0
- package/chunks/chunk-QN3UAKIU.js +21 -0
- package/chunks/chunk-RASMASS4.js +111 -0
- package/chunks/chunk-RHV7UOXD.js +211 -0
- package/chunks/chunk-S7MJLTCR.js +211 -0
- package/chunks/chunk-U6YRINXJ.js +22 -0
- package/chunks/chunk-YO5KOEJF.js +27 -0
- package/chunks/chunk-Z352MSRL.js +127 -0
- package/chunks/chunk-ZTDVUXPR.js +16 -0
- package/package.json +1 -1
@@ -0,0 +1,127 @@
|
|
1
|
+
import {
|
2
|
+
register
|
3
|
+
} from "./chunk-U6YRINXJ.js";
|
4
|
+
|
5
|
+
// src/agnostic/html/sanitize/index.ts
|
6
|
+
var Sanitize;
|
7
|
+
((Sanitize2) => {
|
8
|
+
Sanitize2.defaultOptions = { depth: 20 };
|
9
|
+
function sanitize(inputStr, options = Sanitize2.defaultOptions) {
|
10
|
+
const actualDocument = options.documentObj ?? window.document;
|
11
|
+
if (actualDocument === null) throw register.getError("no-window-document-on-runtime-please-provide" /* NO_DOCUMENT_PLEASE_PROVIDE */, "See documentObj in the options object");
|
12
|
+
const wrapperDiv = actualDocument.createElement("div");
|
13
|
+
const { inputFreeTransform } = options;
|
14
|
+
wrapperDiv.innerHTML = inputFreeTransform !== void 0 ? inputFreeTransform(inputStr) : inputStr;
|
15
|
+
const sanitizedWrapper = sanitizeElement(wrapperDiv, options);
|
16
|
+
const returned = sanitizedWrapper?.innerHTML;
|
17
|
+
return returned ?? "";
|
18
|
+
}
|
19
|
+
Sanitize2.sanitize = sanitize;
|
20
|
+
function sanitizeElement(element, options = Sanitize2.defaultOptions) {
|
21
|
+
const actualDocument = options.documentObj ?? window.document;
|
22
|
+
if (actualDocument === null) throw register.getError("no-window-document-on-runtime-please-provide" /* NO_DOCUMENT_PLEASE_PROVIDE */, "See documentObj in the options object");
|
23
|
+
const { tagName, attributes, childNodes } = element;
|
24
|
+
const {
|
25
|
+
allowedTags = [],
|
26
|
+
allowedAttributes = {},
|
27
|
+
forbiddenTags = [],
|
28
|
+
forbiddenAttributes = {},
|
29
|
+
depth = 20,
|
30
|
+
verbose = false
|
31
|
+
} = options;
|
32
|
+
if (depth <= 0) {
|
33
|
+
console.warn("Max depth reached");
|
34
|
+
return null;
|
35
|
+
}
|
36
|
+
const normalizedTagName = tagName.toLowerCase().trim();
|
37
|
+
const tagIsInForbidden = forbiddenTags.includes("*") || forbiddenTags.includes(normalizedTagName);
|
38
|
+
if (tagIsInForbidden) {
|
39
|
+
if (verbose === true) console.warn(tagName, "tag is forbidden");
|
40
|
+
return null;
|
41
|
+
}
|
42
|
+
const tagIsInAllowed = allowedTags.includes("*") || allowedTags.includes(normalizedTagName);
|
43
|
+
if (!tagIsInAllowed) {
|
44
|
+
if (verbose === true) console.warn(tagName, "tag is not allowed");
|
45
|
+
return null;
|
46
|
+
}
|
47
|
+
const returnedElement = actualDocument.createElement(tagName);
|
48
|
+
const returnedAttributes = Array.from(attributes).filter(({ name: attributeName, value: attributeValue }) => {
|
49
|
+
const allTagsForbiddenAttributes = forbiddenAttributes["*"] ?? [];
|
50
|
+
const thisTagForbiddenAttributes = forbiddenAttributes[normalizedTagName] ?? [];
|
51
|
+
const mergedForbiddenAttributes = [...allTagsForbiddenAttributes, ...thisTagForbiddenAttributes];
|
52
|
+
const isInForbidden = mergedForbiddenAttributes.some(({
|
53
|
+
attributeName: nameTester,
|
54
|
+
attributeValues: valTesters
|
55
|
+
}) => {
|
56
|
+
if (typeof nameTester === "string" && nameTester !== "*" && attributeName !== nameTester) return false;
|
57
|
+
if (typeof nameTester !== "string" && !nameTester.test(attributeName)) return false;
|
58
|
+
if (valTesters === void 0) {
|
59
|
+
if (verbose === true) console.warn(attributeName, "attribute on", tagName, "tag is forbidden");
|
60
|
+
return true;
|
61
|
+
}
|
62
|
+
if (valTesters.includes("*")) {
|
63
|
+
if (verbose === true) console.warn(attributeName, "attribute on", tagName, "tag is forbidden");
|
64
|
+
return true;
|
65
|
+
}
|
66
|
+
return valTesters.some((valTester) => {
|
67
|
+
if (typeof valTester === "string" && attributeValue === valTester) {
|
68
|
+
if (verbose === true) console.warn(attributeValue, "value for", attributeName, "attribute on", tagName, "tag is forbidden. Rule:", valTester);
|
69
|
+
return true;
|
70
|
+
}
|
71
|
+
if (typeof valTester !== "string" && valTester.test(attributeValue)) {
|
72
|
+
if (verbose === true) console.warn(attributeValue, "value for", attributeName, "attribute on", tagName, "tag is forbidden. Rule:", valTester);
|
73
|
+
return true;
|
74
|
+
}
|
75
|
+
return false;
|
76
|
+
});
|
77
|
+
});
|
78
|
+
if (isInForbidden) return false;
|
79
|
+
const allTagsAllowedAttributes = allowedAttributes["*"] ?? [];
|
80
|
+
const thisTagAllowedAttributes = allowedAttributes[normalizedTagName] ?? [];
|
81
|
+
const mergedAllowedAttributes = [...allTagsAllowedAttributes, ...thisTagAllowedAttributes];
|
82
|
+
let latestNotAllowedReason = [tagName, "has no allowed attributes"];
|
83
|
+
const isInAllowed = mergedAllowedAttributes.some(({
|
84
|
+
attributeName: nameTester,
|
85
|
+
attributeValues: valTesters
|
86
|
+
}) => {
|
87
|
+
if (typeof nameTester === "string" && nameTester !== "*" && attributeName !== nameTester) {
|
88
|
+
latestNotAllowedReason = [attributeName, "attribute on", tagName, "tag is not allowed"];
|
89
|
+
return false;
|
90
|
+
}
|
91
|
+
if (typeof nameTester !== "string" && !nameTester.test(attributeName)) {
|
92
|
+
latestNotAllowedReason = [attributeName, "attribute on", tagName, "tag is not allowed"];
|
93
|
+
return false;
|
94
|
+
}
|
95
|
+
if (valTesters === void 0) return true;
|
96
|
+
if (valTesters.includes("*")) return true;
|
97
|
+
return valTesters.some((valTester) => {
|
98
|
+
if (typeof valTester === "string" && attributeValue === valTester) return true;
|
99
|
+
if (typeof valTester !== "string" && valTester.test(attributeValue)) return true;
|
100
|
+
latestNotAllowedReason = [attributeValue, "value for", attributeName, "attribute on", tagName, "tag is not allowed"];
|
101
|
+
return false;
|
102
|
+
});
|
103
|
+
});
|
104
|
+
if (!isInAllowed) {
|
105
|
+
if (verbose === true) console.warn(...latestNotAllowedReason);
|
106
|
+
return false;
|
107
|
+
}
|
108
|
+
return true;
|
109
|
+
});
|
110
|
+
returnedAttributes.forEach(({ name, value }) => {
|
111
|
+
returnedElement.setAttribute(name, value);
|
112
|
+
});
|
113
|
+
const sanitizedChildNodes = Array.from(childNodes).map((node) => {
|
114
|
+
if (node.nodeType === Node.ELEMENT_NODE) return sanitizeElement(node, { ...options, depth: depth - 1 });
|
115
|
+
else if (node.nodeType === Node.TEXT_NODE) return node;
|
116
|
+
else if (options.keepComments === true && node.nodeType === Node.COMMENT_NODE) return node;
|
117
|
+
return null;
|
118
|
+
}).filter((elt) => elt !== null);
|
119
|
+
returnedElement.replaceChildren(...sanitizedChildNodes);
|
120
|
+
return returnedElement;
|
121
|
+
}
|
122
|
+
Sanitize2.sanitizeElement = sanitizeElement;
|
123
|
+
})(Sanitize || (Sanitize = {}));
|
124
|
+
|
125
|
+
export {
|
126
|
+
Sanitize
|
127
|
+
};
|
@@ -0,0 +1,16 @@
|
|
1
|
+
// src/agnostic/strings/replace-all/index.ts
|
2
|
+
function replaceAll(input, pattern, replacer) {
|
3
|
+
const found = Array.from(input.match(pattern) ?? []);
|
4
|
+
const foundReplaced = typeof replacer === "string" ? found.map(() => replacer) : found.map((e) => replacer(e));
|
5
|
+
const splitted = input.split(pattern);
|
6
|
+
const replaced = splitted.map((chunk, chunkPos) => {
|
7
|
+
const isLast = chunkPos === splitted.length - 1;
|
8
|
+
if (isLast) return [chunk];
|
9
|
+
return [chunk, foundReplaced[chunkPos] ?? ""];
|
10
|
+
}).flat().join("");
|
11
|
+
return replaced;
|
12
|
+
}
|
13
|
+
|
14
|
+
export {
|
15
|
+
replaceAll
|
16
|
+
};
|