@xaendar/common 0.9.22 → 0.9.24
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/dist/xaendar-common.js +124 -132
- package/package.json +1 -1
package/dist/xaendar-common.js
CHANGED
|
@@ -1,122 +1,118 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
//#region ../packages/common/src/models/stack/stack.model.ts
|
|
2
|
+
/**
|
|
3
|
+
* A generic LIFO (Last In, First Out) stack data structure.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of elements held in the stack. Defaults to `unknown`.
|
|
6
|
+
*/
|
|
7
|
+
var Stack = class {
|
|
6
8
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @template T - The type of elements held in the stack. Defaults to `unknown`.
|
|
9
|
+
* Internal array holding the stack elements, ordered from bottom to top.
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
constructor() {
|
|
17
|
-
return new Proxy(this, { get(target, prop) {
|
|
18
|
-
return isNaN(Number(prop)) ? target[prop] : target._elements[Number(prop)];
|
|
19
|
-
} });
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* The number of elements currently in the stack.
|
|
23
|
-
*/
|
|
24
|
-
get length() {
|
|
25
|
-
return this._elements.length;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* A shallow copy of the elements in the stack, ordered from bottom to top.
|
|
29
|
-
*/
|
|
30
|
-
get values() {
|
|
31
|
-
return [...this._elements];
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Removes and returns the top element of the stack.
|
|
35
|
-
*
|
|
36
|
-
* @returns The top element, or `undefined` if the stack is empty.
|
|
37
|
-
*/
|
|
38
|
-
pop() {
|
|
39
|
-
return this._elements.pop();
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Pushes an element onto the top of the stack.
|
|
43
|
-
*
|
|
44
|
-
* @param element - The element to push.
|
|
45
|
-
* @returns The new length of the stack.
|
|
46
|
-
*/
|
|
47
|
-
push(element) {
|
|
48
|
-
return this._elements.push(element);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
//#endregion
|
|
52
|
-
//#region ../packages/common/src/utils/indent/indent.utils.ts
|
|
53
|
-
function indent(lines) {
|
|
54
|
-
return typeof lines === "string" ? ` ${lines}` : lines.map((line) => ` ${line}`);
|
|
11
|
+
_elements = new Array();
|
|
12
|
+
constructor() {
|
|
13
|
+
return new Proxy(this, { get(target, prop) {
|
|
14
|
+
return isNaN(Number(prop)) ? target[prop] : target._elements[Number(prop)];
|
|
15
|
+
} });
|
|
55
16
|
}
|
|
56
|
-
//#endregion
|
|
57
|
-
//#region ../packages/common/src/utils/string/string.utils.ts
|
|
58
17
|
/**
|
|
59
|
-
*
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
*
|
|
66
|
-
* https://stackoverflow.com/questions/79478418/how-to-correctly-unref-a-v8-substring-sliced-string-from-its-source-string
|
|
67
|
-
*
|
|
68
|
-
* @param value - The source string to extract the substring from.
|
|
69
|
-
* @param start - The zero-based index at which to start extraction. If omitted, starts from the beginning of the string.
|
|
70
|
-
* If negative, it is treated as `value.length + start`.
|
|
71
|
-
* @param end - The zero-based index at which to end extraction (exclusive). If omitted, extraction goes to the end of the string.
|
|
72
|
-
* If negative, it is treated as `value.length + end`.
|
|
73
|
-
* @returns The substring extracted from `value` between `start` and `end`.
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* slice("Hello world", 0, 5); // "Hello"
|
|
77
|
-
* slice("Hello world", 6); // "world"
|
|
78
|
-
* slice("Hello world", -5); // "world"
|
|
18
|
+
* The number of elements currently in the stack.
|
|
19
|
+
*/
|
|
20
|
+
get length() {
|
|
21
|
+
return this._elements.length;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A shallow copy of the elements in the stack, ordered from bottom to top.
|
|
79
25
|
*/
|
|
80
|
-
|
|
81
|
-
return
|
|
26
|
+
get values() {
|
|
27
|
+
return [...this._elements];
|
|
82
28
|
}
|
|
83
|
-
//#endregion
|
|
84
|
-
//#region ../packages/common/src/costants/not-alllowed-tags.constants.ts
|
|
85
29
|
/**
|
|
86
|
-
*
|
|
87
|
-
* used as custom element names.
|
|
30
|
+
* Removes and returns the top element of the stack.
|
|
88
31
|
*
|
|
89
|
-
* @
|
|
32
|
+
* @returns The top element, or `undefined` if the stack is empty.
|
|
90
33
|
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
"font-face",
|
|
95
|
-
"font-face-src",
|
|
96
|
-
"font-face-uri",
|
|
97
|
-
"font-face-format",
|
|
98
|
-
"font-face-name",
|
|
99
|
-
"missing-glyph"
|
|
100
|
-
];
|
|
101
|
-
//#endregion
|
|
102
|
-
//#region ../packages/common/src/utils/tags/tags.utils.ts
|
|
34
|
+
pop() {
|
|
35
|
+
return this._elements.pop();
|
|
36
|
+
}
|
|
103
37
|
/**
|
|
104
|
-
*
|
|
105
|
-
* A valid custom element name must:
|
|
106
|
-
* - contain a hyphen
|
|
107
|
-
* - no spaces.
|
|
108
|
-
* - start with a lowercase letter.
|
|
109
|
-
* - not contain uppercase letters.
|
|
110
|
-
* - not contain the following chars: '@', '#', '$', '%', '&', '*', '!', '?', '/', '\\', '|', "'", '"', '<', '>', '='
|
|
111
|
-
* - not be a native HTML tag name.
|
|
112
|
-
* - not be a reserved tag name.
|
|
38
|
+
* Pushes an element onto the top of the stack.
|
|
113
39
|
*
|
|
114
|
-
* @param
|
|
115
|
-
* @
|
|
40
|
+
* @param element - The element to push.
|
|
41
|
+
* @returns The new length of the stack.
|
|
116
42
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
43
|
+
push(element) {
|
|
44
|
+
return this._elements.push(element);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region ../packages/common/src/utils/indent/indent.utils.ts
|
|
49
|
+
function indent(lines) {
|
|
50
|
+
return typeof lines === "string" ? ` ${lines}` : lines.map((line) => ` ${line}`);
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region ../packages/common/src/utils/string/string.utils.ts
|
|
54
|
+
/**
|
|
55
|
+
* Returns a substring of `value`, copying the result via JSON
|
|
56
|
+
* serialization (to obtain a "clean" new string instance).
|
|
57
|
+
*
|
|
58
|
+
* This method ensure to resolve a note V8 Engine's problem
|
|
59
|
+
* about Sliced String and how they are hard to be garbage collectable
|
|
60
|
+
* and can lead to preserve a indefinite number of closure occupying
|
|
61
|
+
* unnecessary memory
|
|
62
|
+
* https://stackoverflow.com/questions/79478418/how-to-correctly-unref-a-v8-substring-sliced-string-from-its-source-string
|
|
63
|
+
*
|
|
64
|
+
* @param value - The source string to extract the substring from.
|
|
65
|
+
* @param start - The zero-based index at which to start extraction. If omitted, starts from the beginning of the string.
|
|
66
|
+
* If negative, it is treated as `value.length + start`.
|
|
67
|
+
* @param end - The zero-based index at which to end extraction (exclusive). If omitted, extraction goes to the end of the string.
|
|
68
|
+
* If negative, it is treated as `value.length + end`.
|
|
69
|
+
* @returns The substring extracted from `value` between `start` and `end`.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* slice("Hello world", 0, 5); // "Hello"
|
|
73
|
+
* slice("Hello world", 6); // "world"
|
|
74
|
+
* slice("Hello world", -5); // "world"
|
|
75
|
+
*/
|
|
76
|
+
function slice(value, start, end) {
|
|
77
|
+
return JSON.parse(JSON.stringify(value.slice(start, end)));
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region ../packages/common/src/costants/not-alllowed-tags.constants.ts
|
|
81
|
+
/**
|
|
82
|
+
* Tag names that are reserved by the HTML/SVG specifications and cannot be
|
|
83
|
+
* used as custom element names.
|
|
84
|
+
*
|
|
85
|
+
* @see https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
|
|
86
|
+
*/
|
|
87
|
+
var NOT_ALLOWED_TAGS = [
|
|
88
|
+
"annotation-xml",
|
|
89
|
+
"color-profile",
|
|
90
|
+
"font-face",
|
|
91
|
+
"font-face-src",
|
|
92
|
+
"font-face-uri",
|
|
93
|
+
"font-face-format",
|
|
94
|
+
"font-face-name",
|
|
95
|
+
"missing-glyph"
|
|
96
|
+
];
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region ../packages/common/src/utils/tags/tags.utils.ts
|
|
99
|
+
/**
|
|
100
|
+
* Asserts that a given tag name is valid for use as a custom element name.
|
|
101
|
+
* A valid custom element name must:
|
|
102
|
+
* - contain a hyphen
|
|
103
|
+
* - no spaces.
|
|
104
|
+
* - start with a lowercase letter.
|
|
105
|
+
* - not contain uppercase letters.
|
|
106
|
+
* - not contain the following chars: '@', '#', '$', '%', '&', '*', '!', '?', '/', '\\', '|', "'", '"', '<', '>', '='
|
|
107
|
+
* - not be a native HTML tag name.
|
|
108
|
+
* - not be a reserved tag name.
|
|
109
|
+
*
|
|
110
|
+
* @param tagName - The tag name to validate.
|
|
111
|
+
* @throws Will throw an error if the tag name is invalid.
|
|
112
|
+
*/
|
|
113
|
+
function isValidCustomElementName(tagName) {
|
|
114
|
+
if (!/^[a-z][a-z0-9._\-]*-[a-z0-9._\-]*$/.test(tagName)) {
|
|
115
|
+
console.error(`Tag <${tagName}> is not a valid custom element name. Custom element names must:
|
|
120
116
|
- contain a hyphen
|
|
121
117
|
- no spaces.
|
|
122
118
|
- start with a lowercase letter.
|
|
@@ -124,31 +120,27 @@
|
|
|
124
120
|
- not be a native HTML tag name.
|
|
125
121
|
- not contain the following chars: '@', '#', '$', '%', '&', '*', '!', '?', '/', '\\', '|', "'", '"', '<', '>', '='
|
|
126
122
|
`);
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
if (isReservedTagName(tagName)) {
|
|
126
|
+
console.error(`Tag <${tagName}> is a reserved tag name and cannot be used as a custom element name.
|
|
131
127
|
Reserved names are:
|
|
132
128
|
- ${NOT_ALLOWED_TAGS.join("\n- ")}`);
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
return true;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Checks if a tag name is reserved and cannot be used for a custom element.
|
|
139
|
-
*
|
|
140
|
-
* Reserved names include certain HTML, SVG, or other names that are forbidden by the specification.
|
|
141
|
-
* https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
|
|
142
|
-
*
|
|
143
|
-
* @param tagName - The tag name to check.
|
|
144
|
-
* @returns `true` if the tag name is reserved, `false` otherwise.
|
|
145
|
-
*/
|
|
146
|
-
function isReservedTagName(tagName) {
|
|
147
|
-
return NOT_ALLOWED_TAGS.includes(tagName);
|
|
129
|
+
return false;
|
|
148
130
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Checks if a tag name is reserved and cannot be used for a custom element.
|
|
135
|
+
*
|
|
136
|
+
* Reserved names include certain HTML, SVG, or other names that are forbidden by the specification.
|
|
137
|
+
* https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
|
|
138
|
+
*
|
|
139
|
+
* @param tagName - The tag name to check.
|
|
140
|
+
* @returns `true` if the tag name is reserved, `false` otherwise.
|
|
141
|
+
*/
|
|
142
|
+
function isReservedTagName(tagName) {
|
|
143
|
+
return NOT_ALLOWED_TAGS.includes(tagName);
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
export { Stack, indent, isValidCustomElementName, slice };
|