@design-edito/tools 0.1.30 → 0.1.32

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.
Files changed (69) hide show
  1. package/agnostic/css/index.js +10 -10
  2. package/agnostic/html/get-node-ancestors/index.d.ts +1 -1
  3. package/agnostic/html/get-node-ancestors/index.js +1 -1
  4. package/agnostic/html/hyper-json/cast/index.js +2 -2
  5. package/agnostic/html/hyper-json/index.js +3 -3
  6. package/agnostic/html/hyper-json/transformers/append/index.js +2 -2
  7. package/agnostic/html/hyper-json/transformers/classList/index.js +2 -2
  8. package/agnostic/html/hyper-json/transformers/index.js +2 -2
  9. package/agnostic/html/hyper-json/transformers/join/index.js +2 -2
  10. package/agnostic/html/hyper-json/transformers/length/index.js +2 -2
  11. package/agnostic/html/hyper-json/transformers/print/index.js +2 -2
  12. package/agnostic/html/hyper-json/transformers/push/index.js +2 -2
  13. package/agnostic/html/hyper-json/transformers/querySelector/index.js +2 -2
  14. package/agnostic/html/hyper-json/transformers/ref/index.js +2 -2
  15. package/agnostic/html/hyper-json/transformers/replace/index.js +2 -2
  16. package/agnostic/html/hyper-json/transformers/split/index.js +2 -2
  17. package/agnostic/html/hyper-json/transformers/toArray/index.js +2 -2
  18. package/agnostic/html/hyper-json/transformers/toBoolean/index.js +2 -2
  19. package/agnostic/html/hyper-json/transformers/toElement/index.js +2 -2
  20. package/agnostic/html/hyper-json/transformers/toNodeList/index.js +2 -2
  21. package/agnostic/html/hyper-json/transformers/toNull/index.js +2 -2
  22. package/agnostic/html/hyper-json/transformers/toNumber/index.js +2 -2
  23. package/agnostic/html/hyper-json/transformers/toRecord/index.js +2 -2
  24. package/agnostic/html/hyper-json/transformers/toRef/index.js +2 -2
  25. package/agnostic/html/hyper-json/transformers/toString/index.js +2 -2
  26. package/agnostic/html/hyper-json/transformers/toText/index.js +2 -2
  27. package/agnostic/html/hyper-json/transformers/toTransformer/index.js +2 -2
  28. package/agnostic/html/hyper-json/transformers/transformSelected/index.js +2 -2
  29. package/agnostic/html/hyper-json/transformers/trim/index.js +2 -2
  30. package/agnostic/html/hyper-json/tree/index.js +2 -2
  31. package/agnostic/html/hyper-json/utils/index.js +2 -2
  32. package/agnostic/html/index.js +15 -15
  33. package/agnostic/html/sanitize/index.js +4 -4
  34. package/agnostic/html/selector-to-element/index.js +4 -4
  35. package/agnostic/html/string-to-nodes/index.js +5 -5
  36. package/agnostic/misc/cast/index.d.ts +1 -0
  37. package/agnostic/misc/cast/index.js +1 -1
  38. package/agnostic/misc/crossenv/index.js +2 -2
  39. package/agnostic/misc/index.js +18 -18
  40. package/agnostic/misc/logs/index.js +2 -2
  41. package/agnostic/misc/lorem-ipsum/index.js +6 -6
  42. package/agnostic/numbers/index.js +3 -3
  43. package/agnostic/numbers/interpolate/index.d.ts +1 -0
  44. package/agnostic/numbers/interpolate/index.js +3 -1
  45. package/agnostic/objects/flatten-getters/index.js +2 -2
  46. package/agnostic/objects/index.js +12 -12
  47. package/agnostic/optim/index.js +3 -3
  48. package/agnostic/strings/index.js +3 -3
  49. package/agnostic/time/index.js +3 -3
  50. package/chunks/chunk-3UQJFMBN.js +27 -0
  51. package/chunks/chunk-BJAYUP7M.js +13 -0
  52. package/chunks/chunk-BVCWBTHQ.js +35 -0
  53. package/chunks/chunk-C5753KUP.js +127 -0
  54. package/chunks/chunk-CAMYGA44.js +22 -0
  55. package/chunks/chunk-COLNKMBN.js +35 -0
  56. package/chunks/chunk-EX7FS6IR.js +28 -0
  57. package/chunks/chunk-FR5H2OCV.js +21 -0
  58. package/chunks/chunk-GPWFYPER.js +211 -0
  59. package/chunks/chunk-LUPVHC73.js +17 -0
  60. package/chunks/chunk-MCW3JX25.js +211 -0
  61. package/chunks/chunk-NFUY7SLX.js +211 -0
  62. package/chunks/chunk-NTBSGBV2.js +1108 -0
  63. package/chunks/chunk-SNJJII7A.js +65 -0
  64. package/chunks/chunk-UDY37VIJ.js +22 -0
  65. package/chunks/chunk-VFJYLXCI.js +23 -0
  66. package/chunks/chunk-VKURVIRV.js +28 -0
  67. package/chunks/chunk-WXXW6YLW.js +127 -0
  68. package/node/files/index.js +3 -3
  69. package/package.json +1 -1
@@ -0,0 +1,65 @@
1
+ import {
2
+ isFalsy
3
+ } from "./chunk-QXAJXTXV.js";
4
+
5
+ // src/agnostic/misc/cast/index.ts
6
+ var Cast;
7
+ ((Cast2) => {
8
+ function toBoolean(value) {
9
+ if (typeof value === "boolean") return value;
10
+ if (typeof value === "string") {
11
+ if (value.toLowerCase().trim() === "true") return true;
12
+ return false;
13
+ }
14
+ return !isFalsy(value);
15
+ }
16
+ Cast2.toBoolean = toBoolean;
17
+ function toNumber(value) {
18
+ if (typeof value === "number") return value;
19
+ if (typeof value === "string") return parseFloat(value);
20
+ return 0;
21
+ }
22
+ Cast2.toNumber = toNumber;
23
+ function toString(value) {
24
+ if (typeof value === "string") return value;
25
+ return String(value);
26
+ }
27
+ Cast2.toString = toString;
28
+ function toNull(_value) {
29
+ return null;
30
+ }
31
+ Cast2.toNull = toNull;
32
+ function toArray(value) {
33
+ if (Array.isArray(value)) return value;
34
+ if (typeof value === "object" && value !== null) return Object.entries(value).map((key, value2) => ({ key, value: value2 }));
35
+ return [value];
36
+ }
37
+ Cast2.toArray = toArray;
38
+ function toNumberArr(value) {
39
+ const arrValue = toArray(value);
40
+ return arrValue.map((val) => toNumber(val));
41
+ }
42
+ Cast2.toNumberArr = toNumberArr;
43
+ function toRecord(value) {
44
+ const record = {};
45
+ try {
46
+ Object.keys(value).forEach((key) => {
47
+ record[key] = value[key];
48
+ });
49
+ } catch (err) {
50
+ return record;
51
+ }
52
+ return record;
53
+ }
54
+ Cast2.toRecord = toRecord;
55
+ function toError(value) {
56
+ if (value instanceof Error) return value;
57
+ if (typeof value === "string") return new Error(value);
58
+ return new Error(toString(value));
59
+ }
60
+ Cast2.toError = toError;
61
+ })(Cast || (Cast = {}));
62
+
63
+ export {
64
+ Cast
65
+ };
@@ -0,0 +1,22 @@
1
+ import {
2
+ Crossenv
3
+ } from "./chunk-FR5H2OCV.js";
4
+ import {
5
+ Errors
6
+ } from "./chunk-2KT7AKRW.js";
7
+
8
+ // src/shared/errors/index.ts
9
+ var register = Errors.Register.from({
10
+ ["no-window-document-on-runtime" /* NO_DOCUMENT */]: {
11
+ message: `Runtime '${Crossenv.detectRuntime()}' does not provide a Document object, cannot complete.`,
12
+ detailsMaker: () => void 0
13
+ },
14
+ ["no-window-document-on-runtime-please-provide" /* NO_DOCUMENT_PLEASE_PROVIDE */]: {
15
+ message: `Please provide a Document object since none are found on runtime '${Crossenv.detectRuntime()}'`,
16
+ detailsMaker: (tips) => tips
17
+ }
18
+ });
19
+
20
+ export {
21
+ register
22
+ };
@@ -0,0 +1,23 @@
1
+ import {
2
+ Cast
3
+ } from "./chunk-SNJJII7A.js";
4
+
5
+ // src/agnostic/objects/flatten-getters/index.ts
6
+ function flattenGetters(obj) {
7
+ try {
8
+ const { entries, getOwnPropertyDescriptors } = Object;
9
+ const properties = Cast.toRecord(obj);
10
+ const getters = entries(getOwnPropertyDescriptors(obj)).filter(([_, desc]) => typeof desc.get === "function").map(([key]) => key);
11
+ const returned = { ...properties };
12
+ getters.forEach((getter) => {
13
+ returned[getter] = obj[getter];
14
+ });
15
+ return returned;
16
+ } catch (err) {
17
+ return {};
18
+ }
19
+ }
20
+
21
+ export {
22
+ flattenGetters
23
+ };
@@ -0,0 +1,28 @@
1
+ import {
2
+ Sanitize
3
+ } from "./chunk-C5753KUP.js";
4
+ import {
5
+ register
6
+ } from "./chunk-CAMYGA44.js";
7
+
8
+ // src/agnostic/html/string-to-nodes/index.ts
9
+ function stringToNodes(dirtyStr, options) {
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 sanitizeOptions = {
13
+ ...options?.sanitize,
14
+ documentObj: options?.sanitize?.documentObj ?? options?.documentObj
15
+ };
16
+ const str = options?.sanitize !== void 0 ? Sanitize.sanitize(dirtyStr, sanitizeOptions) : dirtyStr;
17
+ const wrapperDiv = actualDocument.createElement("div");
18
+ wrapperDiv.innerHTML = str;
19
+ const nodes = Array.from(wrapperDiv.childNodes).filter((node) => {
20
+ const allowedNodeTypes = [Node.ELEMENT_NODE, Node.TEXT_NODE];
21
+ return allowedNodeTypes.includes(node.nodeType);
22
+ });
23
+ return nodes;
24
+ }
25
+
26
+ export {
27
+ stringToNodes
28
+ };
@@ -0,0 +1,127 @@
1
+ import {
2
+ register
3
+ } from "./chunk-UDY37VIJ.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
+ };
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  readWrite
3
3
  } from "../../chunks/chunk-7DBNMU6N.js";
4
- import {
5
- isInDirectory
6
- } from "../../chunks/chunk-NRITRUZW.js";
7
4
  import {
8
5
  Subpaths
9
6
  } from "../../chunks/chunk-HGCG2J77.js";
7
+ import {
8
+ isInDirectory
9
+ } from "../../chunks/chunk-NRITRUZW.js";
10
10
  import "../../chunks/chunk-LQFKUNVQ.js";
11
11
 
12
12
  // src/node/files/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@design-edito/tools",
3
- "version": "0.1.30",
3
+ "version": "0.1.32",
4
4
  "description": "",
5
5
  "author": "Maxime Fabas",
6
6
  "license": "ISC",