@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.
Files changed (59) hide show
  1. package/LICENSE +201 -0
  2. package/package.json +58 -0
  3. package/src/global.js +7 -0
  4. package/src/types/api/api.d.ts +147 -0
  5. package/src/types/api/element.d.ts +55 -0
  6. package/src/types/custom/custom.d.ts +8 -0
  7. package/src/types/custom/error/builder/error.builder.d.ts +78 -0
  8. package/src/types/custom/error/constructor/error.base.d.ts +4 -0
  9. package/src/types/custom/error/constructor/error.custom.d.ts +34 -0
  10. package/src/types/custom/error/constructor/error.meta.d.ts +18 -0
  11. package/src/types/custom/error/error.d.ts +5 -0
  12. package/src/types/custom/utils/custom.utils.d.ts +42 -0
  13. package/src/types/custom/utils/generator/generator.d.ts +92 -0
  14. package/src/types/dom/attr/attr.class.d.ts +81 -0
  15. package/src/types/dom/attr/attr.id.d.ts +23 -0
  16. package/src/types/dom/attr/attr.style.d.ts +32 -0
  17. package/src/types/dom/dom.d.ts +8 -0
  18. package/src/types/dom/element/create/element.create.d.ts +67 -0
  19. package/src/types/dom/element/getElementBy/dom.getElementBy.d.ts +71 -0
  20. package/src/types/dom/element/tag-verifier/verifier.d.ts +16 -0
  21. package/src/types/global.d.ts +13 -0
  22. package/src/types/guards/data-types/data-types.d.ts +5 -0
  23. package/src/types/guards/formats/formats.d.ts +5 -0
  24. package/src/types/guards/guards.d.ts +8 -0
  25. package/src/types/primitives/obj/obj.accessor.d.ts +5 -0
  26. package/src/types/primitives/obj/obj.iterator.d.ts +5 -0
  27. package/src/types/primitives/primitives.d.ts +8 -0
  28. package/src/types/primitives/str/str.d.ts +26 -0
  29. package/src/types/storage/local/storage.local.d.ts +86 -0
  30. package/src/types/storage/session/storage.session.d.ts +86 -0
  31. package/src/types/storage/storage.d.ts +8 -0
  32. package/src/utils/custom/custom.js +20 -0
  33. package/src/utils/custom/error/builder/error.builder.js +181 -0
  34. package/src/utils/custom/error/constructor/error.base.js +71 -0
  35. package/src/utils/custom/error/constructor/error.custom.js +107 -0
  36. package/src/utils/custom/error/error.js +23 -0
  37. package/src/utils/custom/utils/custom.utils.js +150 -0
  38. package/src/utils/custom/utils/generator/generator.js +222 -0
  39. package/src/utils/dom/attr/attr.class.js +186 -0
  40. package/src/utils/dom/attr/attr.id.js +64 -0
  41. package/src/utils/dom/attr/attr.style.js +128 -0
  42. package/src/utils/dom/dom.js +29 -0
  43. package/src/utils/dom/element/create/element.create.js +312 -0
  44. package/src/utils/dom/element/getElementBy/dom.getElementBy.js +171 -0
  45. package/src/utils/dom/element/query/dom.query.js +75 -0
  46. package/src/utils/dom/element/tag-verifier/verifier.js +60 -0
  47. package/src/utils/dom/lifecycle/mount.js +48 -0
  48. package/src/utils/dom/lifecycle/unmount.js +43 -0
  49. package/src/utils/guards/data-types/data-types.js +201 -0
  50. package/src/utils/guards/formats/formats.js +274 -0
  51. package/src/utils/guards/guards.js +21 -0
  52. package/src/utils/primitives/obj/obj.accessor.js +242 -0
  53. package/src/utils/primitives/obj/obj.iterator.js +148 -0
  54. package/src/utils/primitives/primitives.js +23 -0
  55. package/src/utils/primitives/str/str.js +52 -0
  56. package/src/utils/storage/local/storage.local.js +236 -0
  57. package/src/utils/storage/session/storage.session.js +236 -0
  58. package/src/utils/storage/storage.js +59 -0
  59. package/src/utils/variables.js +78 -0
@@ -0,0 +1,20 @@
1
+ import { IsNullOrUndefined, IsPropertyAt } from '../guards/data-types/data-types.js';
2
+ import { IsStrEmpty } from '../guards/formats/formats.js';
3
+ import * as CustomUtils from "./utils/custom.utils.js";
4
+ import Generator from './utils/generator/generator.js';
5
+
6
+ /**
7
+ * Attach a collection of customized `@modules` and/or `@utilities` to `globalThis`.
8
+ */
9
+ export default function Custom() {
10
+ const CustomAPI = {};
11
+
12
+ for (const Method of [...Object.values(CustomUtils), Generator]) {
13
+ const Key = CustomUtils.NameOf(Method);
14
+ if (!IsNullOrUndefined(Key) && !IsStrEmpty(Key) && !IsPropertyAt(CustomAPI, Key) && !(Key === "(ANONYMOUS)"))
15
+ CustomUtils.DefineProperty(CustomAPI, Key, Method, "med");
16
+ }
17
+
18
+ CustomUtils.Global("Custom", CustomAPI, "soft");
19
+ }
20
+ Custom();
@@ -0,0 +1,181 @@
1
+ import * as _ from "../constructor/error.custom.js";
2
+
3
+ /* Meta Builder */
4
+ /**
5
+ * @param { string } message
6
+ * @param { string } c_message
7
+ * @param { string } emitter_id
8
+ * @param { string } argument_id
9
+ * @param { Record<string, any> } otherArgument
10
+ * @param { string } [guide]
11
+ */
12
+ const BuildMeta = (message, c_message, emitter_id, argument_id, otherArgument, guide) => {
13
+ /** @type { MetaBaseObject<{}> } */
14
+ const Meta = {
15
+ Message: message,
16
+ Context: {
17
+ Message: c_message,
18
+ Emitter: emitter_id
19
+ },
20
+ Args: {
21
+ Id: argument_id
22
+ },
23
+ Guide: guide
24
+ }
25
+
26
+ if ((typeof otherArgument === "object" && !Array.isArray(otherArgument) &&
27
+ !(otherArgument === null || otherArgument === undefined) &&
28
+ !(otherArgument instanceof Map || otherArgument instanceof Set)) &&
29
+ Object.values(otherArgument).length > 0)
30
+ Object.assign(Meta.Args, otherArgument);
31
+
32
+ return Meta;
33
+ }
34
+
35
+ /**
36
+ * Contains a `@custom` or `@enhance` collection version of `error` builder.
37
+ *
38
+ * Note:
39
+ * - The contents of available error builder(s) in this object are fixed, only the specified or
40
+ * required value are changing.
41
+ */
42
+ const Emit = {
43
+ /**
44
+ * Name of this object.
45
+ */
46
+ name: "Emit",
47
+
48
+ /**
49
+ * Builds and emit the contents of `@ArgumentError`.
50
+ *
51
+ * @param { string } emitter_id - The id of object that throws this error.
52
+ * @param { string } argument_id - The id of object's argument (either an object or parameter) that triggered or cause the error.
53
+ * @param { Array<string> } [expected_arguments] - The expected argument(s) that should be received by the argument.
54
+ */
55
+ _ArgumentError(emitter_id, argument_id, received_argument, ...expected_argument) {
56
+ throw new _.ArgumentError(BuildMeta(
57
+ `An argument error has occurred at ${emitter_id}()! ${emitter_id} expects a '${expected_argument.join(" | ")}' not '${received_argument}'.`,
58
+ `${emitter_id}(@${argument_id}: INVALID_ARGUMENT) {...}`,
59
+ emitter_id, argument_id,
60
+ { ReceivedArgument: received_argument, ExpectedArgument: expected_argument },
61
+ `Ensure to provide the expected argument(s) from this '${argument_id}' argument.`
62
+ ));
63
+ },
64
+
65
+ /**
66
+ * Builds and emit the contents of `@IndexOutOfBoundsError`.
67
+ *
68
+ * @param { string } emitter_id - The id of object that throws this error.
69
+ * @param { string } argument_id - The id of object's argument (either an object or parameter) that triggered or cause the error.
70
+ * @param { number } [index] - The index that the argument received that is out-of-bounds. (Undefined: -1)
71
+ * @param { number } [maximum_bound] - The maximum bound index of the argument object value that an index can be. (Undefined: -1)
72
+ */
73
+ _IndexOutOfBoundsError(emitter_id, argument_id, index = -1, maximum_bound = -1) {
74
+ throw new _.IndexOutOfBoundsError(BuildMeta(
75
+ `A out-of-bounds index has been received at ${emitter_id}()!`,
76
+ `${emitter_id}(@${argument_id}[${index}]: OUT_OF_BOUNDS) {...}`,
77
+ emitter_id, argument_id, { Index: index, MaxBound: maximum_bound },
78
+ `Ensure to provide an index that is within the bounds of this ${argument_id} argument.`
79
+ ));
80
+ },
81
+
82
+ /**
83
+ * Builds an emit the contents of `@InvalidPropertyError`.
84
+ *
85
+ * @param { string } emitter_id - The id of object that throws this error.
86
+ * @param { string } argument_id - The id of object's argument (either an object or parameter) that triggered or cause the error.
87
+ * @param { string } property_id - The invalid property that the argument received.
88
+ */
89
+ _InvalidPropertyError(emitter_id, argument_id, property_id) {
90
+ throw new _.InvalidPropertyError(BuildMeta(
91
+ `An invalid property is found at ${emitter_id}()!`,
92
+ `${emitter_id}(@${argument_id}[${property_id}]: INVALID_PROPERTY) {...}`,
93
+ emitter_id, argument_id, { PropertyId: property_id },
94
+ `Ensure to provide a valid or available property (provided by its intellisense) from this '${argument_id}' argument object at ${emitter_id}.`
95
+ ));
96
+ },
97
+
98
+ /**
99
+ * Builds and emit the contents of `@MissingParameterError`.
100
+ *
101
+ * @param { string } emitter_id - The id of object that throws this error.
102
+ * @param { string } argument_id - The id of object's argument (either an object or parameter) that triggered or cause the error.
103
+ * @param { any } [argument_value] - The current value of the argument.
104
+ */
105
+ _MissingParameterError(emitter_id, argument_id, argument_value) {
106
+ throw new _.MissingParameterError(BuildMeta(
107
+ `A missing parameter is found at ${emitter_id}!`,
108
+ `${emitter_id}(@${argument_id}: MISSING) {...}`,
109
+ emitter_id, argument_id, { Value: argument_value },
110
+ `Ensure to provide or assign a value from this '${argument_id}' argument at ${emitter_id}.`
111
+ ));
112
+ },
113
+
114
+ /**
115
+ * Builds and emit the contents of `@MissingPropertyError`.
116
+ *
117
+ * @param { string } emitter_id - The id of object that throws this error.
118
+ * @param { string } argument_id - The id of object's argument (either an object or parameter) that triggered or cause the error.
119
+ * @param { string } property_id - The missing property that the argument received.
120
+ */
121
+ _MissingPropertyError(emitter_id, argument_id, property_id) {
122
+ throw new _.MissingPropertyError(BuildMeta(
123
+ `A missing property is found at ${emitter_id}()!`,
124
+ `${emitter_id}(@${argument_id}[${property_id}]: MISSING_PROPERTY) {...}`,
125
+ emitter_id, argument_id, { MissingPropertyId: property_id },
126
+ `Ensure to provide the property '${property_id}' and its dedicated value from this '${argument_id}' argument object at ${emitter_id}.`
127
+ ));
128
+ },
129
+
130
+ /**
131
+ * Builds and emit the contents of `@NoSuchElementTagError`.
132
+ *
133
+ * @param { string } emitter_id - The id of object that throws this error.
134
+ * @param { string } argument_id - The id of object's argument (either an object or parameter) that triggered or cause the error.
135
+ * @param { string } tag - The tag that is not known or exists.
136
+ * @param { "HTMLElement" | "SVGElement" | "MathMLElement" } tagOf - The instance/type of element
137
+ */
138
+ _NoSuchElementTagError(emitter_id, argument_id, tag, tagOf) {
139
+ tagOf = typeof tagOf == "string" && tagOf.trim().length > 0 ? tagOf : "NOT_PROVIDED";
140
+
141
+ throw new _.NoSuchElementTagError(BuildMeta(
142
+ `A non-qualified tag of ${tagOf} is found at ${emitter_id}()!`,
143
+ `${emitter_id}(@tag: ${tag} - UNKNOWN_TAG_OF_${tagOf.toUpperCase()}) {...}`,
144
+ emitter_id, argument_id, { Tag: tag, TagOf: tagOf },
145
+ `Ensure to only provide the valid tag of ${tagOf} at this @${argument_id} parameter.`
146
+ ));
147
+ },
148
+
149
+ /**
150
+ * Builds and emit the contents of `@NotSupportedError`.
151
+ *
152
+ * @param { string } emitter_id - The id of object that throws this error.
153
+ * @param { string } unsupported_id - The id of the unsupported object that is being accessed.
154
+ */
155
+ _NotSupportedError(emitter_id, unsupported_id) {
156
+ throw new _.NotSupportedError(BuildMeta(
157
+ `A not supported method or object is being accessed!`,
158
+ `${emitter_id}.${unsupported_id}() { NOT_SUPPORTED }`,
159
+ emitter_id, unsupported_id,
160
+ `Ensure to upgrade your browser environment or your Javascript version.`
161
+ ));
162
+ },
163
+
164
+ /**
165
+ * Builds and emit the contents of `@UnknownPropertyError`.
166
+ *
167
+ * @param { string } emitter_id - The id of object that throws this error.
168
+ * @param { string } argument_id - The id of object's argument (either an object or parameter) that triggered or cause the error.
169
+ * @param { string } property_id - The unknown property id that is trying to be accessed.
170
+ */
171
+ _UnknownPropertyError(emitter_id, argument_id, property_id) {
172
+ throw new _.UnknownPropertyError(BuildMeta(
173
+ `Cannot access a unknown or non-existing property at ${emitter_id}()!`,
174
+ `${emitter_id}(@${argument_id}: { ${property_id}: UNKNOWN_OR_NOT_FOUND }) {...}`,
175
+ emitter_id, argument_id, { PropertyId: property_id },
176
+ `Ensure to only access a existing key-pair or property at this '${argument_id}' argument object at ${emitter_id}.`
177
+ ));
178
+ }
179
+ }
180
+
181
+ export default Emit;
@@ -0,0 +1,71 @@
1
+ import { MissingParameterError } from './error.custom.js';
2
+
3
+ /* -- Default Values -- */
4
+ const Base = (id) => `_NO_${typeof id === "string" ? id.toUpperCase() : String(id).toUpperCase()}_PROVIDED_`;
5
+ const Default = {
6
+ Message: Base("message"),
7
+ Context: Base("context"),
8
+ Args: Base("args"),
9
+ Guide: Base("guide")
10
+ }
11
+
12
+ /* -- Meta Data Property Validation -- */
13
+
14
+ /**
15
+ * @param { string | Record<string, unknown> | Array<unknown> } metaValue
16
+ * @param { any } defaultValue
17
+ */
18
+ const ValidateMetaProperty = (metaValue, defaultValue) => {
19
+ if (metaValue === null || metaValue === undefined)
20
+ return defaultValue;
21
+
22
+ if (typeof metaValue === "string" && metaValue.trim().length <= 0)
23
+ return defaultValue;
24
+
25
+ if (typeof metaValue === "object" && ((Array.isArray(metaValue) && metaValue.length <= 0) || Object.values(metaValue).length <= 0))
26
+ return defaultValue;
27
+
28
+ return metaValue;
29
+ }
30
+
31
+ /**
32
+ * A centralized custom error class for custom and/or modified error classes.
33
+ * @template {Record<string, any>} OtherArgs
34
+ */
35
+ export default class CustomError extends Error {
36
+ Args = { Id: undefined };
37
+ Context = {
38
+ Message: undefined,
39
+ Emitter: undefined
40
+ };
41
+ Guide = "";
42
+ Message = "";
43
+ Name = "CustomError";
44
+ TimeStamp = new Date();
45
+ /**
46
+ * @param { MetaBaseObject<OtherArgs> } Meta
47
+ */
48
+ constructor(Meta) {
49
+ if (Meta.Message === null || Meta.Message === undefined || typeof Meta.Message === "string" && Meta.Message.trim().length === 0)
50
+ throw new MissingParameterError({
51
+ Message: `A message must be provided for the error!`,
52
+ Context: {
53
+ Message: `CustomError.constructor(Meta: { Message: undefined } [REQUIRED]) {...}`,
54
+ Emitter: "CustomError.constructor"
55
+ },
56
+ Args: {
57
+ Id: "Meta",
58
+ Value: Meta
59
+ },
60
+ Guide: "Ensure to provide the 'Message' property at 'Meta' object!"
61
+ });
62
+
63
+ super(Meta.Message);
64
+ this.Name = ValidateMetaProperty(Meta.Name, this.constructor.name);
65
+ this.Message = ValidateMetaProperty(Meta.Message, Default.Message);
66
+ this.Context = ValidateMetaProperty(Meta.Context, Default.Context);
67
+ this.Args = ValidateMetaProperty(Meta.Args, Default.Args);
68
+ this.Guide = ValidateMetaProperty(Meta.Guide, Default.Guide);
69
+ this.TimeStamp = new Date();
70
+ }
71
+ }
@@ -0,0 +1,107 @@
1
+ import CustomError from './error.base.js';
2
+
3
+ /**
4
+ * A custom error class for invalid or unknown arguments.
5
+ * @class Argument
6
+ * @extends { CustomError<ArgumentErrorMeta> }
7
+ */
8
+ export class ArgumentError extends CustomError {
9
+ /**
10
+ * @param { ArgumentErrorMeta } meta
11
+ */
12
+ constructor(meta) {
13
+ super(meta);
14
+ }
15
+ }
16
+
17
+ /**
18
+ * A custom error class for invalid key-pair object.
19
+ *
20
+ * @extends { CustomError<InvalidPropertyErrorMeta> }
21
+ */
22
+ export class InvalidPropertyError extends CustomError {
23
+ /**
24
+ * @param { InvalidPropertyErrorMeta } meta
25
+ */
26
+ constructor(meta) {
27
+ super(meta);
28
+ }
29
+ }
30
+
31
+ /**
32
+ * A custom error class for out-of-bounds index accessor at object(s).
33
+ * @extends { CustomError<IndexOutOfBoundsErrorMeta> }
34
+ */
35
+ export class IndexOutOfBoundsError extends CustomError {
36
+ /**
37
+ * @param { IndexOutOfBoundsErrorMeta } meta
38
+ */
39
+ constructor(meta) {
40
+ super(meta);
41
+ }
42
+ }
43
+
44
+ /**
45
+ * A custom error class for missing parameter value.
46
+ * @extends { CustomError<MissingParameterErrorMeta> }
47
+ */
48
+ export class MissingParameterError extends CustomError {
49
+ /**
50
+ * @param { MissingParameterErrorMeta } meta
51
+ */
52
+ constructor(meta) {
53
+ super(meta);
54
+ }
55
+ }
56
+
57
+ /**
58
+ * A custom error class for missing key-pair object.
59
+ * @extends { CustomError<MissingPropertyErrorMeta> }
60
+ */
61
+ export class MissingPropertyError extends CustomError {
62
+ /**
63
+ * @param { MissingPropertyErrorMeta } meta
64
+ */
65
+ constructor(meta) {
66
+ super(meta);
67
+ }
68
+ }
69
+
70
+ /**
71
+ * A custom error class for not supported method.
72
+ * @extends { CustomError<NotSupportedErrorMeta> }
73
+ */
74
+ export class NotSupportedError extends CustomError {
75
+ /**
76
+ * @param { NotSupportedErrorMeta } meta
77
+ */
78
+ constructor(meta) {
79
+ super(meta);
80
+ }
81
+ }
82
+
83
+ /**
84
+ * A custom error class for unknown key-pair object.
85
+ * @extends { CustomError<UnknownPropertyErrorMeta> }
86
+ */
87
+ export class UnknownPropertyError extends CustomError {
88
+ /**
89
+ * @param { UnknownPropertyErrorMeta } meta
90
+ */
91
+ constructor(meta) {
92
+ super(meta);
93
+ }
94
+ }
95
+
96
+ /**
97
+ * A custom error class for unknown element tag.
98
+ * @extends { CustomError<NoSuchElementTagErrorMeta> }
99
+ */
100
+ export class NoSuchElementTagError extends CustomError {
101
+ /**
102
+ * @param { NoSuchElementTagErrorMeta } meta
103
+ */
104
+ constructor(meta) {
105
+ super(meta);
106
+ }
107
+ }
@@ -0,0 +1,23 @@
1
+ import * as CustomErrorClasses from "./constructor/error.custom.js";
2
+ import Emit from './builder/error.builder.js';
3
+ import { DefineProperty, Global, NameOf } from '../utils/custom.utils.js';
4
+ import { IsNullOrUndefined, IsPropertyAt, IsStr } from '../../guards/data-types/data-types.js';
5
+ import { IsStrEmpty } from '../../guards/formats/formats.js';
6
+
7
+ /**
8
+ * Returns a customized collection of `@error_class_modules` and `@error_class_builder_modules`.
9
+ */
10
+ function ERROR() {
11
+ const ErrorAPI = {};
12
+ const Constructors = { name: "Constructors", ...CustomErrorClasses };
13
+
14
+ for (const Method of [Constructors, Emit]) {
15
+ const Key = NameOf(Method);
16
+ if (!IsNullOrUndefined(Key) && !IsStrEmpty(Key) && !IsPropertyAt(ErrorAPI, Key) && !(Key === "(ANONYMOUS)"))
17
+ DefineProperty(ErrorAPI, NameOf(Method), Method, "med")
18
+ }
19
+
20
+ Global("ERROR", ErrorAPI, "soft");
21
+ }
22
+
23
+ ERROR();
@@ -0,0 +1,150 @@
1
+ import { IsNullOrUndefined, IsNum, IsPlainObj, IsStr } from '../../guards/data-types/data-types.js';
2
+ import { IsStrEmpty } from '../../guards/formats/formats.js';
3
+ import { EachOf, MapOf, SomeOf } from '../../primitives/obj/obj.iterator.js';
4
+ import Emit from '../error/builder/error.builder.js';
5
+
6
+ /**
7
+ * Retrieves the `name` property of the specified `function` or other `object` that supports this property.
8
+ *
9
+ * ***Notes***:
10
+ * - This is not case-sensitive for `name` property of the specified object as long as it has it.
11
+ *
12
+ * @param {{}} obj - The object to get the name from.
13
+ * @returns { string } Returns a '(ANONYMOUS)' value as default when the specified object does not have or support the `name` property.
14
+ */
15
+ export function NameOf(obj) {
16
+ let Key = null;
17
+
18
+ const Keys = Object.getOwnPropertyNames(obj).filter(K => K.length === 4);
19
+ for (const K of Keys) {
20
+ if (!(/^(N|n)/.test(K)))
21
+ continue;
22
+
23
+ if (!(/(A|a)/.test(K.charAt(1))))
24
+ continue;
25
+
26
+ if (!(/(M|m)/.test(K.charAt(2))))
27
+ continue;
28
+
29
+ if (!(/(E|e)/.test(K.charAt(K.length - 1))))
30
+ continue;
31
+
32
+ Key = K;
33
+ break;
34
+ }
35
+
36
+ return !IsStr(Key) ? "(Anonymous)" : obj[Key];
37
+ }
38
+
39
+ /**
40
+ * Returns the `constructor` or `type` of the specified `argument`.
41
+ *
42
+ * @param { any } arg - The argument to get its constructor or type.
43
+ * @returns { string | undefined } Returns a stringified `constructor` and/or `type` of the argument.
44
+ */
45
+ export function ConstructorOrTypeOf(arg) {
46
+ if (IsNullOrUndefined(arg))
47
+ return undefined;
48
+
49
+ return !IsNullOrUndefined(arg["constructor"]) ? arg["constructor"]["name"] : typeof arg;
50
+ }
51
+
52
+ /**
53
+ * Clamps the given `number` value to its specified `minimum` and `maximum` value that it can have.
54
+ *
55
+ * ***Notes***:
56
+ * - If the specified `value`, `min` and `max` are not a valid numeric value, it will return a `-1` value.
57
+ * - If the specified `min` value is greater than the specified `max` value, it will swap their values.
58
+ *
59
+ * @param { number } value - The current numeric value.
60
+ * @param { number } min - The minimum value that the current numeric value can have.
61
+ * @param { number } max - The maximum value that the current numeric value can have.
62
+ * @returns { number } The clamped numeric value.
63
+ */
64
+ export function Clamp(value, min = 0, max = 1) {
65
+ let RANGE = MapOf([value, min, max], VAL => parseInt(VAL));
66
+
67
+ // ❌ - Exits if value, minimum, and/or maximum are not valid numeric values.
68
+ if (SomeOf(RANGE, VAL => !IsNum(VAL)))
69
+ return -1;
70
+
71
+ if (RANGE[1] > RANGE[2] || RANGE[2] < RANGE[1]) {
72
+ const TEMP = RANGE[1];
73
+ RANGE[1] = RANGE[2];
74
+ RANGE[2] = TEMP;
75
+ }
76
+
77
+ return Math.min(Math.max(RANGE[0], RANGE[1]), RANGE[2]);
78
+ }
79
+
80
+ /**
81
+ * Define the given key-pair from the object.
82
+ *
83
+ * @param {{ [p: string]: any }} obj - The object to define the key-pair at.
84
+ * @param { string } key - The access key of key-pair item.
85
+ * @param { * } data - The data of key-pair item.
86
+ * @param { "hard" | "med" | "soft" | "def" } [opt] - Optional on how to store the key-pair dat at `globalThis` API. (writable, configurable, enumerable)
87
+ */
88
+ export function DefineProperty(obj = {}, key, data, opt = "def") {
89
+ const Method = "DefineProperty";
90
+
91
+ if (!IsPlainObj(obj))
92
+ obj = {};
93
+
94
+ if (!IsStr(key))
95
+ Emit._ArgumentError(Method, "key", key, "String");
96
+
97
+ if (IsStrEmpty(key)) {
98
+ console.warn(`${Method}(@key: \'\'): Expects a not-empty-string! (Exited)`);
99
+ return;
100
+ }
101
+
102
+ const CONF = {
103
+ Writable: true,
104
+ Configurable: true,
105
+ Enumerable: true
106
+ }
107
+ if (!IsStr(opt) || IsStrEmpty(opt) || !(opt === "def" || opt === "hard" || opt === "med" || opt === "soft"))
108
+ opt = "def";
109
+
110
+ if (opt === "hard")
111
+ CONF.Configurable = false, CONF.Enumerable = false, CONF.Writable = false;
112
+
113
+ if (opt === "med")
114
+ CONF.Configurable = false, CONF.Writable = false;
115
+
116
+ if (opt === "soft")
117
+ CONF.Writable = false;
118
+
119
+ if (opt === "def")
120
+ CONF.Configurable = true, CONF.Enumerable = true, CONF.Writable = true;
121
+
122
+ return Object.defineProperty(obj, key, {
123
+ value: data,
124
+ writable: CONF.Writable, configurable: CONF.Configurable, enumerable: CONF.Enumerable
125
+ });
126
+ }
127
+
128
+ /**
129
+ * Register the specified key-pair to `globalThis` API.
130
+ *
131
+ * @param { string } key - The access key of item to store at `globalThis` API.
132
+ * @param { * } data - The data of new item at `globalThis` API.
133
+ * @param { "hard" | "med" | "soft" | "def" } [opt] - Optional on how to store the key-pair dat at `globalThis` API. (writable, configurable, enumerable)
134
+ */
135
+ export function Global(key, data, opt = "def") {
136
+ const Method = "Global";
137
+
138
+ if (!IsStr(key))
139
+ Emit._ArgumentError(Method, "key", key, "String");
140
+
141
+ if (IsStrEmpty(key)) {
142
+ console.warn(`${Method}(@key: \'\'): Expects a non-empty-string! (Exited)`);
143
+ return;
144
+ }
145
+
146
+ if (!IsStr(opt) || IsStrEmpty(opt) || !(opt === "def" || opt === "hard" || opt === "med" || opt === "soft"))
147
+ opt = "def";
148
+
149
+ DefineProperty(globalThis, key, data, opt);
150
+ }