@design-edito/tools 0.0.33 → 0.1.2
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/agnostic/arrays/index.d.ts +11 -0
- package/{utils/agnostic → agnostic/arrays}/is-array-of/index.d.ts +2 -2
- package/agnostic/arrays/is-array-of/index.js +23 -0
- package/agnostic/async/index.d.ts +8 -0
- package/agnostic/async/index.js +20 -0
- package/agnostic/async/timeout-call/index.d.ts +1 -0
- package/agnostic/async/timeout-call/index.js +6 -0
- package/agnostic/async/transitions/index.d.ts +41 -0
- package/agnostic/async/transitions/index.js +7 -0
- package/agnostic/async/wait/index.d.ts +1 -0
- package/agnostic/async/wait/index.js +6 -0
- package/agnostic/booleans/index.d.ts +8 -0
- package/agnostic/booleans/index.js +17 -0
- package/{utils/agnostic → agnostic/booleans}/is-falsy/index.d.ts +1 -2
- package/agnostic/booleans/is-falsy/index.js +11 -0
- package/agnostic/css/bem/index.d.ts +7 -0
- package/agnostic/css/bem/index.js +9 -0
- package/{utils/agnostic → agnostic/css}/generate-nice-color/index.d.ts +0 -1
- package/agnostic/css/generate-nice-color/index.js +8 -0
- package/agnostic/css/index.d.ts +14 -0
- package/agnostic/css/index.js +177 -0
- package/agnostic/css/is-valid-css-class-name/index.d.ts +2 -0
- package/agnostic/css/is-valid-css-class-name/index.js +8 -0
- package/agnostic/css/styles-set/index.d.ts +37 -0
- package/agnostic/errors/index.d.ts +30 -0
- package/agnostic/errors/index.js +6 -0
- package/agnostic/html/get-node-ancestors/index.d.ts +1 -0
- package/agnostic/html/get-node-ancestors/index.js +6 -0
- package/agnostic/html/get-position-inside-parent/index.d.ts +1 -0
- package/agnostic/html/get-position-inside-parent/index.js +6 -0
- package/agnostic/html/index.d.ts +17 -0
- package/agnostic/html/index.js +39 -0
- package/agnostic/html/insert-node/index.d.ts +2 -0
- package/agnostic/html/insert-node/index.js +6 -0
- package/agnostic/html/placeholders/index.d.ts +9 -0
- package/agnostic/html/placeholders/index.js +6 -0
- package/agnostic/html/sanitize/index.d.ts +24 -0
- package/agnostic/html/sanitize/index.js +9 -0
- package/agnostic/html/selector-to-element/index.d.ts +1 -0
- package/agnostic/html/selector-to-element/index.js +9 -0
- package/agnostic/html/string-to-nodes/index.d.ts +7 -0
- package/agnostic/html/string-to-nodes/index.js +10 -0
- package/agnostic/index.d.ts +26 -0
- package/agnostic/misc/assert/index.d.ts +5 -0
- package/agnostic/misc/assert/index.js +6 -0
- package/agnostic/misc/cast/index.d.ts +9 -0
- package/agnostic/misc/cast/index.js +8 -0
- package/agnostic/misc/crossenv/index.d.ts +13 -0
- package/agnostic/misc/crossenv/index.js +6 -0
- package/agnostic/misc/get-current-downlink/index.d.ts +1 -0
- package/agnostic/misc/get-current-downlink/index.js +6 -0
- package/agnostic/misc/index.d.ts +22 -0
- package/agnostic/misc/index.js +45 -0
- package/{utils/agnostic → agnostic/misc}/is-constructor-function/index.d.ts +1 -1
- package/agnostic/misc/is-constructor-function/index.js +6 -0
- package/{utils/agnostic → agnostic/misc}/is-nullish/index.d.ts +0 -1
- package/agnostic/misc/is-nullish/index.js +10 -0
- package/agnostic/misc/logs/index.d.ts +55 -0
- package/agnostic/misc/logs/index.js +6 -0
- package/agnostic/misc/random/index.d.ts +10 -0
- package/agnostic/misc/random/index.js +6 -0
- package/agnostic/numbers/absolute-modulo/index.d.ts +1 -0
- package/agnostic/numbers/absolute-modulo/index.js +6 -0
- package/agnostic/numbers/clamp/index.d.ts +1 -0
- package/agnostic/numbers/clamp/index.js +6 -0
- package/agnostic/numbers/index.d.ts +13 -0
- package/agnostic/numbers/index.js +30 -0
- package/agnostic/numbers/interpolate/index.d.ts +1 -0
- package/agnostic/numbers/interpolate/index.js +6 -0
- package/agnostic/numbers/responsive-harmonics/index.js +9 -0
- package/agnostic/numbers/round/index.d.ts +1 -0
- package/agnostic/numbers/round/index.js +6 -0
- package/agnostic/objects/enums/index.d.ts +4 -0
- package/agnostic/objects/enums/index.js +7 -0
- package/{utils/agnostic → agnostic/objects/enums}/is-in-enum/index.d.ts +1 -1
- package/agnostic/objects/enums/is-in-enum/index.js +6 -0
- package/agnostic/objects/flatten-getters/index.d.ts +1 -0
- package/agnostic/objects/flatten-getters/index.js +9 -0
- package/agnostic/objects/index.d.ts +12 -0
- package/agnostic/objects/index.js +32 -0
- package/agnostic/objects/is-object/index.d.ts +1 -0
- package/agnostic/objects/is-object/index.js +6 -0
- package/agnostic/objects/is-record/index.d.ts +1 -0
- package/agnostic/objects/is-record/index.js +6 -0
- package/agnostic/objects/record-format/index.js +16 -0
- package/agnostic/objects/validation/index.d.ts +3 -0
- package/agnostic/objects/validation/index.js +6 -0
- package/agnostic/optim/index.d.ts +7 -0
- package/agnostic/optim/index.js +18 -0
- package/{utils/agnostic → agnostic/optim}/memoize/index.d.ts +1 -1
- package/agnostic/optim/memoize/index.js +6 -0
- package/agnostic/optim/throttle-debounce/index.js +8 -0
- package/{utils/agnostic → agnostic/optim}/throttle-debounce/types.d.ts +0 -1
- package/agnostic/regexps/index.d.ts +23 -0
- package/agnostic/regexps/index.js +89 -0
- package/agnostic/strings/char-codes/index.d.ts +17 -0
- package/agnostic/strings/char-codes/index.js +6 -0
- package/agnostic/strings/index.d.ts +14 -0
- package/agnostic/strings/index.js +32 -0
- package/agnostic/strings/matches/index.d.ts +3 -0
- package/agnostic/strings/matches/index.js +10 -0
- package/agnostic/strings/normalize-indent/index.d.ts +1 -0
- package/agnostic/strings/normalize-indent/index.js +6 -0
- package/{utils/agnostic → agnostic/strings}/replace-all/index.d.ts +1 -1
- package/agnostic/strings/replace-all/index.js +6 -0
- package/agnostic/strings/to-alphanum/index.d.ts +1 -0
- package/agnostic/strings/to-alphanum/index.js +6 -0
- package/chunks/chunk-32IRF4OP.js +9 -0
- package/chunks/chunk-34U4HX4V.js +73 -0
- package/chunks/chunk-4GDNHUCZ.js +162 -0
- package/chunks/chunk-4QQBKBYH.js +59 -0
- package/chunks/chunk-4VC5PT5T.js +13 -0
- package/chunks/chunk-5LNUCDQ6.js +132 -0
- package/chunks/chunk-7AWTHZLY.js +12 -0
- package/chunks/chunk-7DBNMU6N.js +14 -0
- package/chunks/chunk-COVPTTAD.js +10 -0
- package/chunks/chunk-DNIOWD7K.js +8 -0
- package/chunks/chunk-DQNJQBC6.js +10 -0
- package/chunks/chunk-E6MSDKON.js +13 -0
- package/chunks/chunk-EDVNAV3G.js +72 -0
- package/chunks/chunk-EW46EXFB.js +8 -0
- package/chunks/chunk-FPEW3A27.js +14 -0
- package/chunks/chunk-GJOU3UAL.js +36 -0
- package/chunks/chunk-HC6ZOHCS.js +14 -0
- package/chunks/chunk-HGCG2J77.js +122 -0
- package/chunks/chunk-IFD7GSGK.js +130 -0
- package/chunks/chunk-JQXNEJAP.js +18 -0
- package/chunks/chunk-JWBDZPQG.js +18 -0
- package/chunks/chunk-K37RALUX.js +8 -0
- package/chunks/chunk-KIONYWA7.js +168 -0
- package/chunks/chunk-KQT5CTGF.js +21 -0
- package/chunks/chunk-LEXQ6E6L.js +31 -0
- package/chunks/chunk-LQFKUNVQ.js +19 -0
- package/chunks/chunk-MF56TTC5.js +15 -0
- package/chunks/chunk-MT74WIQR.js +41 -0
- package/chunks/chunk-NRITRUZW.js +10 -0
- package/chunks/chunk-NRJQKVQV.js +31 -0
- package/chunks/chunk-OSAXBA7G.js +10 -0
- package/chunks/chunk-PO3V3I57.js +23 -0
- package/chunks/chunk-QXAJXTXV.js +19 -0
- package/chunks/chunk-RCO57B6F.js +9 -0
- package/chunks/chunk-SQZGZ3VT.js +15 -0
- package/chunks/chunk-UYTXXUU7.js +54 -0
- package/chunks/chunk-VTPRO4NJ.js +10 -0
- package/chunks/chunk-VYW4IADX.js +35 -0
- package/chunks/chunk-VZDUZTW6.js +113 -0
- package/chunks/chunk-W5A2TON3.js +10 -0
- package/chunks/chunk-W7YBGJ4H.js +28 -0
- package/chunks/chunk-WLL3FNVL.js +40 -0
- package/chunks/chunk-WOAYU6LB.js +13 -0
- package/chunks/chunk-XA4HVHJ4.js +18 -0
- package/chunks/chunk-XN3PZIVL.js +38 -0
- package/chunks/chunk-YDIBNEGA.js +9 -0
- package/components/index.d.ts +4 -0
- package/index.d.ts +3 -0
- package/node/files/index.d.ts +9 -0
- package/node/files/index.js +21 -0
- package/node/files/is-in-directory/index.d.ts +1 -0
- package/node/files/is-in-directory/index.js +6 -0
- package/node/files/read-write/index.d.ts +9 -0
- package/node/files/read-write/index.js +6 -0
- package/node/files/subpaths/index.d.ts +34 -0
- package/node/files/subpaths/index.js +7 -0
- package/node/index.d.ts +6 -0
- package/node/process/index.d.ts +8 -0
- package/node/process/index.js +20 -0
- package/{utils/node/process-exit → node/process/on-exit}/index.d.ts +1 -1
- package/node/process/on-exit/index.js +14 -0
- package/package.json +12 -12
- package/shared/errors/index.d.ts +14 -0
- package/shared/index.d.ts +0 -0
- package/chunks/chunk-BEZTX3QU.js +0 -1
- package/chunks/chunk-BW5CY5YB.js +0 -1
- package/chunks/chunk-DIPJ73JH.js +0 -1
- package/chunks/chunk-EFFU6KXJ.js +0 -1
- package/chunks/chunk-KNE7WIIW.js +0 -1
- package/chunks/chunk-LCLAV6Q2.js +0 -1
- package/chunks/chunk-PCAKH6ZJ.js +0 -1
- package/chunks/chunk-QQRJPDR7.js +0 -1
- package/chunks/chunk-WZBNXYN3.js +0 -1
- package/chunks/chunk-XCKXCF4A.js +0 -1
- package/chunks/chunk-ZVJO36JU.js +0 -1
- package/components/Comp/index.js +0 -1
- package/index.js +0 -96
- package/utils/agnostic/absolute-modulo/index.d.ts +0 -1
- package/utils/agnostic/absolute-modulo/index.js +0 -1
- package/utils/agnostic/array/index.d.ts +0 -7
- package/utils/agnostic/array/index.js +0 -1
- package/utils/agnostic/assert/index.d.ts +0 -3
- package/utils/agnostic/assert/index.js +0 -1
- package/utils/agnostic/await-timeout/index.d.ts +0 -2
- package/utils/agnostic/await-timeout/index.js +0 -1
- package/utils/agnostic/bem/index.d.ts +0 -5
- package/utils/agnostic/bem/index.js +0 -1
- package/utils/agnostic/cast/index.d.ts +0 -7
- package/utils/agnostic/cast/index.js +0 -1
- package/utils/agnostic/charcode-string/index.d.ts +0 -2
- package/utils/agnostic/charcode-string/index.js +0 -1
- package/utils/agnostic/clamp/index.d.ts +0 -1
- package/utils/agnostic/clamp/index.js +0 -1
- package/utils/agnostic/clientside-html-sanitizer/index.d.ts +0 -22
- package/utils/agnostic/clientside-html-sanitizer/index.js +0 -1
- package/utils/agnostic/crossenv/index.d.ts +0 -11
- package/utils/agnostic/crossenv/index.js +0 -1
- package/utils/agnostic/flatten-getters/index.d.ts +0 -1
- package/utils/agnostic/flatten-getters/index.js +0 -1
- package/utils/agnostic/generate-html-placeholders/index.d.ts +0 -7
- package/utils/agnostic/generate-html-placeholders/index.js +0 -5
- package/utils/agnostic/generate-nice-color/index.js +0 -1
- package/utils/agnostic/insert-node/index.d.ts +0 -2
- package/utils/agnostic/insert-node/index.js +0 -1
- package/utils/agnostic/interpolate/index.d.ts +0 -3
- package/utils/agnostic/interpolate/index.js +0 -1
- package/utils/agnostic/is-array-of/index.js +0 -1
- package/utils/agnostic/is-constructor-function/index.js +0 -1
- package/utils/agnostic/is-falsy/index.js +0 -1
- package/utils/agnostic/is-in-enum/index.js +0 -1
- package/utils/agnostic/is-nullish/index.js +0 -1
- package/utils/agnostic/is-object/index.d.ts +0 -1
- package/utils/agnostic/is-object/index.js +0 -1
- package/utils/agnostic/is-record/index.d.ts +0 -1
- package/utils/agnostic/is-record/index.js +0 -1
- package/utils/agnostic/is-valid-css-class-name/index.d.ts +0 -2
- package/utils/agnostic/is-valid-css-class-name/index.js +0 -1
- package/utils/agnostic/memoize/index.js +0 -1
- package/utils/agnostic/object-validate-from-partial/index.d.ts +0 -1
- package/utils/agnostic/object-validate-from-partial/index.js +0 -1
- package/utils/agnostic/random/index.d.ts +0 -9
- package/utils/agnostic/random/index.js +0 -1
- package/utils/agnostic/record-format/index.js +0 -1
- package/utils/agnostic/regexp/index.d.ts +0 -21
- package/utils/agnostic/regexp/index.js +0 -1
- package/utils/agnostic/replace-all/index.js +0 -1
- package/utils/agnostic/responsive-harmonics/index.js +0 -1
- package/utils/agnostic/round-numbers/index.d.ts +0 -1
- package/utils/agnostic/round-numbers/index.js +0 -1
- package/utils/agnostic/selector-to-element/index.d.ts +0 -1
- package/utils/agnostic/selector-to-element/index.js +0 -1
- package/utils/agnostic/silent-log/index.d.ts +0 -53
- package/utils/agnostic/silent-log/index.js +0 -9
- package/utils/agnostic/str-to-nodes/index.d.ts +0 -7
- package/utils/agnostic/str-to-nodes/index.js +0 -1
- package/utils/agnostic/string-matches/index.d.ts +0 -4
- package/utils/agnostic/string-matches/index.js +0 -1
- package/utils/agnostic/string-normalize-indent/index.d.ts +0 -1
- package/utils/agnostic/string-normalize-indent/index.js +0 -3
- package/utils/agnostic/throttle-debounce/index.js +0 -1
- package/utils/agnostic/to-alphanum/index.d.ts +0 -1
- package/utils/agnostic/to-alphanum/index.js +0 -1
- package/utils/agnostic/transition/index.d.ts +0 -39
- package/utils/agnostic/transition/index.js +0 -1
- package/utils/agnostic/wait/index.d.ts +0 -1
- package/utils/agnostic/wait/index.js +0 -1
- package/utils/browser/dynamic-css/index.d.ts +0 -4
- package/utils/browser/dynamic-css/index.js +0 -2
- package/utils/browser/get-current-downlink/index.d.ts +0 -1
- package/utils/browser/get-current-downlink/index.js +0 -1
- package/utils/browser/get-node-ancestors/index.d.ts +0 -1
- package/utils/browser/get-node-ancestors/index.js +0 -1
- package/utils/node/is-in-directory/index.d.ts +0 -1
- package/utils/node/is-in-directory/index.js +0 -1
- package/utils/node/list-subpaths/index.d.ts +0 -33
- package/utils/node/list-subpaths/index.js +0 -1
- package/utils/node/process-exit/index.js +0 -1
- package/utils/node/read-write-file/index.d.ts +0 -12
- package/utils/node/read-write-file/index.js +0 -1
- /package/{utils/agnostic → agnostic/css}/bem/BEM.d.ts +0 -0
- /package/{utils/agnostic → agnostic/css}/bem/getNamesArr.d.ts +0 -0
- /package/{utils/agnostic → agnostic/numbers}/responsive-harmonics/index.d.ts +0 -0
- /package/{utils/agnostic → agnostic/objects}/record-format/index.d.ts +0 -0
- /package/{utils/agnostic → agnostic/optim}/throttle-debounce/index.d.ts +0 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// src/agnostic/misc/logs/index.ts
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
var Logs;
|
|
4
|
+
((Logs2) => {
|
|
5
|
+
function makeTextBlock(text, vPadding = 1, hPadding = vPadding) {
|
|
6
|
+
const lines = text.split("\n");
|
|
7
|
+
const longestLine = Math.max(...lines.map((line) => line.length));
|
|
8
|
+
const textBlockArr = new Array(lines.length + 2 * vPadding).fill(null).map(() => new Array(longestLine + hPadding * 2).fill(" "));
|
|
9
|
+
lines.forEach((line, linePos) => {
|
|
10
|
+
const chars = line.split("");
|
|
11
|
+
textBlockArr[linePos + vPadding]?.splice(hPadding, chars.length, ...chars);
|
|
12
|
+
});
|
|
13
|
+
return textBlockArr.map((lineArr) => lineArr.join("")).join("\n");
|
|
14
|
+
}
|
|
15
|
+
Logs2.makeTextBlock = makeTextBlock;
|
|
16
|
+
Logs2.styles = {
|
|
17
|
+
regular: (text) => text,
|
|
18
|
+
light: (text) => chalk.grey(text),
|
|
19
|
+
danger: (text) => chalk.bold.bgRed.whiteBright(makeTextBlock(`/!\\
|
|
20
|
+
|
|
21
|
+
${text}
|
|
22
|
+
`, 2, 6)),
|
|
23
|
+
important: (text) => chalk.bold(text),
|
|
24
|
+
title: (text) => `# ${chalk.bold.underline(`${text}
|
|
25
|
+
`)}`,
|
|
26
|
+
info: (text) => chalk.blueBright(text),
|
|
27
|
+
error: (text) => chalk.red(text),
|
|
28
|
+
warning: (text) => chalk.yellow(text)
|
|
29
|
+
};
|
|
30
|
+
const logsTimeOrigin = /* @__PURE__ */ new Date();
|
|
31
|
+
class Log {
|
|
32
|
+
type;
|
|
33
|
+
data;
|
|
34
|
+
time;
|
|
35
|
+
stack;
|
|
36
|
+
constructor(type, data) {
|
|
37
|
+
this.type = type;
|
|
38
|
+
this.data = data;
|
|
39
|
+
this.time = /* @__PURE__ */ new Date();
|
|
40
|
+
this.stack = new Error().stack ?? "";
|
|
41
|
+
}
|
|
42
|
+
get displayTime() {
|
|
43
|
+
return this.time.toLocaleDateString("en-US", {
|
|
44
|
+
year: "numeric",
|
|
45
|
+
month: "short",
|
|
46
|
+
day: "numeric",
|
|
47
|
+
weekday: "short",
|
|
48
|
+
hour: "numeric",
|
|
49
|
+
minute: "numeric",
|
|
50
|
+
second: "numeric"
|
|
51
|
+
}) + `:${this.time.getMilliseconds()}`;
|
|
52
|
+
}
|
|
53
|
+
get elapsedTimeMs() {
|
|
54
|
+
return (this.time.getTime() - logsTimeOrigin.getTime()) / 1e3;
|
|
55
|
+
}
|
|
56
|
+
get displayStack() {
|
|
57
|
+
return this.stack.split("\n").map((line) => line.trim()).slice(4).join("\n");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
class Logger {
|
|
61
|
+
_private_threads = /* @__PURE__ */ new Map();
|
|
62
|
+
constructor() {
|
|
63
|
+
this.dir = this.dir.bind(this);
|
|
64
|
+
this.error = this.error.bind(this);
|
|
65
|
+
this.log = this.log.bind(this);
|
|
66
|
+
this.warn = this.warn.bind(this);
|
|
67
|
+
this.setLog = this.setLog.bind(this);
|
|
68
|
+
this.print = this.print.bind(this);
|
|
69
|
+
this.printThreads = this.printThreads.bind(this);
|
|
70
|
+
}
|
|
71
|
+
// assert (thread: string = '', ...args: ConsoleMethodsParams['assert']) { this.setLog(thread, 'assert', args) }
|
|
72
|
+
// count (thread: string = '', ...args: ConsoleMethodsParams['count']) { this.setLog(thread, 'count', args) }
|
|
73
|
+
// countReset (thread: string = '', ...args: ConsoleMethodsParams['countReset']) { this.setLog(thread, 'countReset', args) }
|
|
74
|
+
// debug (thread: string = '', ...args: ConsoleMethodsParams['debug']) { this.setLog(thread, 'debug', args) }
|
|
75
|
+
dir(thread = "", ...args) {
|
|
76
|
+
this.setLog(thread, "dir", args);
|
|
77
|
+
}
|
|
78
|
+
// dirxml (thread: string = '', ...args: ConsoleMethodsParams['dirxml']) { this.setLog(thread, 'dirxml', args) }
|
|
79
|
+
error(thread = "", ...args) {
|
|
80
|
+
this.setLog(thread, "error", args);
|
|
81
|
+
}
|
|
82
|
+
// group (thread: string = '', ...args: ConsoleMethodsParams['group']) { this.setLog(thread, 'group', args) }
|
|
83
|
+
// groupCollapsed (thread: string = '', ...args: ConsoleMethodsParams['groupCollapsed']) { this.setLog(thread, 'groupCollapsed', args) }
|
|
84
|
+
// groupEnd (thread: string = '', ...args: ConsoleMethodsParams['groupEnd']) { this.setLog(thread, 'groupEnd', args) }
|
|
85
|
+
// info (thread: string = '', ...args: ConsoleMethodsParams['info']) { this.setLog(thread, 'info', args) }
|
|
86
|
+
log(thread = "", ...args) {
|
|
87
|
+
this.setLog(thread, "log", args);
|
|
88
|
+
}
|
|
89
|
+
// table (thread: string = '', ...args: ConsoleMethodsParams['table']) { this.setLog(thread, 'table', args) }
|
|
90
|
+
// time (thread: string = '', ...args: ConsoleMethodsParams['time']) { this.setLog(thread, 'time', args) }
|
|
91
|
+
// timeEnd (thread: string = '', ...args: ConsoleMethodsParams['timeEnd']) { this.setLog(thread, 'timeEnd', args) }
|
|
92
|
+
// trace (thread: string = '', ...args: ConsoleMethodsParams['trace']) { this.setLog(thread, 'trace', args) }
|
|
93
|
+
warn(thread = "", ...args) {
|
|
94
|
+
this.setLog(thread, "warn", args);
|
|
95
|
+
}
|
|
96
|
+
setLog(threadName, type, data) {
|
|
97
|
+
const log = new Log(type, data);
|
|
98
|
+
const thread = this._private_threads.get(threadName) ?? [];
|
|
99
|
+
this._private_threads.set(threadName, [...thread, log]);
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
print(threadFilter, withStack) {
|
|
103
|
+
const allLogs = Array.from(this._private_threads.entries()).map(([threadName, logs]) => logs.map((log) => ({ threadName, log }))).flat().sort((eltA, eltB) => eltA.log.time.getTime() - eltB.log.time.getTime()).filter(({ threadName }) => {
|
|
104
|
+
if (threadFilter === void 0) return true;
|
|
105
|
+
return threadName === threadFilter;
|
|
106
|
+
});
|
|
107
|
+
allLogs.forEach(({ threadName, log }) => {
|
|
108
|
+
console.log(`%c${threadName}`, "font-weight: 800; color: white; background: black; padding: 4px;", `+${log.elapsedTimeMs}s \u2013`, log.displayTime);
|
|
109
|
+
if (withStack === true) console.log(`%c${log.displayStack}`, "color: grey; font-size: inherit;");
|
|
110
|
+
console[log.type](...log.data);
|
|
111
|
+
console.log("");
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
printThreads(withStack) {
|
|
115
|
+
Array.from(this._private_threads.entries()).forEach(([threadName, logs]) => {
|
|
116
|
+
console.group(`%c${threadName}`, "font-weight: 800; color: white; background: black; padding: 4px;");
|
|
117
|
+
logs.forEach((log) => {
|
|
118
|
+
console.log(`+${log.elapsedTimeMs}s \u2013`, log.displayTime);
|
|
119
|
+
if (withStack === true) console.log(`%c${log.displayStack}`, "color: grey; font-size: inherit;");
|
|
120
|
+
console[log.type](...log.data);
|
|
121
|
+
console.log("");
|
|
122
|
+
});
|
|
123
|
+
console.groupEnd();
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
Logs2.Logger = Logger;
|
|
128
|
+
})(Logs || (Logs = {}));
|
|
129
|
+
|
|
130
|
+
export {
|
|
131
|
+
Logs
|
|
132
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/agnostic/misc/get-current-downlink/index.ts
|
|
2
|
+
function getCurrentDownlink() {
|
|
3
|
+
if (typeof window !== "object") return void 0;
|
|
4
|
+
if (typeof window.navigator !== "object") return void 0;
|
|
5
|
+
const navigator = window.navigator;
|
|
6
|
+
const connection = navigator?.connection ?? navigator?.mozConnection ?? navigator?.webkitConnection;
|
|
7
|
+
return connection?.downlink;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
getCurrentDownlink
|
|
12
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/node/files/read-write/index.ts
|
|
2
|
+
import { promises as fs } from "node:fs";
|
|
3
|
+
async function readWrite(path, editor, ...options) {
|
|
4
|
+
const [readOptions, writeOptions] = options;
|
|
5
|
+
const read = await fs.readFile(path, readOptions);
|
|
6
|
+
const edited = editor(read);
|
|
7
|
+
const actualWriteOptions = options.length === 2 ? writeOptions : readOptions;
|
|
8
|
+
await fs.writeFile(path, edited, actualWriteOptions);
|
|
9
|
+
return edited;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
readWrite
|
|
14
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/agnostic/strings/to-alphanum/index.ts
|
|
2
|
+
function toAlphanum(string, replacer = "") {
|
|
3
|
+
const replaced = string.replace(/[^a-z0-9]/igm, replacer);
|
|
4
|
+
if (replacer.length === 0) return replaced;
|
|
5
|
+
return replaced.replace(new RegExp(`${replacer}+`, "igm"), replacer);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
toAlphanum
|
|
10
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/agnostic/objects/enums/is-in-enum/index.ts
|
|
2
|
+
function isInEnum(enumObj, value) {
|
|
3
|
+
const keys = Object.keys(enumObj);
|
|
4
|
+
const values = Object.values(enumObj);
|
|
5
|
+
const numericValues = values.filter((val) => typeof val === "number");
|
|
6
|
+
const cleanKeys = keys.filter((key) => !numericValues.includes(parseInt(key, 10)));
|
|
7
|
+
const cleanValues = cleanKeys.map((cleanKey) => enumObj[cleanKey]);
|
|
8
|
+
return cleanValues.includes(value);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
isInEnum
|
|
13
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// src/agnostic/css/generate-nice-color/index.ts
|
|
2
|
+
var niceColors = [
|
|
3
|
+
"fuchsia",
|
|
4
|
+
"teal",
|
|
5
|
+
"aliceblue",
|
|
6
|
+
"bisque",
|
|
7
|
+
"blueviolet",
|
|
8
|
+
"burlywood",
|
|
9
|
+
"chocolate",
|
|
10
|
+
"coral",
|
|
11
|
+
"cornflowerblue",
|
|
12
|
+
"crimson",
|
|
13
|
+
"darkblue",
|
|
14
|
+
"darkgoldenrod",
|
|
15
|
+
"darkkhaki",
|
|
16
|
+
"darkmagenta",
|
|
17
|
+
"darkolivegreen",
|
|
18
|
+
"darkorange",
|
|
19
|
+
"darkorchid",
|
|
20
|
+
"darkred",
|
|
21
|
+
"darksalmon",
|
|
22
|
+
"darkslateblue",
|
|
23
|
+
"darkslategray",
|
|
24
|
+
"darkviolet",
|
|
25
|
+
"deeppink",
|
|
26
|
+
"deepskyblue",
|
|
27
|
+
"dodgerblue",
|
|
28
|
+
"firebrick",
|
|
29
|
+
"floralwhite",
|
|
30
|
+
"gainsboro",
|
|
31
|
+
"gold",
|
|
32
|
+
"hotpink",
|
|
33
|
+
"indianred",
|
|
34
|
+
"indigo",
|
|
35
|
+
"khaki",
|
|
36
|
+
"lavender",
|
|
37
|
+
"lightcoral",
|
|
38
|
+
"lightgreen",
|
|
39
|
+
"lightsalmon",
|
|
40
|
+
"lightsteelblue",
|
|
41
|
+
"limegreen",
|
|
42
|
+
"magenta",
|
|
43
|
+
"mediumseagreen",
|
|
44
|
+
"mediumspringgreen",
|
|
45
|
+
"mediumvioletred",
|
|
46
|
+
"moccasin",
|
|
47
|
+
"orangered",
|
|
48
|
+
"orchid",
|
|
49
|
+
"palegoldenrod",
|
|
50
|
+
"palevioletred",
|
|
51
|
+
"peachpuff",
|
|
52
|
+
"peru",
|
|
53
|
+
"plum",
|
|
54
|
+
"royalblue",
|
|
55
|
+
"sandybrown",
|
|
56
|
+
"springgreen",
|
|
57
|
+
"tan",
|
|
58
|
+
"thistle",
|
|
59
|
+
"tomato",
|
|
60
|
+
"violet",
|
|
61
|
+
"wheat",
|
|
62
|
+
"yellowgreen"
|
|
63
|
+
];
|
|
64
|
+
var generateNiceColor = () => {
|
|
65
|
+
const pos = Math.floor(Math.random() * niceColors.length);
|
|
66
|
+
return niceColors[pos];
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export {
|
|
70
|
+
niceColors,
|
|
71
|
+
generateNiceColor
|
|
72
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/agnostic/objects/validation/index.ts
|
|
2
|
+
var Validation;
|
|
3
|
+
((Validation2) => {
|
|
4
|
+
function fromPartial(obj, partial) {
|
|
5
|
+
return Object.entries(partial).every(([key, val]) => {
|
|
6
|
+
return obj[key] === val;
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
Validation2.fromPartial = fromPartial;
|
|
10
|
+
})(Validation || (Validation = {}));
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
Validation
|
|
14
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// src/agnostic/misc/crossenv/index.ts
|
|
2
|
+
var Crossenv;
|
|
3
|
+
((Crossenv2) => {
|
|
4
|
+
let RuntimeName;
|
|
5
|
+
((RuntimeName2) => {
|
|
6
|
+
RuntimeName2["NODE"] = "Node.js";
|
|
7
|
+
RuntimeName2["BROWSER"] = "Browser";
|
|
8
|
+
RuntimeName2["DENO"] = "Deno";
|
|
9
|
+
RuntimeName2["REACT_NATIVE"] = "React Native";
|
|
10
|
+
RuntimeName2["ELECTRON"] = "Electron";
|
|
11
|
+
RuntimeName2["CLOUDFLARE"] = "Cloudflare Workers";
|
|
12
|
+
RuntimeName2["AWS_LAMBDA"] = "AWS Lambda";
|
|
13
|
+
})(RuntimeName = Crossenv2.RuntimeName || (Crossenv2.RuntimeName = {}));
|
|
14
|
+
function detectRuntime() {
|
|
15
|
+
if (typeof process !== "undefined" && typeof process.versions !== "undefined" && typeof process.versions.node !== "undefined") return "Node.js" /* NODE */;
|
|
16
|
+
if (typeof window !== "undefined" && typeof window.document !== "undefined") return "Browser" /* BROWSER */;
|
|
17
|
+
if (typeof Deno !== "undefined") return "Deno" /* DENO */;
|
|
18
|
+
if (typeof process !== "undefined" && typeof navigator.userAgent === "string" && /ReactNative/.test(navigator.userAgent)) return "React Native" /* REACT_NATIVE */;
|
|
19
|
+
if (typeof process !== "undefined" && typeof process.versions !== "undefined" && typeof process.version.electron !== "undefined") return "Electron" /* ELECTRON */;
|
|
20
|
+
if (typeof self !== "undefined" && typeof self.addEventListener === "function" && typeof Headers !== "undefined") return "Cloudflare Workers" /* CLOUDFLARE */;
|
|
21
|
+
if (typeof AWS !== "undefined" && typeof AWS.Lambda !== "undefined") return "AWS Lambda" /* AWS_LAMBDA */;
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
Crossenv2.detectRuntime = detectRuntime;
|
|
25
|
+
function getDocument() {
|
|
26
|
+
const runtime = detectRuntime();
|
|
27
|
+
const runtimesWithGlobalWindow = ["Browser" /* BROWSER */, "Electron" /* ELECTRON */];
|
|
28
|
+
const runtimeHasGlobalWindow = runtimesWithGlobalWindow.includes(runtime);
|
|
29
|
+
return runtimeHasGlobalWindow ? window.document : null;
|
|
30
|
+
}
|
|
31
|
+
Crossenv2.getDocument = getDocument;
|
|
32
|
+
})(Crossenv || (Crossenv = {}));
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
Crossenv
|
|
36
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/agnostic/misc/is-nullish/index.ts
|
|
2
|
+
var nullishValues = [null, void 0];
|
|
3
|
+
function isNullish(val) {
|
|
4
|
+
return nullishValues.includes(val);
|
|
5
|
+
}
|
|
6
|
+
function isNotNullish(val) {
|
|
7
|
+
return !isNullish(val);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
nullishValues,
|
|
12
|
+
isNullish,
|
|
13
|
+
isNotNullish
|
|
14
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
matchesSome
|
|
3
|
+
} from "./chunk-LQFKUNVQ.js";
|
|
4
|
+
|
|
5
|
+
// src/node/files/subpaths/index.ts
|
|
6
|
+
import { promises as fs } from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
var Subpaths;
|
|
9
|
+
((Subpaths2) => {
|
|
10
|
+
Subpaths2.defaultListContext = {
|
|
11
|
+
depth: 0,
|
|
12
|
+
lstats: null,
|
|
13
|
+
rootPath: null
|
|
14
|
+
};
|
|
15
|
+
Subpaths2.fillListContext = (input) => {
|
|
16
|
+
return {
|
|
17
|
+
...Subpaths2.defaultListContext,
|
|
18
|
+
...input
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
Subpaths2.defaultListOptions = {
|
|
22
|
+
directories: true,
|
|
23
|
+
files: true,
|
|
24
|
+
symlinks: true,
|
|
25
|
+
hidden: true,
|
|
26
|
+
followSimlinks: false,
|
|
27
|
+
dedupeSimlinksContents: false,
|
|
28
|
+
maxDepth: Infinity,
|
|
29
|
+
returnRelative: false,
|
|
30
|
+
exclude: null,
|
|
31
|
+
include: null,
|
|
32
|
+
filter: () => true
|
|
33
|
+
};
|
|
34
|
+
Subpaths2.fillOptions = (input) => {
|
|
35
|
+
return {
|
|
36
|
+
...Subpaths2.defaultListOptions,
|
|
37
|
+
...input
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
async function list(...args) {
|
|
41
|
+
const [inputPath, _options] = args;
|
|
42
|
+
const options = (0, Subpaths2.fillOptions)(_options ?? {});
|
|
43
|
+
const subpaths = await listAbsoluteSubpaths(...args);
|
|
44
|
+
return options.returnRelative ? subpaths.map((subpath) => path.relative(inputPath, subpath)) : subpaths;
|
|
45
|
+
}
|
|
46
|
+
Subpaths2.list = list;
|
|
47
|
+
async function listAbsoluteSubpaths(inputPath, _options = {}, __private_context = {}) {
|
|
48
|
+
const options = (0, Subpaths2.fillOptions)(_options);
|
|
49
|
+
const _private_context = (0, Subpaths2.fillListContext)(__private_context);
|
|
50
|
+
if (_private_context.rootPath === null) {
|
|
51
|
+
_private_context.rootPath = inputPath;
|
|
52
|
+
}
|
|
53
|
+
const subpaths = [];
|
|
54
|
+
if (_private_context.depth > options.maxDepth) return subpaths;
|
|
55
|
+
try {
|
|
56
|
+
const pathStat = _private_context.lstats ?? await fs.lstat(inputPath);
|
|
57
|
+
if (!pathStat.isDirectory()) return subpaths;
|
|
58
|
+
} catch (err) {
|
|
59
|
+
return subpaths;
|
|
60
|
+
}
|
|
61
|
+
const childrenRelPaths = await fs.readdir(inputPath);
|
|
62
|
+
await Promise.all(childrenRelPaths.map(async (childRelPath) => {
|
|
63
|
+
const childAbsPath = path.join(inputPath, childRelPath);
|
|
64
|
+
const childRelFromRootPath = path.relative(_private_context.rootPath ?? inputPath, childAbsPath);
|
|
65
|
+
const childLstats = await fs.lstat(childAbsPath);
|
|
66
|
+
try {
|
|
67
|
+
const isDirectory = childLstats.isDirectory();
|
|
68
|
+
const isSymlink = childLstats.isSymbolicLink();
|
|
69
|
+
const isFile = !isDirectory && !isSymlink;
|
|
70
|
+
const isHidden = path.basename(childAbsPath).startsWith(".");
|
|
71
|
+
const type = isDirectory ? "directory" : isSymlink ? "symlink" : "file";
|
|
72
|
+
if (isDirectory && options.directories === false) throw true;
|
|
73
|
+
if (isSymlink && options.symlinks === false) throw false;
|
|
74
|
+
if (isFile && options.files === false) throw false;
|
|
75
|
+
if (isHidden && options.hidden === false) throw false;
|
|
76
|
+
const realPath = isSymlink ? await fs.realpath(childAbsPath) : childAbsPath;
|
|
77
|
+
const childPathForFilters = options.returnRelative ? childRelFromRootPath : childAbsPath;
|
|
78
|
+
const isInExclude = matchesSome(childPathForFilters, options.exclude ?? []);
|
|
79
|
+
const isInInclude = matchesSome(childPathForFilters, options.include ?? []);
|
|
80
|
+
if (isInExclude && !isInInclude) throw false;
|
|
81
|
+
const isInFilter = await options.filter(childPathForFilters, { type, hidden: isHidden, realPath });
|
|
82
|
+
if (!isInFilter) throw true;
|
|
83
|
+
if (isSymlink) {
|
|
84
|
+
if (options.followSimlinks === false) subpaths.push(childAbsPath);
|
|
85
|
+
else {
|
|
86
|
+
const childSubpaths = await listAbsoluteSubpaths(realPath, options, {
|
|
87
|
+
..._private_context,
|
|
88
|
+
depth: _private_context.depth + 1
|
|
89
|
+
});
|
|
90
|
+
subpaths.push(realPath, ...childSubpaths);
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
if (isDirectory) {
|
|
94
|
+
const childSubpaths = await listAbsoluteSubpaths(childAbsPath, options, {
|
|
95
|
+
..._private_context,
|
|
96
|
+
depth: _private_context.depth + 1,
|
|
97
|
+
lstats: childLstats
|
|
98
|
+
});
|
|
99
|
+
subpaths.push(childAbsPath, ...childSubpaths);
|
|
100
|
+
} else {
|
|
101
|
+
subpaths.push(childAbsPath);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
} catch (err) {
|
|
105
|
+
if (typeof err !== "boolean") throw new Error(`This try/catch block should only throw booleans`);
|
|
106
|
+
const shouldDiveDeeper = err;
|
|
107
|
+
if (!shouldDiveDeeper) return [];
|
|
108
|
+
const childSubpaths = await listAbsoluteSubpaths(childAbsPath, options, {
|
|
109
|
+
..._private_context,
|
|
110
|
+
depth: _private_context.depth + 1,
|
|
111
|
+
lstats: childLstats
|
|
112
|
+
});
|
|
113
|
+
subpaths.push(...childSubpaths);
|
|
114
|
+
}
|
|
115
|
+
}));
|
|
116
|
+
return options.dedupeSimlinksContents ? Array.from(new Set(subpaths)) : subpaths;
|
|
117
|
+
}
|
|
118
|
+
})(Subpaths || (Subpaths = {}));
|
|
119
|
+
|
|
120
|
+
export {
|
|
121
|
+
Subpaths
|
|
122
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import {
|
|
2
|
+
register
|
|
3
|
+
} from "./chunk-KQT5CTGF.js";
|
|
4
|
+
import {
|
|
5
|
+
Crossenv
|
|
6
|
+
} from "./chunk-GJOU3UAL.js";
|
|
7
|
+
|
|
8
|
+
// src/agnostic/html/sanitize/index.ts
|
|
9
|
+
var Sanitize;
|
|
10
|
+
((Sanitize2) => {
|
|
11
|
+
Sanitize2.defaultOptions = { depth: 20 };
|
|
12
|
+
function sanitize(inputStr, options = Sanitize2.defaultOptions) {
|
|
13
|
+
const actualDocument = options.documentObj ?? Crossenv.getDocument();
|
|
14
|
+
if (actualDocument === null) throw register.getError("no-window-document-on-runtime-please-provide" /* NO_DOCUMENT_PLEASE_PROVIDE */, "See documentObj in the options object");
|
|
15
|
+
const wrapperDiv = actualDocument.createElement("div");
|
|
16
|
+
const { inputFreeTransform } = options;
|
|
17
|
+
wrapperDiv.innerHTML = inputFreeTransform !== void 0 ? inputFreeTransform(inputStr) : inputStr;
|
|
18
|
+
const sanitizedWrapper = sanitizeElement(wrapperDiv, options);
|
|
19
|
+
const returned = sanitizedWrapper?.innerHTML;
|
|
20
|
+
return returned ?? "";
|
|
21
|
+
}
|
|
22
|
+
Sanitize2.sanitize = sanitize;
|
|
23
|
+
function sanitizeElement(element, options = Sanitize2.defaultOptions) {
|
|
24
|
+
const actualDocument = options.documentObj ?? Crossenv.getDocument();
|
|
25
|
+
if (actualDocument === null) throw register.getError("no-window-document-on-runtime-please-provide" /* NO_DOCUMENT_PLEASE_PROVIDE */, "See documentObj in the options object");
|
|
26
|
+
const { tagName, attributes, childNodes } = element;
|
|
27
|
+
const {
|
|
28
|
+
allowedTags = [],
|
|
29
|
+
allowedAttributes = {},
|
|
30
|
+
forbiddenTags = [],
|
|
31
|
+
forbiddenAttributes = {},
|
|
32
|
+
depth = 20,
|
|
33
|
+
verbose = false
|
|
34
|
+
} = options;
|
|
35
|
+
if (depth <= 0) {
|
|
36
|
+
console.warn("Max depth reached");
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const normalizedTagName = tagName.toLowerCase().trim();
|
|
40
|
+
const tagIsInForbidden = forbiddenTags.includes("*") || forbiddenTags.includes(normalizedTagName);
|
|
41
|
+
if (tagIsInForbidden) {
|
|
42
|
+
if (verbose === true) console.warn(tagName, "tag is forbidden");
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const tagIsInAllowed = allowedTags.includes("*") || allowedTags.includes(normalizedTagName);
|
|
46
|
+
if (!tagIsInAllowed) {
|
|
47
|
+
if (verbose === true) console.warn(tagName, "tag is not allowed");
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const returnedElement = actualDocument.createElement(tagName);
|
|
51
|
+
const returnedAttributes = Array.from(attributes).filter(({ name: attributeName, value: attributeValue }) => {
|
|
52
|
+
const allTagsForbiddenAttributes = forbiddenAttributes["*"] ?? [];
|
|
53
|
+
const thisTagForbiddenAttributes = forbiddenAttributes[normalizedTagName] ?? [];
|
|
54
|
+
const mergedForbiddenAttributes = [...allTagsForbiddenAttributes, ...thisTagForbiddenAttributes];
|
|
55
|
+
const isInForbidden = mergedForbiddenAttributes.some(({
|
|
56
|
+
attributeName: nameTester,
|
|
57
|
+
attributeValues: valTesters
|
|
58
|
+
}) => {
|
|
59
|
+
if (typeof nameTester === "string" && nameTester !== "*" && attributeName !== nameTester) return false;
|
|
60
|
+
if (typeof nameTester !== "string" && !nameTester.test(attributeName)) return false;
|
|
61
|
+
if (valTesters === void 0) {
|
|
62
|
+
if (verbose === true) console.warn(attributeName, "attribute on", tagName, "tag is forbidden");
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
if (valTesters.includes("*")) {
|
|
66
|
+
if (verbose === true) console.warn(attributeName, "attribute on", tagName, "tag is forbidden");
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
return valTesters.some((valTester) => {
|
|
70
|
+
if (typeof valTester === "string" && attributeValue === valTester) {
|
|
71
|
+
if (verbose === true) console.warn(attributeValue, "value for", attributeName, "attribute on", tagName, "tag is forbidden. Rule:", valTester);
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
if (typeof valTester !== "string" && valTester.test(attributeValue)) {
|
|
75
|
+
if (verbose === true) console.warn(attributeValue, "value for", attributeName, "attribute on", tagName, "tag is forbidden. Rule:", valTester);
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
if (isInForbidden) return false;
|
|
82
|
+
const allTagsAllowedAttributes = allowedAttributes["*"] ?? [];
|
|
83
|
+
const thisTagAllowedAttributes = allowedAttributes[normalizedTagName] ?? [];
|
|
84
|
+
const mergedAllowedAttributes = [...allTagsAllowedAttributes, ...thisTagAllowedAttributes];
|
|
85
|
+
let latestNotAllowedReason = [tagName, "has no allowed attributes"];
|
|
86
|
+
const isInAllowed = mergedAllowedAttributes.some(({
|
|
87
|
+
attributeName: nameTester,
|
|
88
|
+
attributeValues: valTesters
|
|
89
|
+
}) => {
|
|
90
|
+
if (typeof nameTester === "string" && nameTester !== "*" && attributeName !== nameTester) {
|
|
91
|
+
latestNotAllowedReason = [attributeName, "attribute on", tagName, "tag is not allowed"];
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
if (typeof nameTester !== "string" && !nameTester.test(attributeName)) {
|
|
95
|
+
latestNotAllowedReason = [attributeName, "attribute on", tagName, "tag is not allowed"];
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
if (valTesters === void 0) return true;
|
|
99
|
+
if (valTesters.includes("*")) return true;
|
|
100
|
+
return valTesters.some((valTester) => {
|
|
101
|
+
if (typeof valTester === "string" && attributeValue === valTester) return true;
|
|
102
|
+
if (typeof valTester !== "string" && valTester.test(attributeValue)) return true;
|
|
103
|
+
latestNotAllowedReason = [attributeValue, "value for", attributeName, "attribute on", tagName, "tag is not allowed"];
|
|
104
|
+
return false;
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
if (!isInAllowed) {
|
|
108
|
+
if (verbose === true) console.warn(...latestNotAllowedReason);
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
return true;
|
|
112
|
+
});
|
|
113
|
+
returnedAttributes.forEach(({ name, value }) => {
|
|
114
|
+
returnedElement.setAttribute(name, value);
|
|
115
|
+
});
|
|
116
|
+
const sanitizedChildNodes = Array.from(childNodes).map((node) => {
|
|
117
|
+
if (node.nodeType === Node.ELEMENT_NODE) return sanitizeElement(node, { ...options, depth: depth - 1 });
|
|
118
|
+
else if (node.nodeType === Node.TEXT_NODE) return node;
|
|
119
|
+
else if (options.keepComments === true && node.nodeType === Node.COMMENT_NODE) return node;
|
|
120
|
+
return null;
|
|
121
|
+
}).filter((elt) => elt !== null);
|
|
122
|
+
returnedElement.replaceChildren(...sanitizedChildNodes);
|
|
123
|
+
return returnedElement;
|
|
124
|
+
}
|
|
125
|
+
Sanitize2.sanitizeElement = sanitizeElement;
|
|
126
|
+
})(Sanitize || (Sanitize = {}));
|
|
127
|
+
|
|
128
|
+
export {
|
|
129
|
+
Sanitize
|
|
130
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/agnostic/strings/normalize-indent/index.ts
|
|
2
|
+
function normalizeIndent(input, indentLevel = 0) {
|
|
3
|
+
const indent = " ".repeat(indentLevel);
|
|
4
|
+
const lines = input.split("\n");
|
|
5
|
+
const noIndentLines = lines.map((line) => line.replace(/^\s*/igm, ""));
|
|
6
|
+
const pipeReplacedLines = noIndentLines.map((line) => {
|
|
7
|
+
const nbPipeCharsOnLineStart = line.match(/^\|+/igm)?.[0].length ?? 0;
|
|
8
|
+
const noPipeLine = line.slice(nbPipeCharsOnLineStart);
|
|
9
|
+
const replacedPipes = " ".repeat(nbPipeCharsOnLineStart);
|
|
10
|
+
return replacedPipes + noPipeLine;
|
|
11
|
+
});
|
|
12
|
+
const normalizedLines = pipeReplacedLines.map((line) => indent + line);
|
|
13
|
+
return normalizedLines.join("\n");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
normalizeIndent
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/agnostic/optim/memoize/index.ts
|
|
2
|
+
function memoize(toMemoizeFunc) {
|
|
3
|
+
let cachedArgs = void 0;
|
|
4
|
+
let cachedResult = void 0;
|
|
5
|
+
return function memoized(...args) {
|
|
6
|
+
const allArgsAreInCache = cachedArgs !== void 0 && args.every((arg, argPos) => cachedArgs[argPos] === arg);
|
|
7
|
+
const allCachedAreInArgs = cachedArgs !== void 0 && cachedArgs.every((arg, argPos) => args[argPos] === arg);
|
|
8
|
+
const returnCache = allArgsAreInCache && allCachedAreInArgs;
|
|
9
|
+
if (returnCache) return cachedResult;
|
|
10
|
+
const result = toMemoizeFunc(...args);
|
|
11
|
+
cachedResult = result;
|
|
12
|
+
return result;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
memoize
|
|
18
|
+
};
|