@xaendar/common 0.9.18 → 0.9.22
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.
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
(function(global, factory) {
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["@xaendar/common"] = {}));
|
|
3
|
+
})(this, function(exports) {
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
5
|
+
//#region ../packages/common/src/models/stack/stack.model.ts
|
|
6
|
+
/**
|
|
7
|
+
* A generic LIFO (Last In, First Out) stack data structure.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The type of elements held in the stack. Defaults to `unknown`.
|
|
10
|
+
*/
|
|
11
|
+
var Stack = class {
|
|
12
|
+
/**
|
|
13
|
+
* Internal array holding the stack elements, ordered from bottom to top.
|
|
14
|
+
*/
|
|
15
|
+
_elements = new Array();
|
|
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}`);
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region ../packages/common/src/utils/string/string.utils.ts
|
|
58
|
+
/**
|
|
59
|
+
* Returns a substring of `value`, copying the result via JSON
|
|
60
|
+
* serialization (to obtain a "clean" new string instance).
|
|
61
|
+
*
|
|
62
|
+
* This method ensure to resolve a note V8 Engine's problem
|
|
63
|
+
* about Sliced String and how they are hard to be garbage collectable
|
|
64
|
+
* and can lead to preserve a indefinite number of closure occupying
|
|
65
|
+
* unnecessary memory
|
|
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"
|
|
79
|
+
*/
|
|
80
|
+
function slice(value, start, end) {
|
|
81
|
+
return JSON.parse(JSON.stringify(value.slice(start, end)));
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region ../packages/common/src/costants/not-alllowed-tags.constants.ts
|
|
85
|
+
/**
|
|
86
|
+
* Tag names that are reserved by the HTML/SVG specifications and cannot be
|
|
87
|
+
* used as custom element names.
|
|
88
|
+
*
|
|
89
|
+
* @see https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
|
|
90
|
+
*/
|
|
91
|
+
var NOT_ALLOWED_TAGS = [
|
|
92
|
+
"annotation-xml",
|
|
93
|
+
"color-profile",
|
|
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
|
|
103
|
+
/**
|
|
104
|
+
* Asserts that a given tag name is valid for use as a custom element name.
|
|
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.
|
|
113
|
+
*
|
|
114
|
+
* @param tagName - The tag name to validate.
|
|
115
|
+
* @throws Will throw an error if the tag name is invalid.
|
|
116
|
+
*/
|
|
117
|
+
function isValidCustomElementName(tagName) {
|
|
118
|
+
if (!/^[a-z][a-z0-9._\-]*-[a-z0-9._\-]*$/.test(tagName)) {
|
|
119
|
+
console.error(`Tag <${tagName}> is not a valid custom element name. Custom element names must:
|
|
120
|
+
- contain a hyphen
|
|
121
|
+
- no spaces.
|
|
122
|
+
- start with a lowercase letter.
|
|
123
|
+
- not contain uppercase letters.
|
|
124
|
+
- not be a native HTML tag name.
|
|
125
|
+
- not contain the following chars: '@', '#', '$', '%', '&', '*', '!', '?', '/', '\\', '|', "'", '"', '<', '>', '='
|
|
126
|
+
`);
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
if (isReservedTagName(tagName)) {
|
|
130
|
+
console.error(`Tag <${tagName}> is a reserved tag name and cannot be used as a custom element name.
|
|
131
|
+
Reserved names are:
|
|
132
|
+
- ${NOT_ALLOWED_TAGS.join("\n- ")}`);
|
|
133
|
+
return false;
|
|
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);
|
|
148
|
+
}
|
|
149
|
+
//#endregion
|
|
150
|
+
exports.Stack = Stack;
|
|
151
|
+
exports.indent = indent;
|
|
152
|
+
exports.isValidCustomElementName = isValidCustomElementName;
|
|
153
|
+
exports.slice = slice;
|
|
154
|
+
});
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xaendar/common",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.22",
|
|
4
4
|
"description": "A library containing common classes and utilities",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
7
|
-
"main": "./dist/xaendar-common.
|
|
8
|
-
"module": "./dist/xaendar-common.
|
|
9
|
-
"types": "./dist/xaendar-common.
|
|
7
|
+
"main": "./dist/xaendar-common.js",
|
|
8
|
+
"module": "./dist/xaendar-common.js",
|
|
9
|
+
"types": "./dist/xaendar-common.d.ts",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
12
|
"import": {
|
|
13
|
-
"types": "./dist/xaendar-common.
|
|
14
|
-
"default": "./dist/xaendar-common.
|
|
13
|
+
"types": "./dist/xaendar-common.d.ts",
|
|
14
|
+
"default": "./dist/xaendar-common.js"
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -1,146 +0,0 @@
|
|
|
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 {
|
|
8
|
-
/**
|
|
9
|
-
* Internal array holding the stack elements, ordered from bottom to top.
|
|
10
|
-
*/
|
|
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
|
-
} });
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
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.
|
|
25
|
-
*/
|
|
26
|
-
get values() {
|
|
27
|
-
return [...this._elements];
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Removes and returns the top element of the stack.
|
|
31
|
-
*
|
|
32
|
-
* @returns The top element, or `undefined` if the stack is empty.
|
|
33
|
-
*/
|
|
34
|
-
pop() {
|
|
35
|
-
return this._elements.pop();
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Pushes an element onto the top of the stack.
|
|
39
|
-
*
|
|
40
|
-
* @param element - The element to push.
|
|
41
|
-
* @returns The new length of the stack.
|
|
42
|
-
*/
|
|
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:
|
|
116
|
-
- contain a hyphen
|
|
117
|
-
- no spaces.
|
|
118
|
-
- start with a lowercase letter.
|
|
119
|
-
- not contain uppercase letters.
|
|
120
|
-
- not be a native HTML tag name.
|
|
121
|
-
- not contain the following chars: '@', '#', '$', '%', '&', '*', '!', '?', '/', '\\', '|', "'", '"', '<', '>', '='
|
|
122
|
-
`);
|
|
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.
|
|
127
|
-
Reserved names are:
|
|
128
|
-
- ${NOT_ALLOWED_TAGS.join("\n- ")}`);
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
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 };
|
|
File without changes
|