xdbc 1.0.217 → 1.0.218

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 (89) hide show
  1. package/.gitattributes +8 -0
  2. package/.vscode/settings.json +3 -3
  3. package/.vscode/tasks.json +23 -23
  4. package/ASSESSMENT.md +249 -0
  5. package/README.md +131 -1
  6. package/__tests__/DBC/AE.test.ts +62 -62
  7. package/__tests__/DBC/ARRAY.test.ts +91 -91
  8. package/__tests__/DBC/DEFINED.test.ts +53 -53
  9. package/__tests__/DBC/DOM.test.ts +481 -0
  10. package/__tests__/DBC/Decorators.test.ts +367 -367
  11. package/__tests__/DBC/EQ.test.ts +13 -13
  12. package/__tests__/DBC/GREATER.test.ts +31 -31
  13. package/__tests__/DBC/HasAttribute.test.ts +60 -60
  14. package/__tests__/DBC/IF.test.ts +62 -62
  15. package/__tests__/DBC/INSTANCE.test.ts +13 -13
  16. package/__tests__/DBC/JSON.OP.test.ts +47 -47
  17. package/__tests__/DBC/JSON.Parse.test.ts +17 -17
  18. package/__tests__/DBC/OR.test.ts +14 -14
  19. package/__tests__/DBC/PLAIN_OBJECT.test.ts +109 -109
  20. package/__tests__/DBC/REGEX.test.ts +17 -17
  21. package/__tests__/DBC/TYPE.test.ts +13 -13
  22. package/__tests__/DBC/UNDEFINED.test.ts +45 -45
  23. package/__tests__/DBC/ZOD.test.ts +54 -54
  24. package/__tests__/DBC/onInfringement.test.ts +262 -0
  25. package/biome.json +40 -40
  26. package/dist/DBC/AE.js +172 -0
  27. package/dist/DBC/ARR/PLAIN_OBJECT.d.ts +0 -3
  28. package/dist/DBC/ARR/PLAIN_OBJECT.js +95 -0
  29. package/dist/DBC/ARRAY.d.ts +0 -3
  30. package/dist/DBC/ARRAY.js +90 -0
  31. package/dist/DBC/COMPARISON/GREATER.js +21 -0
  32. package/dist/DBC/COMPARISON/GREATER_OR_EQUAL.js +21 -0
  33. package/dist/DBC/COMPARISON/LESS.js +21 -0
  34. package/dist/DBC/COMPARISON/LESS_OR_EQUAL.js +21 -0
  35. package/dist/DBC/COMPARISON.js +98 -0
  36. package/dist/DBC/DEFINED.js +87 -0
  37. package/dist/DBC/DOM.d.ts +87 -0
  38. package/dist/DBC/DOM.js +223 -0
  39. package/dist/DBC/EQ/DIFFERENT.js +34 -0
  40. package/dist/DBC/EQ.js +101 -0
  41. package/dist/DBC/HasAttribute.js +101 -0
  42. package/dist/DBC/IF.js +96 -0
  43. package/dist/DBC/INSTANCE.js +122 -0
  44. package/dist/DBC/JSON.OP.js +120 -0
  45. package/dist/DBC/JSON.Parse.js +104 -0
  46. package/dist/DBC/OR.js +125 -0
  47. package/dist/DBC/REGEX.js +136 -0
  48. package/dist/DBC/TYPE.js +112 -0
  49. package/dist/DBC/UNDEFINED.js +87 -0
  50. package/dist/DBC/ZOD.js +99 -0
  51. package/dist/DBC.d.ts +18 -4
  52. package/dist/DBC.js +645 -0
  53. package/dist/Demo.d.ts +10 -0
  54. package/dist/Demo.js +713 -0
  55. package/dist/bundle.js +6140 -405
  56. package/dist/index.d.ts +22 -0
  57. package/dist/index.js +22 -0
  58. package/jest.config.js +32 -32
  59. package/package.json +71 -55
  60. package/src/DBC/AE.ts +269 -288
  61. package/src/DBC/ARR/PLAIN_OBJECT.ts +122 -133
  62. package/src/DBC/ARRAY.ts +117 -127
  63. package/src/DBC/COMPARISON/GREATER.ts +41 -46
  64. package/src/DBC/COMPARISON/GREATER_OR_EQUAL.ts +41 -45
  65. package/src/DBC/COMPARISON/LESS.ts +41 -45
  66. package/src/DBC/COMPARISON/LESS_OR_EQUAL.ts +41 -45
  67. package/src/DBC/COMPARISON.ts +149 -159
  68. package/src/DBC/DEFINED.ts +117 -122
  69. package/src/DBC/DOM.ts +291 -0
  70. package/src/DBC/EQ/DIFFERENT.ts +51 -57
  71. package/src/DBC/EQ.ts +154 -163
  72. package/src/DBC/HasAttribute.ts +149 -154
  73. package/src/DBC/IF.ts +173 -179
  74. package/src/DBC/INSTANCE.ts +168 -171
  75. package/src/DBC/JSON.OP.ts +178 -186
  76. package/src/DBC/JSON.Parse.ts +150 -157
  77. package/src/DBC/OR.ts +183 -187
  78. package/src/DBC/REGEX.ts +195 -196
  79. package/src/DBC/TYPE.ts +142 -149
  80. package/src/DBC/UNDEFINED.ts +115 -117
  81. package/src/DBC/ZOD.ts +130 -135
  82. package/src/DBC.ts +902 -904
  83. package/src/Demo.ts +537 -404
  84. package/src/index.ts +22 -0
  85. package/tsconfig.json +18 -18
  86. package/tsconfig.test.json +7 -7
  87. package/typedoc.json +16 -16
  88. package/webpack.config.js +27 -27
  89. package/Assessment.md +0 -507
package/src/DBC/EQ.ts CHANGED
@@ -1,163 +1,154 @@
1
- import { DBC } from "../DBC";
2
- /**
3
- * A {@link DBC } defining that two {@link object }s gotta be equal.
4
- *
5
- * @remarks
6
- * Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
7
- export class EQ extends DBC {
8
- // #region Condition checking.
9
- /**
10
- * Checks if the value **toCheck** is equal to the specified **equivalent**.
11
- *
12
- * @param toCheck The value that has to be equal to it's possible **equivalent** for this {@link DBC } to be fulfilled.
13
- * @param equivalent The {@link object } the one **toCheck** has to be equal to in order for this {@link DBC } to be
14
- * fulfilled.
15
- *
16
- * @returns TRUE if the value **toCheck** and the **equivalent** are equal to each other, otherwise FALSE. */
17
- public static checkAlgorithm(
18
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
19
- toCheck: any,
20
- equivalent: object,
21
- invert: boolean,
22
- ): boolean | string {
23
- if (!invert && equivalent !== toCheck) {
24
- return `Value has to be equal to "${equivalent}"`;
25
- }
26
-
27
- if (invert && equivalent === toCheck) {
28
- return `Value must not be equal to "${equivalent}"`;
29
- }
30
-
31
- return true;
32
- }
33
- /**
34
- * A parameter-decorator factory using the {@link EQ.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
35
- * by the tagged parameter.
36
- *
37
- * @param equivalent See {@link EQ.checkAlgorithm }.
38
- * @param path See {@link DBC.decPrecondition }.
39
- * @param dbc See {@link DBC.decPrecondition }.
40
- *
41
- * @returns See {@link DBC.decPrecondition }. */
42
- public static PRE(
43
- // biome-ignore lint/suspicious/noExplicitAny: To check for UNDEFINED and NULL.
44
- equivalent: any,
45
- invert = false,
46
- path: string | undefined = undefined,
47
- hint: string | undefined = undefined,
48
- dbc: string | undefined = undefined,
49
- ): (
50
- target: object,
51
- methodName: string | symbol | undefined,
52
- parameterIndex: number,
53
- ) => void {
54
- return DBC.createPRE(
55
- EQ.checkAlgorithm,
56
- [equivalent, invert],
57
- dbc,
58
- path,
59
- hint,
60
- );
61
- }
62
- /**
63
- * A method-decorator factory using the {@link EQ.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
64
- * by the tagged method's returnvalue.
65
- *
66
- * @param equivalent See {@link EQ.checkAlgorithm }.
67
- * @param path See {@link DBC.Postcondition }.
68
- * @param dbc See {@link DBC.decPostcondition }.
69
- *
70
- * @returns See {@link DBC.decPostcondition }. */
71
- public static POST(
72
- // biome-ignore lint/suspicious/noExplicitAny: To check for UNDEFINED and NULL.
73
- equivalent: any,
74
- invert = false,
75
- path: string | undefined = undefined,
76
- hint: string | undefined = undefined,
77
- dbc: string | undefined = undefined,
78
- ): (
79
- target: object,
80
- propertyKey: string,
81
- descriptor: PropertyDescriptor,
82
- ) => PropertyDescriptor {
83
- return DBC.createPOST(
84
- EQ.checkAlgorithm,
85
- [equivalent, invert],
86
- dbc,
87
- path,
88
- hint,
89
- );
90
- }
91
- /**
92
- * A field-decorator factory using the {@link EQ.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
93
- * by the tagged field.
94
- *
95
- * @param equivalent See {@link EQ.checkAlgorithm }.
96
- * @param path See {@link DBC.decInvariant }.
97
- * @param dbc See {@link DBC.decInvariant }.
98
- *
99
- * @returns See {@link DBC.decInvariant }. */
100
- public static INVARIANT(
101
- // biome-ignore lint/suspicious/noExplicitAny: To check for UNDEFINED and NULL.
102
- equivalent: any,
103
- invert = false,
104
- path: string | undefined = undefined,
105
- hint: string | undefined = undefined,
106
- dbc: string | undefined = undefined,
107
- ) {
108
- return DBC.createINVARIANT(EQ, [equivalent, invert], dbc, path, hint);
109
- }
110
- // #endregion Condition checking.
111
- // #region Referenced Condition checking.
112
- //
113
- // For usage in dynamic scenarios (like with AE-DBC).
114
- //
115
- /**
116
- * Invokes the {@link EQ.checkAlgorithm } passing the value **toCheck**, {@link EQ.equivalent } and {@link EQ.invert }.
117
- *
118
- * @param toCheck See {@link EQ.checkAlgorithm }.
119
- *
120
- * @returns See {@link EQ.checkAlgorithm}. */
121
- // biome-ignore lint/suspicious/noExplicitAny: Necessary to check against NULL & UNDEFINED.
122
- public check(toCheck: any) {
123
- return EQ.checkAlgorithm(toCheck, this.equivalent, this.invert);
124
- }
125
- /**
126
- * Invokes the {@link EQ.checkAlgorithm } passing the value **toCheck** and the specified **type** .
127
- *
128
- * @param toCheck See {@link EQ.checkAlgorithm }.
129
- *
130
- * @returns The **CANDIDATE** **toCheck** doesn't fulfill this {@link EQ }.
131
- *
132
- * @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link EQ }.*/
133
- public static tsCheck<CANDIDATE>(
134
- toCheck: CANDIDATE | undefined | null,
135
- equivalent: any,
136
- hint: string | undefined = undefined,
137
- id: string | undefined = undefined,
138
- dbc: string | undefined = undefined,
139
- ): CANDIDATE {
140
- const result = EQ.checkAlgorithm(toCheck, equivalent, false);
141
-
142
- if (result === true) {
143
- return toCheck as CANDIDATE;
144
- }
145
- DBC.reportTsCheckInfringement(
146
- `${id ? `(${id}) ` : ""}${result as string} ${hint ? `✨ ${hint} ✨` : ""}`,
147
- dbc,
148
- );
149
- return toCheck as CANDIDATE;
150
- }
151
- /**
152
- * Creates this {@link EQ } by setting the protected property {@link EQ.equivalent } used by {@link EQ.check }.
153
- *
154
- * @param equivalent See {@link EQ.check }. */
155
- public constructor(
156
- // biome-ignore lint/suspicious/noExplicitAny: To be able to match UNDEFINED and NULL.
157
- protected equivalent: any,
158
- protected invert = false,
159
- ) {
160
- super();
161
- }
162
- // #endregion Referenced Condition checking.
163
- }
1
+ import { DBC } from "../DBC";
2
+ /**
3
+ * A {@link DBC } defining that two {@link object }s gotta be equal.
4
+ *
5
+ * @remarks
6
+ * Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
7
+ export class EQ extends DBC {
8
+ // #region Condition checking.
9
+ /**
10
+ * Checks if the value **toCheck** is equal to the specified **equivalent**.
11
+ *
12
+ * @param toCheck The value that has to be equal to it's possible **equivalent** for this {@link DBC } to be fulfilled.
13
+ * @param equivalent The {@link object } the one **toCheck** has to be equal to in order for this {@link DBC } to be
14
+ * fulfilled.
15
+ *
16
+ * @returns TRUE if the value **toCheck** and the **equivalent** are equal to each other, otherwise FALSE. */
17
+ public static checkAlgorithm(
18
+ toCheck: any,
19
+ equivalent: object,
20
+ invert: boolean,
21
+ ): boolean | string {
22
+ if (!invert && equivalent !== toCheck) {
23
+ return `Value has to be equal to "${equivalent}"`;
24
+ }
25
+ if (invert && equivalent === toCheck) {
26
+ return `Value must not be equal to "${equivalent}"`;
27
+ }
28
+ return true;
29
+ }
30
+ /**
31
+ * A parameter-decorator factory using the {@link EQ.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
32
+ * by the tagged parameter.
33
+ *
34
+ * @param equivalent See {@link EQ.checkAlgorithm }.
35
+ * @param path See {@link DBC.decPrecondition }.
36
+ * @param dbc See {@link DBC.decPrecondition }.
37
+ *
38
+ * @returns See {@link DBC.decPrecondition }. */
39
+ public static PRE(
40
+ equivalent: any,
41
+ invert = false,
42
+ path: string | undefined = undefined,
43
+ hint: string | undefined = undefined,
44
+ dbc: string | undefined = undefined,
45
+ ): (
46
+ target: object,
47
+ methodName: string | symbol | undefined,
48
+ parameterIndex: number,
49
+ ) => void {
50
+ return DBC.createPRE(
51
+ EQ.checkAlgorithm,
52
+ [equivalent, invert],
53
+ dbc,
54
+ path,
55
+ hint,
56
+ );
57
+ }
58
+ /**
59
+ * A method-decorator factory using the {@link EQ.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
60
+ * by the tagged method's returnvalue.
61
+ *
62
+ * @param equivalent See {@link EQ.checkAlgorithm }.
63
+ * @param path See {@link DBC.Postcondition }.
64
+ * @param dbc See {@link DBC.decPostcondition }.
65
+ *
66
+ * @returns See {@link DBC.decPostcondition }. */
67
+ public static POST(
68
+ equivalent: any,
69
+ invert = false,
70
+ path: string | undefined = undefined,
71
+ hint: string | undefined = undefined,
72
+ dbc: string | undefined = undefined,
73
+ ): (
74
+ target: object,
75
+ propertyKey: string,
76
+ descriptor: PropertyDescriptor,
77
+ ) => PropertyDescriptor {
78
+ return DBC.createPOST(
79
+ EQ.checkAlgorithm,
80
+ [equivalent, invert],
81
+ dbc,
82
+ path,
83
+ hint,
84
+ );
85
+ }
86
+ /**
87
+ * A field-decorator factory using the {@link EQ.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
88
+ * by the tagged field.
89
+ *
90
+ * @param equivalent See {@link EQ.checkAlgorithm }.
91
+ * @param path See {@link DBC.decInvariant }.
92
+ * @param dbc See {@link DBC.decInvariant }.
93
+ *
94
+ * @returns See {@link DBC.decInvariant }. */
95
+ public static INVARIANT(
96
+ equivalent: any,
97
+ invert = false,
98
+ path: string | undefined = undefined,
99
+ hint: string | undefined = undefined,
100
+ dbc: string | undefined = undefined,
101
+ ) {
102
+ return DBC.createINVARIANT(EQ, [equivalent, invert], dbc, path, hint);
103
+ }
104
+ // #endregion Condition checking.
105
+ // #region Referenced Condition checking.
106
+ //
107
+ // For usage in dynamic scenarios (like with AE-DBC).
108
+ //
109
+ /**
110
+ * Invokes the {@link EQ.checkAlgorithm } passing the value **toCheck**, {@link EQ.equivalent } and {@link EQ.invert }.
111
+ *
112
+ * @param toCheck See {@link EQ.checkAlgorithm }.
113
+ *
114
+ * @returns See {@link EQ.checkAlgorithm}. */
115
+ public check(toCheck: any) {
116
+ return EQ.checkAlgorithm(toCheck, this.equivalent, this.invert);
117
+ }
118
+ /**
119
+ * Invokes the {@link EQ.checkAlgorithm } passing the value **toCheck** and the specified **type** .
120
+ *
121
+ * @param toCheck See {@link EQ.checkAlgorithm }.
122
+ *
123
+ * @returns The **CANDIDATE** **toCheck** doesn't fulfill this {@link EQ }.
124
+ *
125
+ * @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link EQ }.*/
126
+ public static tsCheck<CANDIDATE>(
127
+ toCheck: CANDIDATE | undefined | null,
128
+ equivalent: any,
129
+ hint: string | undefined = undefined,
130
+ id: string | undefined = undefined,
131
+ dbc: string | undefined = undefined,
132
+ ): CANDIDATE {
133
+ const result = EQ.checkAlgorithm(toCheck, equivalent, false);
134
+ if (result === true) {
135
+ return toCheck as CANDIDATE;
136
+ }
137
+ DBC.reportTsCheckInfringement(
138
+ `${id ? `(${id}) ` : ""}${result as string} ${hint ? `✨ ${hint} ✨` : ""}`,
139
+ dbc,
140
+ );
141
+ return toCheck as CANDIDATE;
142
+ }
143
+ /**
144
+ * Creates this {@link EQ } by setting the protected property {@link EQ.equivalent } used by {@link EQ.check }.
145
+ *
146
+ * @param equivalent See {@link EQ.check }. */
147
+ public constructor(
148
+ protected equivalent: any,
149
+ protected invert = false,
150
+ ) {
151
+ super();
152
+ }
153
+ // #endregion Referenced Condition checking.
154
+ }
@@ -1,154 +1,149 @@
1
- import { DBC } from "../DBC";
2
- /**
3
- * A {@link DBC } defining that a {@link HTMLElement } gotta have a certain attribute set.
4
- *
5
- * @remarks
6
- * Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
7
- export class HasAttribute extends DBC {
8
- // #region Condition checking.
9
- /**
10
- * Checks if the {@link HTMLElement } **toCheck** has the attribute **toCheckFor**.
11
- *
12
- * @param toCheckFor name of the attribute to check for whether it is set or not.
13
- *
14
- * @returns TRUE if the {@link HTMLElement } **toCheck** has set the attribute **toCheckFor**,
15
- * otherwise a proper errormessage. */
16
- public static checkAlgorithm(
17
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
18
- toCheck: any,
19
- toCheckFor: string,
20
- invert,
21
- ): boolean | string {
22
- if (!(toCheck instanceof HTMLElement)) {
23
- return `The object to check for whether it has the attribute "${toCheckFor}" is not a HTMLElement. It is of type "${typeof toCheck}".`;
24
- }
25
-
26
- if (!invert && !(toCheck as HTMLElement).hasAttribute(toCheckFor)) {
27
- return `Required Attribute "${toCheckFor}" is not set.`;
28
- }
29
-
30
- if (invert && (toCheck as HTMLElement).hasAttribute(toCheckFor)) {
31
- return `Forbidden Attribute "${toCheckFor}" is set.`;
32
- }
33
-
34
- return true;
35
- }
36
- /**
37
- * A parameter-decorator factory using the {@link HasAttribute.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
38
- * by the tagged parameter.
39
- *
40
- * @param toCheckFor See {@link HasAttribute.checkAlgorithm }.
41
- * @param path See {@link DBC.decPrecondition }.
42
- * @param dbc See {@link DBC.decPrecondition }.
43
- *
44
- * @returns See {@link DBC.decPrecondition }. */
45
- public static PRE(
46
- toCheckFor: string,
47
- invert = false,
48
- path: string | undefined = undefined,
49
- dbc = "WaXCode.DBC",
50
- ): (
51
- target: object,
52
- methodName: string | symbol | undefined,
53
- parameterIndex: number,
54
- ) => void {
55
- return DBC.createPRE(
56
- HasAttribute.checkAlgorithm,
57
- [toCheckFor, invert],
58
- dbc,
59
- path,
60
- );
61
- }
62
- /**
63
- * A method-decorator factory using the {@link HasAttribute.checkAlgorithm } to determine whether this {@link DBC } is
64
- * fulfilled by the tagged method's returnvalue.
65
- *
66
- * @param toCheckFor See {@link HasAttribute.checkAlgorithm }.
67
- * @param path See {@link DBC.Postcondition }.
68
- * @param dbc See {@link DBC.decPostcondition }.
69
- *
70
- * @returns See {@link DBC.decPostcondition }. */
71
- public static POST(
72
- toCheckFor: string,
73
- invert = false,
74
- path: string | undefined = undefined,
75
- dbc = "WaXCode.DBC",
76
- ): (
77
- target: object,
78
- propertyKey: string,
79
- descriptor: PropertyDescriptor,
80
- ) => PropertyDescriptor {
81
- return DBC.createPOST(
82
- HasAttribute.checkAlgorithm,
83
- [toCheckFor, invert],
84
- dbc,
85
- path,
86
- );
87
- }
88
- /**
89
- * A field-decorator factory using the {@link hasAttribute.checkAlgorithm } to determine whether this {@link DBC } is
90
- * fulfilled by the tagged field.
91
- *
92
- * @param toCheckFor See {@link hasAttribute.checkAlgorithm }.
93
- * @param path See {@link DBC.decInvariant }.
94
- * @param dbc See {@link DBC.decInvariant }.
95
- *
96
- * @returns See {@link DBC.decInvariant }. */
97
- public static INVARIANT(
98
- toCheckFor: any,
99
- invert = false,
100
- path: string | undefined = undefined,
101
- dbc = "WaXCode.DBC",
102
- ) {
103
- return DBC.createINVARIANT(HasAttribute, [toCheckFor, invert], dbc, path);
104
- }
105
- /**
106
- * A field-decorator factory using the {@link hasAttribute.checkAlgorithm } to determine whether this {@link DBC } is
107
- * fulfilled by the tagged field's class instance.
108
- *
109
- * @param toCheckFor See {@link hasAttribute.checkAlgorithm }.
110
- * @param path See {@link DBC.decInvariant }.
111
- * @param dbc See {@link DBC.decInvariant }.
112
- *
113
- * @returns See {@link DBC.decInvariant }. */
114
- public static cINVARIANT(
115
- toCheckFor: any,
116
- invert = false,
117
- path: string | undefined = undefined,
118
- dbc = "WaXCode.DBC",
119
- ) {
120
- return DBC.decClassInvariant(
121
- [new HasAttribute(toCheckFor, invert)],
122
- path,
123
- dbc,
124
- );
125
- }
126
- // #endregion Condition checking.
127
- // #region Referenced Condition checking.
128
- //
129
- // For usage in dynamic scenarios (like with AE-DBC).
130
- //
131
- /**
132
- * Invokes the {@link hasAttribute.checkAlgorithm } passing the value **toCheck**, {@link hasAttribute.equivalent } and
133
- * {@link hasAttribute.invert }.
134
- *
135
- * @param toCheck See {@link EQ.checkAlgorithm }.
136
- *
137
- * @returns See {@link EQ.checkAlgorithm}. */
138
- // biome-ignore lint/suspicious/noExplicitAny: Necessary to check against NULL & UNDEFINED.
139
- public check(toCheck: any) {
140
- return HasAttribute.checkAlgorithm(toCheck, this.toCheckFor, this.invert);
141
- }
142
- /**
143
- * Creates this {@link DBC } by setting the protected property {@link hasAttribute.equivalent } used by
144
- * {@link hasAttribute.check }.
145
- *
146
- * @param toCheckFor See {@link hasAttribute.check }. */
147
- public constructor(
148
- protected toCheckFor: string,
149
- protected invert = false,
150
- ) {
151
- super();
152
- }
153
- // #endregion Referenced Condition checking.
154
- }
1
+ import { DBC } from "../DBC";
2
+ /**
3
+ * A {@link DBC } defining that a {@link HTMLElement } gotta have a certain attribute set.
4
+ *
5
+ * @remarks
6
+ * Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
7
+ export class HasAttribute extends DBC {
8
+ // #region Condition checking.
9
+ /**
10
+ * Checks if the {@link HTMLElement } **toCheck** has the attribute **toCheckFor**.
11
+ *
12
+ * @param toCheckFor name of the attribute to check for whether it is set or not.
13
+ *
14
+ * @returns TRUE if the {@link HTMLElement } **toCheck** has set the attribute **toCheckFor**,
15
+ * otherwise a proper errormessage. */
16
+ public static checkAlgorithm(
17
+ toCheck: any,
18
+ toCheckFor: string,
19
+ invert,
20
+ ): boolean | string {
21
+ if (!(toCheck instanceof HTMLElement)) {
22
+ return `The object to check for whether it has the attribute "${toCheckFor}" is not a HTMLElement. It is of type "${typeof toCheck}".`;
23
+ }
24
+ if (!invert && !(toCheck as HTMLElement).hasAttribute(toCheckFor)) {
25
+ return `Required Attribute "${toCheckFor}" is not set.`;
26
+ }
27
+ if (invert && (toCheck as HTMLElement).hasAttribute(toCheckFor)) {
28
+ return `Forbidden Attribute "${toCheckFor}" is set.`;
29
+ }
30
+ return true;
31
+ }
32
+ /**
33
+ * A parameter-decorator factory using the {@link HasAttribute.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
34
+ * by the tagged parameter.
35
+ *
36
+ * @param toCheckFor See {@link HasAttribute.checkAlgorithm }.
37
+ * @param path See {@link DBC.decPrecondition }.
38
+ * @param dbc See {@link DBC.decPrecondition }.
39
+ *
40
+ * @returns See {@link DBC.decPrecondition }. */
41
+ public static PRE(
42
+ toCheckFor: string,
43
+ invert = false,
44
+ path: string | undefined = undefined,
45
+ dbc = "WaXCode.DBC",
46
+ ): (
47
+ target: object,
48
+ methodName: string | symbol | undefined,
49
+ parameterIndex: number,
50
+ ) => void {
51
+ return DBC.createPRE(
52
+ HasAttribute.checkAlgorithm,
53
+ [toCheckFor, invert],
54
+ dbc,
55
+ path,
56
+ );
57
+ }
58
+ /**
59
+ * A method-decorator factory using the {@link HasAttribute.checkAlgorithm } to determine whether this {@link DBC } is
60
+ * fulfilled by the tagged method's returnvalue.
61
+ *
62
+ * @param toCheckFor See {@link HasAttribute.checkAlgorithm }.
63
+ * @param path See {@link DBC.Postcondition }.
64
+ * @param dbc See {@link DBC.decPostcondition }.
65
+ *
66
+ * @returns See {@link DBC.decPostcondition }. */
67
+ public static POST(
68
+ toCheckFor: string,
69
+ invert = false,
70
+ path: string | undefined = undefined,
71
+ dbc = "WaXCode.DBC",
72
+ ): (
73
+ target: object,
74
+ propertyKey: string,
75
+ descriptor: PropertyDescriptor,
76
+ ) => PropertyDescriptor {
77
+ return DBC.createPOST(
78
+ HasAttribute.checkAlgorithm,
79
+ [toCheckFor, invert],
80
+ dbc,
81
+ path,
82
+ );
83
+ }
84
+ /**
85
+ * A field-decorator factory using the {@link hasAttribute.checkAlgorithm } to determine whether this {@link DBC } is
86
+ * fulfilled by the tagged field.
87
+ *
88
+ * @param toCheckFor See {@link hasAttribute.checkAlgorithm }.
89
+ * @param path See {@link DBC.decInvariant }.
90
+ * @param dbc See {@link DBC.decInvariant }.
91
+ *
92
+ * @returns See {@link DBC.decInvariant }. */
93
+ public static INVARIANT(
94
+ toCheckFor: any,
95
+ invert = false,
96
+ path: string | undefined = undefined,
97
+ dbc = "WaXCode.DBC",
98
+ ) {
99
+ return DBC.createINVARIANT(HasAttribute, [toCheckFor, invert], dbc, path);
100
+ }
101
+ /**
102
+ * A field-decorator factory using the {@link hasAttribute.checkAlgorithm } to determine whether this {@link DBC } is
103
+ * fulfilled by the tagged field's class instance.
104
+ *
105
+ * @param toCheckFor See {@link hasAttribute.checkAlgorithm }.
106
+ * @param path See {@link DBC.decInvariant }.
107
+ * @param dbc See {@link DBC.decInvariant }.
108
+ *
109
+ * @returns See {@link DBC.decInvariant }. */
110
+ public static cINVARIANT(
111
+ toCheckFor: any,
112
+ invert = false,
113
+ path: string | undefined = undefined,
114
+ dbc = "WaXCode.DBC",
115
+ ) {
116
+ return DBC.decClassInvariant(
117
+ [new HasAttribute(toCheckFor, invert)],
118
+ path,
119
+ dbc,
120
+ );
121
+ }
122
+ // #endregion Condition checking.
123
+ // #region Referenced Condition checking.
124
+ //
125
+ // For usage in dynamic scenarios (like with AE-DBC).
126
+ //
127
+ /**
128
+ * Invokes the {@link hasAttribute.checkAlgorithm } passing the value **toCheck**, {@link hasAttribute.equivalent } and
129
+ * {@link hasAttribute.invert }.
130
+ *
131
+ * @param toCheck See {@link EQ.checkAlgorithm }.
132
+ *
133
+ * @returns See {@link EQ.checkAlgorithm}. */
134
+ public check(toCheck: any) {
135
+ return HasAttribute.checkAlgorithm(toCheck, this.toCheckFor, this.invert);
136
+ }
137
+ /**
138
+ * Creates this {@link DBC } by setting the protected property {@link hasAttribute.equivalent } used by
139
+ * {@link hasAttribute.check }.
140
+ *
141
+ * @param toCheckFor See {@link hasAttribute.check }. */
142
+ public constructor(
143
+ protected toCheckFor: string,
144
+ protected invert = false,
145
+ ) {
146
+ super();
147
+ }
148
+ // #endregion Referenced Condition checking.
149
+ }