@xaendar/common 0.5.3 → 0.5.5

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.
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Asserts that a given tag name is valid for use as a custom element name.
3
+ * A valid custom element name must:
4
+ * - contain a hyphen
5
+ * - no spaces.
6
+ * - start with a lowercase letter.
7
+ * - not contain uppercase letters.
8
+ * - not contain the following chars: '@', '#', '$', '%', '&', '*', '!', '?', '/', '\\', '|', "'", '"', '<', '>', '='
9
+ * - not be a native HTML tag name.
10
+ * - not be a reserved tag name.
11
+ * @param tagName The tag name to validate.
12
+ * @throws Will throw an error if the tag name is invalid.
13
+ */
14
+ export declare function assertIsValidElementName(tagName: string): boolean;
15
+
1
16
  /**
2
17
  * Indents each line of a code block by two spaces.
3
18
  * @param lines The lines of code to indent.
@@ -55,4 +55,66 @@ function indent(...lines) {
55
55
  return lines.map((line) => ` ${line}`);
56
56
  }
57
57
  //#endregion
58
- export { Stack, indent };
58
+ //#region ../packages/common/src/costants/not-alllowed-tags.constants.ts
59
+ /**
60
+ * List of strings not allowed as names for CustomElements
61
+ */
62
+ var NOT_ALLOWED_TAGS = [
63
+ "annotation-xml",
64
+ "color-profile",
65
+ "font-face",
66
+ "font-face-src",
67
+ "font-face-uri",
68
+ "font-face-format",
69
+ "font-face-name",
70
+ "missing-glyph"
71
+ ];
72
+ //#endregion
73
+ //#region ../packages/common/src/utils/tags/tags.utils.ts
74
+ /**
75
+ * Asserts that a given tag name is valid for use as a custom element name.
76
+ * A valid custom element name must:
77
+ * - contain a hyphen
78
+ * - no spaces.
79
+ * - start with a lowercase letter.
80
+ * - not contain uppercase letters.
81
+ * - not contain the following chars: '@', '#', '$', '%', '&', '*', '!', '?', '/', '\\', '|', "'", '"', '<', '>', '='
82
+ * - not be a native HTML tag name.
83
+ * - not be a reserved tag name.
84
+ * @param tagName The tag name to validate.
85
+ * @throws Will throw an error if the tag name is invalid.
86
+ */
87
+ function assertIsValidElementName(tagName) {
88
+ if (!/^[a-z][a-z0-9._\-]*-[a-z0-9._\-]*$/.test(tagName)) {
89
+ console.error(`Tag <${tagName}> is not a valid custom element name. Custom element names must:
90
+ - contain a hyphen
91
+ - no spaces.
92
+ - start with a lowercase letter.
93
+ - not contain uppercase letters.
94
+ - not to be a native HTML tag name.
95
+ - not contain the following chars: '@', '#', '$', '%', '&', '*', '!', '?', '/', '\\', '|', "'", '"', '<', '>', '='
96
+ `);
97
+ return false;
98
+ }
99
+ if (isReservedTagName(tagName)) {
100
+ console.error(`Tag <${tagName}> is a reserved tag name and cannot be used as a custom element name.
101
+ Reserved names are:
102
+ - ${NOT_ALLOWED_TAGS.join("\n- ")}`);
103
+ return false;
104
+ }
105
+ return true;
106
+ }
107
+ /**
108
+ * Checks if a tag name is reserved and cannot be used for a custom element.
109
+ *
110
+ * Reserved names include certain HTML, SVG, or other names that are forbidden by the specification.
111
+ * https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
112
+ *
113
+ * @param tagName - The tag name to check.
114
+ * @returns `true` if the tag name is reserved, `false` otherwise.
115
+ */
116
+ function isReservedTagName(tagName) {
117
+ return NOT_ALLOWED_TAGS.includes(tagName);
118
+ }
119
+ //#endregion
120
+ export { Stack, assertIsValidElementName, indent };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xaendar/common",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "A library containing common classes and utilities",
5
5
  "sideEffects": false,
6
6
  "type": "module",