@carlsebastian/jsu 1.0.34
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/LICENSE +201 -0
- package/package.json +58 -0
- package/src/global.js +7 -0
- package/src/types/api/api.d.ts +147 -0
- package/src/types/api/element.d.ts +55 -0
- package/src/types/custom/custom.d.ts +8 -0
- package/src/types/custom/error/builder/error.builder.d.ts +78 -0
- package/src/types/custom/error/constructor/error.base.d.ts +4 -0
- package/src/types/custom/error/constructor/error.custom.d.ts +34 -0
- package/src/types/custom/error/constructor/error.meta.d.ts +18 -0
- package/src/types/custom/error/error.d.ts +5 -0
- package/src/types/custom/utils/custom.utils.d.ts +42 -0
- package/src/types/custom/utils/generator/generator.d.ts +92 -0
- package/src/types/dom/attr/attr.class.d.ts +81 -0
- package/src/types/dom/attr/attr.id.d.ts +23 -0
- package/src/types/dom/attr/attr.style.d.ts +32 -0
- package/src/types/dom/dom.d.ts +8 -0
- package/src/types/dom/element/create/element.create.d.ts +67 -0
- package/src/types/dom/element/getElementBy/dom.getElementBy.d.ts +71 -0
- package/src/types/dom/element/tag-verifier/verifier.d.ts +16 -0
- package/src/types/global.d.ts +13 -0
- package/src/types/guards/data-types/data-types.d.ts +5 -0
- package/src/types/guards/formats/formats.d.ts +5 -0
- package/src/types/guards/guards.d.ts +8 -0
- package/src/types/primitives/obj/obj.accessor.d.ts +5 -0
- package/src/types/primitives/obj/obj.iterator.d.ts +5 -0
- package/src/types/primitives/primitives.d.ts +8 -0
- package/src/types/primitives/str/str.d.ts +26 -0
- package/src/types/storage/local/storage.local.d.ts +86 -0
- package/src/types/storage/session/storage.session.d.ts +86 -0
- package/src/types/storage/storage.d.ts +8 -0
- package/src/utils/custom/custom.js +20 -0
- package/src/utils/custom/error/builder/error.builder.js +181 -0
- package/src/utils/custom/error/constructor/error.base.js +71 -0
- package/src/utils/custom/error/constructor/error.custom.js +107 -0
- package/src/utils/custom/error/error.js +23 -0
- package/src/utils/custom/utils/custom.utils.js +150 -0
- package/src/utils/custom/utils/generator/generator.js +222 -0
- package/src/utils/dom/attr/attr.class.js +186 -0
- package/src/utils/dom/attr/attr.id.js +64 -0
- package/src/utils/dom/attr/attr.style.js +128 -0
- package/src/utils/dom/dom.js +29 -0
- package/src/utils/dom/element/create/element.create.js +312 -0
- package/src/utils/dom/element/getElementBy/dom.getElementBy.js +171 -0
- package/src/utils/dom/element/query/dom.query.js +75 -0
- package/src/utils/dom/element/tag-verifier/verifier.js +60 -0
- package/src/utils/dom/lifecycle/mount.js +48 -0
- package/src/utils/dom/lifecycle/unmount.js +43 -0
- package/src/utils/guards/data-types/data-types.js +201 -0
- package/src/utils/guards/formats/formats.js +274 -0
- package/src/utils/guards/guards.js +21 -0
- package/src/utils/primitives/obj/obj.accessor.js +242 -0
- package/src/utils/primitives/obj/obj.iterator.js +148 -0
- package/src/utils/primitives/primitives.js +23 -0
- package/src/utils/primitives/str/str.js +52 -0
- package/src/utils/storage/local/storage.local.js +236 -0
- package/src/utils/storage/session/storage.session.js +236 -0
- package/src/utils/storage/storage.js +59 -0
- package/src/utils/variables.js +78 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import Emit from '../../custom/error/builder/error.builder.js';
|
|
2
|
+
import { IsChildNode, IsPropertyAt } from '../../guards/data-types/data-types.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Unmounts the given `childNode` to its `parentNode`.
|
|
6
|
+
*
|
|
7
|
+
* ***Reference***:
|
|
8
|
+
* `remove()`
|
|
9
|
+
*
|
|
10
|
+
* @overload
|
|
11
|
+
* @param { ChildNode } childNode - The `childNode` to unmount at its `parentNode`.
|
|
12
|
+
* @returns { void }
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Unmounts the given `childNode` collection to their `parentNode`.
|
|
16
|
+
*
|
|
17
|
+
* ***Reference***:
|
|
18
|
+
* `remove()`
|
|
19
|
+
*
|
|
20
|
+
* @overload
|
|
21
|
+
* @param { ...ChildNode[] } childNodes - The `childNode` collection to unmount to their respective `parentNode`.
|
|
22
|
+
* @return { void }
|
|
23
|
+
*/
|
|
24
|
+
export default function Unmount(...childNodes) {
|
|
25
|
+
const Method = "Unmount", ICtr = childNodes.length, PCN = ICtr > 1 ? "childNodes" : "childNode";
|
|
26
|
+
|
|
27
|
+
if (childNodes.length === 0) {
|
|
28
|
+
console.warn(`${Method}(): Expects at least 1 or more 'childNode' to remove. (Exited)`);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
for (const Node of childNodes) {
|
|
33
|
+
if (!IsChildNode(Node))
|
|
34
|
+
Emit._ArgumentError(Method, PCN, Node, "ChildNode");
|
|
35
|
+
|
|
36
|
+
if (!IsPropertyAt(Node, "remove")) {
|
|
37
|
+
console.warn(`${Method}(@${PCN}${ICtr > 1 ? `[${Node}]` : `: ${Node}`}: NOT_SUPPORTED_METHOD): A given child node does not support the 'remove()' method! (${ICtr > 1 ? "Skipped" : "Exited"})`);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Node.remove();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates whether if the specified argument is `null` or `undefined`.
|
|
3
|
+
*
|
|
4
|
+
* @template T
|
|
5
|
+
* @param { T } arg - The argument to validate.
|
|
6
|
+
* @returns { arg is Extract<T, null | undefined> }
|
|
7
|
+
*/
|
|
8
|
+
export function IsNullOrUndefined(arg) {
|
|
9
|
+
return arg === null || arg === undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Validates whether if the specified argument is a `string`.
|
|
14
|
+
*
|
|
15
|
+
* @param { any } arg - The argument to validate.
|
|
16
|
+
* @returns { arg is string }
|
|
17
|
+
*/
|
|
18
|
+
export function IsStr(arg) {
|
|
19
|
+
return typeof arg === "string" || arg?.constructor === String;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Validates whether if the specified argument is an `array`.
|
|
24
|
+
*
|
|
25
|
+
* @template T
|
|
26
|
+
* @param { T } arg - The argument to validate.
|
|
27
|
+
* @returns { arg is Array<T> }
|
|
28
|
+
*/
|
|
29
|
+
export function IsArr(arg) {
|
|
30
|
+
return typeof arg === "object" && Array.isArray(arg);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Validates whether if the specified argument is a `function`.
|
|
35
|
+
*
|
|
36
|
+
* @param { any } arg - The argument to validate.
|
|
37
|
+
* @returns { arg is Function }
|
|
38
|
+
*/
|
|
39
|
+
export function IsFunc(arg) {
|
|
40
|
+
return typeof arg === "function" || arg?.constructor === Function;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Validates whether if the specified argument is a `map object`.
|
|
45
|
+
*
|
|
46
|
+
* @template T
|
|
47
|
+
* @param { T } arg - The argument to validate.
|
|
48
|
+
* @returns { arg is T extends Map<infer K, infer V> ? Map<K, V> : boolean }
|
|
49
|
+
*/
|
|
50
|
+
export function IsMapObj(arg) {
|
|
51
|
+
return arg?.constructor === Map || arg instanceof Map;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Validates whether if the specified argument is a `set object`.
|
|
56
|
+
*
|
|
57
|
+
* @template T
|
|
58
|
+
* @param { T } arg - The argument to validate.
|
|
59
|
+
* @returns { arg is Set<T> }
|
|
60
|
+
*/
|
|
61
|
+
export function IsSetObj(arg) {
|
|
62
|
+
return arg?.constructor === Set || arg instanceof Set;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Validates whether if the specified argument is a `plain object`.
|
|
67
|
+
*
|
|
68
|
+
* @template T
|
|
69
|
+
* @param { T } arg - The argument to validate.
|
|
70
|
+
* @returns { arg is T extends { [p: string]: infer V } ? Record<string, V> : boolean }
|
|
71
|
+
*/
|
|
72
|
+
export function IsPlainObj(arg) {
|
|
73
|
+
return typeof arg === "object" && !(IsArr(arg) || IsNullOrUndefined(arg) || IsMapObj(arg) || IsSetObj(arg));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Validates whether if the specified argument is a `boolean`.
|
|
78
|
+
*
|
|
79
|
+
* @param { any } arg - The argument to validate.
|
|
80
|
+
* @returns { arg is boolean }
|
|
81
|
+
*/
|
|
82
|
+
export function IsBool(arg) {
|
|
83
|
+
return typeof arg === "boolean" || arg?.constructor === Boolean;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Validates whether if the specified argument is a `number`.
|
|
88
|
+
*
|
|
89
|
+
* @param { any } arg - The argument to validate.
|
|
90
|
+
* @returns { arg is number }
|
|
91
|
+
*/
|
|
92
|
+
export function IsNum(arg) {
|
|
93
|
+
return (typeof arg === "number" || arg?.constructor === Number) && !Number.isNaN(arg);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Validates whether if the specified argument is a `Node`.
|
|
98
|
+
*
|
|
99
|
+
* @param { any } arg - The argument to validate.
|
|
100
|
+
* @returns { arg is Node }
|
|
101
|
+
*/
|
|
102
|
+
export function IsNode(arg) {
|
|
103
|
+
return arg?.constructor === Node;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Validates whether if the specified argument is a `ParentNode`.
|
|
108
|
+
*
|
|
109
|
+
* @param { any } arg - The argument to validate.
|
|
110
|
+
* @returns { arg is ParentNode }
|
|
111
|
+
*/
|
|
112
|
+
export function IsParentNode(arg) {
|
|
113
|
+
if (arg === null || arg === undefined)
|
|
114
|
+
return false;
|
|
115
|
+
|
|
116
|
+
const IsQueryAble = [
|
|
117
|
+
"getElementsByClassName", "getElementsByTagName", "getElementsByTagNameNS"
|
|
118
|
+
].every(prop => typeof arg[prop] === "function");
|
|
119
|
+
|
|
120
|
+
return "children" in arg && "firstElementChild" in arg && "lastElementChild" in arg && IsQueryAble;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Validates whether if the specified argument is a `ChildNode`.
|
|
125
|
+
*
|
|
126
|
+
* @param { any } arg - The argument to validate.
|
|
127
|
+
* @returns { arg is ChildNode }
|
|
128
|
+
*/
|
|
129
|
+
export function IsChildNode(arg) {
|
|
130
|
+
if (IsNullOrUndefined(arg))
|
|
131
|
+
return false;
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
typeof arg.after === "function" && typeof arg.before === "function" &&
|
|
135
|
+
typeof arg.remove === "function" && typeof arg.replaceWith === "function"
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Validates whether if the specified argument is an `Element` or instance of it.
|
|
141
|
+
*
|
|
142
|
+
* @param { any } arg - The argument to validate.
|
|
143
|
+
* @returns { arg is Element }
|
|
144
|
+
*/
|
|
145
|
+
export function IsElement(arg) {
|
|
146
|
+
return arg?.constructor === Element || arg instanceof Element;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Validates whether if the specified argument is an `HTMLElement` or instance of it.
|
|
151
|
+
*
|
|
152
|
+
* @param { any } arg - The argument to validate.
|
|
153
|
+
* @returns { arg is HTMLElement }
|
|
154
|
+
*/
|
|
155
|
+
export function IsHTMLElement(arg) {
|
|
156
|
+
return arg?.constructor === HTMLElement || arg instanceof HTMLElement;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Validates whether if the specified argument is an `HTMLUnknownElement` or instance of it.
|
|
161
|
+
*
|
|
162
|
+
* @param { any } arg - The argument to validate.
|
|
163
|
+
* @returns { arg is HTMLUnknownElement }
|
|
164
|
+
*/
|
|
165
|
+
export function IsUnknownElement(arg) {
|
|
166
|
+
return arg?.constructor === HTMLUnknownElement || arg instanceof HTMLUnknownElement;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Validates whether if the specified argument is `Iterator`.
|
|
171
|
+
*
|
|
172
|
+
* @param { any } arg - The argument to validate.
|
|
173
|
+
* @returns { arg is Iterator }
|
|
174
|
+
*/
|
|
175
|
+
export function IsIterator(arg) {
|
|
176
|
+
return arg?.constructor === Iterator || arg instanceof Iterator;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Validates whether if the specified argument is `RegExp`.
|
|
181
|
+
*
|
|
182
|
+
* @param { any } arg - The argument to validate.
|
|
183
|
+
* @returns { arg is RegExp }
|
|
184
|
+
*/
|
|
185
|
+
export function IsRegExp(arg) {
|
|
186
|
+
return arg?.constructor === RegExp || arg instanceof RegExp;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Validates whether if the specified argument supported the specified property.
|
|
191
|
+
*
|
|
192
|
+
* @param { any } arg - The argument to validate.
|
|
193
|
+
* @param { string } property - The property to check.
|
|
194
|
+
* @returns { boolean } The validation state result.
|
|
195
|
+
*/
|
|
196
|
+
export function IsPropertyAt(arg, property) {
|
|
197
|
+
if (IsNullOrUndefined(arg) || !IsStr(property) || property.trim().length === 0)
|
|
198
|
+
return false;
|
|
199
|
+
|
|
200
|
+
return Object.hasOwn(arg, property) || property in arg;
|
|
201
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { HTMLElementTags } from '../../variables.js';
|
|
2
|
+
import { IsArr, IsFunc, IsMapObj, IsNullOrUndefined, IsNum, IsPlainObj, IsSetObj, IsStr } from '../data-types/data-types.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Validates whether if the specified ***function*** argument is ***anonymous***.
|
|
6
|
+
*
|
|
7
|
+
* @param { Function } func - The function to validate.
|
|
8
|
+
* @returns { boolean }
|
|
9
|
+
*/
|
|
10
|
+
export function IsFuncAnonymous(func) {
|
|
11
|
+
return IsFunc(func) && !func.toString().startsWith("function") && !func.toString().includes("=>");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Validates whether if the specified ***function*** argument is ***asynchronous***.
|
|
16
|
+
*
|
|
17
|
+
* @param { Function } func - The function to validate.
|
|
18
|
+
* @returns { boolean }
|
|
19
|
+
*/
|
|
20
|
+
export function IsFuncAsynchronous(func) {
|
|
21
|
+
return IsFunc(func) && !IsNullOrUndefined(func?.constructor?.name) && func.constructor.name === "AsyncFunction";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Validates whether if the specified ***string*** argument includes lowercase characters.
|
|
26
|
+
*
|
|
27
|
+
* @param { string } str - The string to validate.
|
|
28
|
+
* @returns { boolean }
|
|
29
|
+
*/
|
|
30
|
+
export function HasLowerCase(str) {
|
|
31
|
+
return IsStr(str) && /[a-z]/.test(str);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Validates whether if the specified ***string*** argument starts with lowercase character.
|
|
36
|
+
*
|
|
37
|
+
* @param { string } str - The string to validate.
|
|
38
|
+
* @returns { boolean }
|
|
39
|
+
*/
|
|
40
|
+
export function IsStartsWithLowerCase(str) {
|
|
41
|
+
return IsStr(str) && /^[a-z]/.test(str);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Validates whether if the specified ***string*** argument ends with lowercase character.
|
|
46
|
+
*
|
|
47
|
+
* @param { string } str - The string to validate.
|
|
48
|
+
* @returns { boolean }
|
|
49
|
+
*/
|
|
50
|
+
export function IsEndsWithLowerCase(str) {
|
|
51
|
+
return IsStr(str) && /[a-z]$/.test(str);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Validates whether if the specified ***string*** argument includes uppercase characters.
|
|
56
|
+
*
|
|
57
|
+
* @param { string } str - The string to validate.
|
|
58
|
+
* @returns { boolean }
|
|
59
|
+
*/
|
|
60
|
+
export function HasUpperCase(str) {
|
|
61
|
+
return IsStr(str) && /[A-Z]/.test(str);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Validates whether if the specified ***string*** argument starts with uppercase character.
|
|
66
|
+
*
|
|
67
|
+
* @param { string } str - The string to validate.
|
|
68
|
+
* @returns { boolean }
|
|
69
|
+
*/
|
|
70
|
+
export function IsStartsWithUpperCase(str) {
|
|
71
|
+
return IsStr(str) && /^[A-Z]/.test(str);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Validates whether if the specified ***string*** argument ends with uppercase character.
|
|
76
|
+
*
|
|
77
|
+
* @param { string } str - The string to validate.
|
|
78
|
+
* @returns { boolean }
|
|
79
|
+
*/
|
|
80
|
+
export function IsEndsWithUpperCase(str) {
|
|
81
|
+
return IsStr(str) && /[A-Z]$/.test(str);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Validates whether if the specified ***string*** argument includes numbers.
|
|
86
|
+
*
|
|
87
|
+
* @param { string } str - The string to validate.
|
|
88
|
+
* @returns { boolean }
|
|
89
|
+
*/
|
|
90
|
+
export function HasNumbers(str) {
|
|
91
|
+
return IsStr(str) && /\d/.test(str);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Validates whether if the specified ***string*** argument starts with number.
|
|
96
|
+
*
|
|
97
|
+
* @param { string } str - The string to validate.
|
|
98
|
+
* @returns { boolean }
|
|
99
|
+
*/
|
|
100
|
+
export function IsStartsWithNumber(str) {
|
|
101
|
+
return IsStr(str) && /^\d/.test(str);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Validates whether if the specified ***string*** argument ends with number.
|
|
106
|
+
*
|
|
107
|
+
* @param { string } str - The string to validate.
|
|
108
|
+
* @returns { boolean }
|
|
109
|
+
*/
|
|
110
|
+
export function IsEndsWithNumber(str) {
|
|
111
|
+
return IsStr(str) && /\d$/.test(str);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Validates whether if the specified ***string*** argument includes specified characters.
|
|
116
|
+
*
|
|
117
|
+
* @param { string } str - The string to validate.
|
|
118
|
+
* @returns { boolean }
|
|
119
|
+
*/
|
|
120
|
+
export function HasSpecialCharacters(str) {
|
|
121
|
+
return IsStr(str) && /[^a-zA-Z\d]/.test(str);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Validates whether if the specified ***string*** argument starts with special character.
|
|
126
|
+
*
|
|
127
|
+
* @param { string } str - The string to validate.
|
|
128
|
+
* @returns { boolean }
|
|
129
|
+
*/
|
|
130
|
+
export function IsStartsWithSpecialCharacter(str) {
|
|
131
|
+
return IsStr(str) && /^[^a-zA-Z\d]/.test(str);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Validates whether if the specified ***string*** argument ends with special character.
|
|
136
|
+
*
|
|
137
|
+
* @param { string } str - The string to validate.
|
|
138
|
+
* @returns { boolean }
|
|
139
|
+
*/
|
|
140
|
+
export function IsEndsWithSpecialCharacter(str) {
|
|
141
|
+
return IsStr(str) && /[^a-zA-Z\d]$/.test(str);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Validates whether if the specified ***string*** argument includes ASCII characters.
|
|
146
|
+
*
|
|
147
|
+
* @param { string } str - The string to validate.
|
|
148
|
+
* @returns { boolean }
|
|
149
|
+
*/
|
|
150
|
+
export function HasASCII(str) {
|
|
151
|
+
return IsStr(str) && /[^\x00-\x7F]/.test(str);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Validates whether if the specified ***string*** argument starts with ASCII character.
|
|
156
|
+
*
|
|
157
|
+
* @param { string } str - The string to validate.
|
|
158
|
+
* @returns { boolean }
|
|
159
|
+
*/
|
|
160
|
+
export function IsStartsWithASCII(str) {
|
|
161
|
+
return IsStr(str) && /^[^\x00-\x7F]/.test(str);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Validates whether if the specified ***string*** argument ends with ASCII character.
|
|
166
|
+
*
|
|
167
|
+
* @param { string } str - The string to validate.
|
|
168
|
+
* @returns { boolean }
|
|
169
|
+
*/
|
|
170
|
+
export function IsEndsWithASCII(str) {
|
|
171
|
+
return IsStr(str) && /[^\x00-\x7F]$/.test(str);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Validates whether if the specified ***string*** argument is empty.
|
|
176
|
+
*
|
|
177
|
+
* @param { string } str - The string to validate.
|
|
178
|
+
* @returns { boolean }
|
|
179
|
+
*/
|
|
180
|
+
export function IsStrEmpty(str) {
|
|
181
|
+
return IsStr(str) && str.trim().length <= 0;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Validates whether if the specified ***array*** argument is empty.
|
|
186
|
+
*
|
|
187
|
+
* @template T
|
|
188
|
+
* @param { Array<T> } arr - The array to validate.
|
|
189
|
+
* @returns { arr extends Array<never> ? true : false }
|
|
190
|
+
*/
|
|
191
|
+
export function IsArrEmpty(arr) {
|
|
192
|
+
return IsArr(arr) && arr.length <= 0;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Validates whether if the specified ***plain object*** is empty.
|
|
197
|
+
*
|
|
198
|
+
* @param { Record<string, unknown> } obj - The plain object to validate.
|
|
199
|
+
* @returns { boolean }
|
|
200
|
+
*/
|
|
201
|
+
export function IsPlainObjEmpty(obj) {
|
|
202
|
+
return IsPlainObj(obj) && Object.entries(obj).length <= 0;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Validates whether if the specified ***map object*** is empty.
|
|
207
|
+
*
|
|
208
|
+
* @param { Map<unknown, unknown> } mObj - The map object to validate.
|
|
209
|
+
* @returns { boolean }
|
|
210
|
+
*/
|
|
211
|
+
export function IsMapObjEmpty(mObj) {
|
|
212
|
+
return IsMapObj(mObj) && mObj.size <= 0;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Validates whether if the specified ***set object*** is empty.
|
|
217
|
+
*
|
|
218
|
+
* @param { Set<unknown> } sObj - The set object to validate.
|
|
219
|
+
* @returns { boolean }
|
|
220
|
+
*/
|
|
221
|
+
export function IsSetObjEmpty(sObj) {
|
|
222
|
+
return IsSetObj(sObj) && sObj.size <= 0;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Validates whether if the specified `object` has the specified `property` id.
|
|
227
|
+
*
|
|
228
|
+
* @overload
|
|
229
|
+
* @param {{ [prop: string]: unknown }} obj - The object to check the property.
|
|
230
|
+
* @param { string } propertyId - The property id to check.
|
|
231
|
+
* @returns { boolean }
|
|
232
|
+
*/
|
|
233
|
+
/**
|
|
234
|
+
* Validates whether if the specified `map object` has the specified `property` id.
|
|
235
|
+
*
|
|
236
|
+
* @template T
|
|
237
|
+
* @overload
|
|
238
|
+
* @param { T } obj - The map object to check the property.
|
|
239
|
+
* @param { string } propertyId - The property id to check.
|
|
240
|
+
* @returns { boolean }
|
|
241
|
+
*/
|
|
242
|
+
export function HasProperty(obj = {}, propertyId) {
|
|
243
|
+
if (IsPlainObj(obj)) {
|
|
244
|
+
if (!IsStr(propertyId) || !IsStrEmpty(propertyId))
|
|
245
|
+
return false;
|
|
246
|
+
|
|
247
|
+
return Object.hasOwn(obj, propertyId);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (IsMapObj(obj))
|
|
251
|
+
return obj.has(propertyId);
|
|
252
|
+
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Validates whether if the specified `Array` or `Set` of elements includes the specified search `element`.
|
|
258
|
+
*
|
|
259
|
+
* @param { Array<unknown> | Set<unknown> } obj - The `Array` or `Set` of elements.
|
|
260
|
+
* @param { any } searchElement - The element to search.
|
|
261
|
+
* @param { number } [atPos] - A optional parameter to start looking at collection of elements. (Default: 0)
|
|
262
|
+
* @returns { boolean }
|
|
263
|
+
*/
|
|
264
|
+
export function HasValue(obj, searchElement, atPos = 0) {
|
|
265
|
+
const Pos = atPos < 0 ? Math.abs(atPos) : atPos;
|
|
266
|
+
|
|
267
|
+
if (IsArr(obj))
|
|
268
|
+
return obj.includes(searchElement, Pos);
|
|
269
|
+
|
|
270
|
+
if (IsSetObj(obj))
|
|
271
|
+
return [...obj.values()].includes(searchElement, Pos);
|
|
272
|
+
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DefineProperty, Global } from '../custom/utils/custom.utils.js';
|
|
2
|
+
import * as T from "./data-types/data-types.js";
|
|
3
|
+
import * as F from "./formats/formats.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Contains validations methods for types such ah ***string***, ***null***,
|
|
7
|
+
* ***function*** and many more!
|
|
8
|
+
*/
|
|
9
|
+
export default function Guards() {
|
|
10
|
+
const GuardsAPI = {};
|
|
11
|
+
|
|
12
|
+
for (const Method of [...Object.values(T), ...Object.values(F)]) {
|
|
13
|
+
const Key = Method.name;
|
|
14
|
+
if (!T.IsNullOrUndefined(Key) && !F.IsStrEmpty(Key) && !T.IsPropertyAt(GuardsAPI, Key))
|
|
15
|
+
DefineProperty(GuardsAPI, Key, Method, "med");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
Global("Guards", GuardsAPI, "soft");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
Guards();
|