xdbc 1.0.217 → 1.0.219

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 (120) hide show
  1. package/.gitattributes +16 -8
  2. package/.vscode/settings.json +3 -3
  3. package/.vscode/tasks.json +23 -23
  4. package/ASSESSMENT.md +249 -0
  5. package/README.md +538 -408
  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 +786 -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 +45 -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 +123 -0
  38. package/dist/DBC/DOM.js +362 -0
  39. package/dist/DBC/EQ/DIFFERENT.js +34 -0
  40. package/dist/DBC/EQ.js +101 -0
  41. package/dist/DBC/GREATER.js +99 -0
  42. package/dist/DBC/HasAttribute.js +101 -0
  43. package/dist/DBC/IF.js +96 -0
  44. package/dist/DBC/INSTANCE.js +122 -0
  45. package/dist/DBC/JSON.OP.js +120 -0
  46. package/dist/DBC/JSON.Parse.js +104 -0
  47. package/dist/DBC/OR.js +125 -0
  48. package/dist/DBC/REGEX.js +136 -0
  49. package/dist/DBC/TYPE.js +112 -0
  50. package/dist/DBC/UNDEFINED.js +87 -0
  51. package/dist/DBC/ZOD.js +99 -0
  52. package/dist/DBC.d.ts +18 -4
  53. package/dist/DBC.js +645 -0
  54. package/dist/Demo.d.ts +10 -0
  55. package/dist/Demo.js +713 -0
  56. package/dist/Test.html +18 -0
  57. package/dist/bundle.js +6140 -405
  58. package/dist/index.d.ts +22 -0
  59. package/dist/index.html +18 -0
  60. package/dist/index.js +22 -0
  61. package/docs/assets/highlight.css +22 -22
  62. package/docs/assets/icons.js +17 -17
  63. package/docs/assets/main.js +60 -60
  64. package/docs/assets/style.css +1640 -1640
  65. package/docs/classes/DBC.DBC.html +98 -98
  66. package/docs/classes/DBC_AE.AE.html +160 -160
  67. package/docs/classes/DBC_EQ.EQ.html +131 -131
  68. package/docs/classes/DBC_GREATER.GREATER.html +139 -139
  69. package/docs/classes/DBC_INSTANCE.INSTANCE.html +130 -130
  70. package/docs/classes/DBC_JSON.OP.JSON_OP.html +138 -138
  71. package/docs/classes/DBC_JSON.Parse.JSON_Parse.html +129 -129
  72. package/docs/classes/DBC_OR.OR.html +137 -137
  73. package/docs/classes/DBC_REGEX.REGEX.html +136 -136
  74. package/docs/classes/DBC_TYPE.TYPE.html +130 -130
  75. package/docs/classes/Demo.Demo.html +14 -14
  76. package/docs/hierarchy.html +1 -1
  77. package/docs/index.html +1 -1
  78. package/docs/modules/DBC.html +1 -1
  79. package/docs/modules/DBC_AE.html +1 -1
  80. package/docs/modules/DBC_EQ.html +1 -1
  81. package/docs/modules/DBC_GREATER.html +1 -1
  82. package/docs/modules/DBC_INSTANCE.html +1 -1
  83. package/docs/modules/DBC_JSON.OP.html +1 -1
  84. package/docs/modules/DBC_JSON.Parse.html +1 -1
  85. package/docs/modules/DBC_OR.html +1 -1
  86. package/docs/modules/DBC_REGEX.html +1 -1
  87. package/docs/modules/DBC_TYPE.html +1 -1
  88. package/docs/modules/Demo.html +1 -1
  89. package/jest.config.js +32 -32
  90. package/package.json +71 -55
  91. package/src/DBC/AE.ts +269 -288
  92. package/src/DBC/ARR/PLAIN_OBJECT.ts +122 -133
  93. package/src/DBC/ARRAY.ts +117 -127
  94. package/src/DBC/COMPARISON/GREATER.ts +41 -46
  95. package/src/DBC/COMPARISON/GREATER_OR_EQUAL.ts +41 -45
  96. package/src/DBC/COMPARISON/LESS.ts +41 -45
  97. package/src/DBC/COMPARISON/LESS_OR_EQUAL.ts +41 -45
  98. package/src/DBC/COMPARISON.ts +149 -159
  99. package/src/DBC/DEFINED.ts +117 -122
  100. package/src/DBC/DOM.ts +453 -0
  101. package/src/DBC/EQ/DIFFERENT.ts +51 -57
  102. package/src/DBC/EQ.ts +154 -163
  103. package/src/DBC/HasAttribute.ts +149 -154
  104. package/src/DBC/IF.ts +173 -179
  105. package/src/DBC/INSTANCE.ts +168 -171
  106. package/src/DBC/JSON.OP.ts +178 -186
  107. package/src/DBC/JSON.Parse.ts +150 -157
  108. package/src/DBC/OR.ts +183 -187
  109. package/src/DBC/REGEX.ts +195 -196
  110. package/src/DBC/TYPE.ts +142 -149
  111. package/src/DBC/UNDEFINED.ts +115 -117
  112. package/src/DBC/ZOD.ts +130 -135
  113. package/src/DBC.ts +902 -904
  114. package/src/Demo.ts +537 -404
  115. package/src/index.ts +22 -0
  116. package/tsconfig.json +18 -18
  117. package/tsconfig.test.json +7 -7
  118. package/typedoc.json +16 -16
  119. package/webpack.config.js +27 -27
  120. package/Assessment.md +0 -507
@@ -1,45 +1,41 @@
1
- import { COMPARISON } from "../COMPARISON";
2
- /** See {@link COMPARISON }. */
3
- export class GREATER_OR_EQUAL extends COMPARISON {
4
- /** See {@link COMPARISON.PRE }. */
5
- public static override PRE(
6
- // biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
7
- equivalent: any,
8
- equalityPermitted = false,
9
- invert = false,
10
- path: string | undefined = undefined,
11
- hint: string | undefined = undefined,
12
- dbc: string | undefined = undefined,
13
- ) {
14
- return COMPARISON.PRE(equivalent, true, false, path, hint, dbc);
15
- }
16
- /** See {@link COMPARISON.POST }. */
17
- public static override POST(
18
- // biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
19
- equivalent: any,
20
- equalityPermitted = false,
21
- invert = false,
22
- path: string | undefined = undefined,
23
- hint: string | undefined = undefined,
24
- dbc: string | undefined = undefined,
25
- ) {
26
- return COMPARISON.POST(equivalent, true, false, path, hint, dbc);
27
- }
28
- /** See {@link COMPARISON.INVARIANT }. */
29
- public static INVARIANT(
30
- // biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
31
- equivalent: any,
32
- equalityPermitted = false,
33
- invert = false,
34
- path: string | undefined = undefined,
35
- hint: string | undefined = undefined,
36
- dbc: string | undefined = undefined,
37
- ) {
38
- return COMPARISON.INVARIANT(equivalent, true, false, path, hint, dbc);
39
- }
40
- /** See {@link COMPARISON.constructor }. */
41
- // biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
42
- constructor(public equivalent: any) {
43
- super(equivalent, true, false);
44
- }
45
- }
1
+ import { COMPARISON } from "../COMPARISON";
2
+ /** See {@link COMPARISON }. */
3
+ export class GREATER_OR_EQUAL extends COMPARISON {
4
+ /** See {@link COMPARISON.PRE }. */
5
+ public static override PRE(
6
+ equivalent: any,
7
+ equalityPermitted = false,
8
+ invert = false,
9
+ path: string | undefined = undefined,
10
+ hint: string | undefined = undefined,
11
+ dbc: string | undefined = undefined,
12
+ ) {
13
+ return COMPARISON.PRE(equivalent, true, false, path, hint, dbc);
14
+ }
15
+ /** See {@link COMPARISON.POST }. */
16
+ public static override POST(
17
+ equivalent: any,
18
+ equalityPermitted = false,
19
+ invert = false,
20
+ path: string | undefined = undefined,
21
+ hint: string | undefined = undefined,
22
+ dbc: string | undefined = undefined,
23
+ ) {
24
+ return COMPARISON.POST(equivalent, true, false, path, hint, dbc);
25
+ }
26
+ /** See {@link COMPARISON.INVARIANT }. */
27
+ public static INVARIANT(
28
+ equivalent: any,
29
+ equalityPermitted = false,
30
+ invert = false,
31
+ path: string | undefined = undefined,
32
+ hint: string | undefined = undefined,
33
+ dbc: string | undefined = undefined,
34
+ ) {
35
+ return COMPARISON.INVARIANT(equivalent, true, false, path, hint, dbc);
36
+ }
37
+ /** See {@link COMPARISON.constructor }. */
38
+ constructor(public equivalent: any) {
39
+ super(equivalent, true, false);
40
+ }
41
+ }
@@ -1,45 +1,41 @@
1
- import { COMPARISON } from "../COMPARISON";
2
- /** See {@link COMPARISON }. */
3
- export class LESS extends COMPARISON {
4
- /** See {@link COMPARISON.PRE }. */
5
- public static override PRE(
6
- // biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
7
- equivalent: any,
8
- equalityPermitted = false,
9
- invert = false,
10
- path: string | undefined = undefined,
11
- hint: string | undefined = undefined,
12
- dbc: string | undefined = undefined,
13
- ) {
14
- return COMPARISON.PRE(equivalent, false, true, path, hint, dbc);
15
- }
16
- /** See {@link COMPARISON.POST }. */
17
- public static override POST(
18
- // biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
19
- equivalent: any,
20
- equalityPermitted = false,
21
- invert = false,
22
- path: string | undefined = undefined,
23
- hint: string | undefined = undefined,
24
- dbc: string | undefined = undefined,
25
- ) {
26
- return COMPARISON.POST(equivalent, false, true, path, hint, dbc);
27
- }
28
- /** See {@link COMPARISON.INVARIANT }. */
29
- public static INVARIANT(
30
- // biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
31
- equivalent: any,
32
- equalityPermitted = false,
33
- invert = false,
34
- path: string | undefined = undefined,
35
- hint: string | undefined = undefined,
36
- dbc: string | undefined = undefined,
37
- ) {
38
- return COMPARISON.INVARIANT(equivalent, false, true, path, hint, dbc);
39
- }
40
- /** See {@link COMPARISON.constructor }. */
41
- // biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
42
- constructor(public equivalent: any) {
43
- super(equivalent, false, true);
44
- }
45
- }
1
+ import { COMPARISON } from "../COMPARISON";
2
+ /** See {@link COMPARISON }. */
3
+ export class LESS extends COMPARISON {
4
+ /** See {@link COMPARISON.PRE }. */
5
+ public static override PRE(
6
+ equivalent: any,
7
+ equalityPermitted = false,
8
+ invert = false,
9
+ path: string | undefined = undefined,
10
+ hint: string | undefined = undefined,
11
+ dbc: string | undefined = undefined,
12
+ ) {
13
+ return COMPARISON.PRE(equivalent, false, true, path, hint, dbc);
14
+ }
15
+ /** See {@link COMPARISON.POST }. */
16
+ public static override POST(
17
+ equivalent: any,
18
+ equalityPermitted = false,
19
+ invert = false,
20
+ path: string | undefined = undefined,
21
+ hint: string | undefined = undefined,
22
+ dbc: string | undefined = undefined,
23
+ ) {
24
+ return COMPARISON.POST(equivalent, false, true, path, hint, dbc);
25
+ }
26
+ /** See {@link COMPARISON.INVARIANT }. */
27
+ public static INVARIANT(
28
+ equivalent: any,
29
+ equalityPermitted = false,
30
+ invert = false,
31
+ path: string | undefined = undefined,
32
+ hint: string | undefined = undefined,
33
+ dbc: string | undefined = undefined,
34
+ ) {
35
+ return COMPARISON.INVARIANT(equivalent, false, true, path, hint, dbc);
36
+ }
37
+ /** See {@link COMPARISON.constructor }. */
38
+ constructor(public equivalent: any) {
39
+ super(equivalent, false, true);
40
+ }
41
+ }
@@ -1,45 +1,41 @@
1
- import { COMPARISON } from "../COMPARISON";
2
- /** See {@link COMPARISON }. */
3
- export class LESS_OR_EQUAL extends COMPARISON {
4
- /** See {@link COMPARISON.PRE }. */
5
- public static override PRE(
6
- // biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
7
- equivalent: any,
8
- equalityPermitted = false,
9
- invert = false,
10
- path: string | undefined = undefined,
11
- hint: string | undefined = undefined,
12
- dbc: string | undefined = undefined,
13
- ) {
14
- return COMPARISON.PRE(equivalent, true, true, path, hint, dbc);
15
- }
16
- /** See {@link COMPARISON.POST }. */
17
- public static override POST(
18
- // biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
19
- equivalent: any,
20
- equalityPermitted = false,
21
- invert = false,
22
- path: string | undefined = undefined,
23
- hint: string | undefined = undefined,
24
- dbc: string | undefined = undefined,
25
- ) {
26
- return COMPARISON.POST(equivalent, true, true, path, hint, dbc);
27
- }
28
- /** See {@link COMPARISON.INVARIANT }. */
29
- public static INVARIANT(
30
- // biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
31
- equivalent: any,
32
- equalityPermitted = false,
33
- invert = false,
34
- path: string | undefined = undefined,
35
- hint: string | undefined = undefined,
36
- dbc: string | undefined = undefined,
37
- ) {
38
- return COMPARISON.INVARIANT(equivalent, true, true, path, hint, dbc);
39
- }
40
- /** See {@link COMPARISON.constructor }. */
41
- // biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
42
- constructor(public equivalent: any) {
43
- super(equivalent, true, true);
44
- }
45
- }
1
+ import { COMPARISON } from "../COMPARISON";
2
+ /** See {@link COMPARISON }. */
3
+ export class LESS_OR_EQUAL extends COMPARISON {
4
+ /** See {@link COMPARISON.PRE }. */
5
+ public static override PRE(
6
+ equivalent: any,
7
+ equalityPermitted = false,
8
+ invert = false,
9
+ path: string | undefined = undefined,
10
+ hint: string | undefined = undefined,
11
+ dbc: string | undefined = undefined,
12
+ ) {
13
+ return COMPARISON.PRE(equivalent, true, true, path, hint, dbc);
14
+ }
15
+ /** See {@link COMPARISON.POST }. */
16
+ public static override POST(
17
+ equivalent: any,
18
+ equalityPermitted = false,
19
+ invert = false,
20
+ path: string | undefined = undefined,
21
+ hint: string | undefined = undefined,
22
+ dbc: string | undefined = undefined,
23
+ ) {
24
+ return COMPARISON.POST(equivalent, true, true, path, hint, dbc);
25
+ }
26
+ /** See {@link COMPARISON.INVARIANT }. */
27
+ public static INVARIANT(
28
+ equivalent: any,
29
+ equalityPermitted = false,
30
+ invert = false,
31
+ path: string | undefined = undefined,
32
+ hint: string | undefined = undefined,
33
+ dbc: string | undefined = undefined,
34
+ ) {
35
+ return COMPARISON.INVARIANT(equivalent, true, true, path, hint, dbc);
36
+ }
37
+ /** See {@link COMPARISON.constructor }. */
38
+ constructor(public equivalent: any) {
39
+ super(equivalent, true, true);
40
+ }
41
+ }
@@ -1,159 +1,149 @@
1
- import { DBC } from "../DBC";
2
- /**
3
- * A {@link DBC } defining a comparison between two {@link object }s.
4
- *
5
- * @remarks
6
- * Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
7
- export class COMPARISON extends DBC {
8
- // #region Condition checking.
9
- /**
10
- * Does a comparison between the {@link object } **toCheck** and the **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
- // biome-ignore lint/suspicious/noExplicitAny: Necessary for dynamic comparison
18
- static checkAlgorithm(
19
- toCheck: any,
20
- equivalent: any,
21
- equalityPermitted: boolean,
22
- invert: boolean,
23
- ) {
24
- if (equalityPermitted && !invert && toCheck < equivalent) {
25
- return `Value has to be greater than or equal to "${equivalent}"`;
26
- }
27
-
28
- if (equalityPermitted && invert && toCheck > equivalent) {
29
- return `Value has to be less than or equal to "${equivalent}"`;
30
- }
31
-
32
- if (!equalityPermitted && !invert && toCheck <= equivalent) {
33
- return `Value has to be greater than "${equivalent}"`;
34
- }
35
-
36
- if (!equalityPermitted && invert && toCheck >= equivalent) {
37
- return `Value has to be less than "${equivalent}"`;
38
- }
39
-
40
- return true;
41
- }
42
- /**
43
- * A parameter-decorator factory using the {@link COMPARISON.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
44
- * by the tagged parameter.
45
- *
46
- * @param equivalent See {@link COMPARISON.checkAlgorithm }.
47
- * @param equalityPermitted See {@link COMPARISON.checkAlgorithm }.
48
- * @param path See {@link DBC.decPrecondition }.
49
- * @param hint See {@link DBC.decPrecondition }.
50
- * @param dbc See {@link DBC.decPrecondition }.
51
- *
52
- * @returns See {@link DBC.decPrecondition }. */
53
- static PRE(
54
- // biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
55
- equivalent: any,
56
- equalityPermitted = false,
57
- invert = false,
58
- path: string | undefined = undefined,
59
- hint: string | undefined = undefined,
60
- dbc: string | undefined = undefined,
61
- ) {
62
- return DBC.createPRE(
63
- COMPARISON.checkAlgorithm,
64
- [equivalent, equalityPermitted, invert],
65
- dbc,
66
- path,
67
- hint,
68
- );
69
- }
70
- /**
71
- * A method-decorator factory using the {@link COMPARISON.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
72
- * by the tagged method's returnvalue.
73
- *
74
- * @param equivalent See {@link COMPARISON.checkAlgorithm }.
75
- * @param equalityPermitted See {@link COMPARISON.checkAlgorithm }.
76
- * @param path See {@link DBC.Postcondition }.
77
- * @param hint See {@link DBC.decPostcondition }.
78
- * @param dbc See {@link DBC.decPostcondition }.
79
- *
80
- * @returns See {@link DBC.decPostcondition }. */
81
- static POST(
82
- // biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
83
- equivalent: any,
84
- equalityPermitted = false,
85
- invert = false,
86
- path: string | undefined = undefined,
87
- hint: string | undefined = undefined,
88
- dbc: string | undefined = undefined,
89
- ) {
90
- return DBC.createPOST(
91
- COMPARISON.checkAlgorithm,
92
- [equivalent, equalityPermitted, invert],
93
- dbc,
94
- path,
95
- hint,
96
- );
97
- }
98
- /**
99
- * A field-decorator factory using the {@link COMPARISON.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
100
- * by the tagged field.
101
- *
102
- * @param equivalent See {@link COMPARISON.checkAlgorithm }.
103
- * @param equalityPermitted See {@link COMPARISON.checkAlgorithm }.
104
- * @param path See {@link DBC.decInvariant }.
105
- * @param hint See {@link DBC.decInvariant }.
106
- * @param dbc See {@link DBC.decInvariant }.
107
- *
108
- * @returns See {@link DBC.decInvariant }. */
109
- static INVARIANT(
110
- // biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
111
- equivalent: any,
112
- equalityPermitted = false,
113
- invert = false,
114
- path: string | undefined = undefined,
115
- hint: string | undefined = undefined,
116
- dbc: string | undefined = undefined,
117
- ) {
118
- return DBC.createINVARIANT(
119
- COMPARISON,
120
- [equivalent, equalityPermitted, invert],
121
- dbc,
122
- path,
123
- hint,
124
- );
125
- }
126
- // #endregion Condition checking.
127
- // #region Referenced Condition checking.
128
- // #region Dynamic usage.
129
- /**
130
- * Invokes the {@link COMPARISON.checkAlgorithm } passing the value **toCheck**, {@link COMPARISON.equivalent } and {@link COMPARISON.invert }.
131
- *
132
- * @param toCheck See {@link COMPARISON.checkAlgorithm }.
133
- *
134
- * @returns See {@link COMPARISON.checkAlgorithm}. */
135
- // biome-ignore lint/suspicious/noExplicitAny: Necessary for dynamic comparison
136
- public check(toCheck: any) {
137
- return COMPARISON.checkAlgorithm(
138
- toCheck,
139
- this.equivalent,
140
- this.equalityPermitted,
141
- this.invert,
142
- );
143
- }
144
- /**
145
- * Creates this {@link COMPARISON } by setting the protected property {@link COMPARISON.equivalent }, {@link COMPARISON.equalityPermitted } and {@link COMPARISON.invert } used by {@link COMPARISON.check }.
146
- *
147
- * @param equivalent See {@link COMPARISON.check }.
148
- * @param equalityPermitted See {@link COMPARISON.check }.
149
- * @param invert See {@link COMPARISON.check }. */
150
- constructor(
151
- // biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
152
- public equivalent: any,
153
- public equalityPermitted = false,
154
- public invert = false,
155
- ) {
156
- super();
157
- }
158
- // #endregion Dynamic usage.
159
- }
1
+ import { DBC } from "../DBC";
2
+ /**
3
+ * A {@link DBC } defining a comparison between two {@link object }s.
4
+ *
5
+ * @remarks
6
+ * Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
7
+ export class COMPARISON extends DBC {
8
+ // #region Condition checking.
9
+ /**
10
+ * Does a comparison between the {@link object } **toCheck** and the **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
+ static checkAlgorithm(
18
+ toCheck: any,
19
+ equivalent: any,
20
+ equalityPermitted: boolean,
21
+ invert: boolean,
22
+ ) {
23
+ if (equalityPermitted && !invert && toCheck < equivalent) {
24
+ return `Value has to be greater than or equal to "${equivalent}"`;
25
+ }
26
+ if (equalityPermitted && invert && toCheck > equivalent) {
27
+ return `Value has to be less than or equal to "${equivalent}"`;
28
+ }
29
+ if (!equalityPermitted && !invert && toCheck <= equivalent) {
30
+ return `Value has to be greater than "${equivalent}"`;
31
+ }
32
+ if (!equalityPermitted && invert && toCheck >= equivalent) {
33
+ return `Value has to be less than "${equivalent}"`;
34
+ }
35
+ return true;
36
+ }
37
+ /**
38
+ * A parameter-decorator factory using the {@link COMPARISON.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
39
+ * by the tagged parameter.
40
+ *
41
+ * @param equivalent See {@link COMPARISON.checkAlgorithm }.
42
+ * @param equalityPermitted See {@link COMPARISON.checkAlgorithm }.
43
+ * @param path See {@link DBC.decPrecondition }.
44
+ * @param hint See {@link DBC.decPrecondition }.
45
+ * @param dbc See {@link DBC.decPrecondition }.
46
+ *
47
+ * @returns See {@link DBC.decPrecondition }. */
48
+ static PRE(
49
+ equivalent: any,
50
+ equalityPermitted = false,
51
+ invert = false,
52
+ path: string | undefined = undefined,
53
+ hint: string | undefined = undefined,
54
+ dbc: string | undefined = undefined,
55
+ ) {
56
+ return DBC.createPRE(
57
+ COMPARISON.checkAlgorithm,
58
+ [equivalent, equalityPermitted, invert],
59
+ dbc,
60
+ path,
61
+ hint,
62
+ );
63
+ }
64
+ /**
65
+ * A method-decorator factory using the {@link COMPARISON.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
66
+ * by the tagged method's returnvalue.
67
+ *
68
+ * @param equivalent See {@link COMPARISON.checkAlgorithm }.
69
+ * @param equalityPermitted See {@link COMPARISON.checkAlgorithm }.
70
+ * @param path See {@link DBC.Postcondition }.
71
+ * @param hint See {@link DBC.decPostcondition }.
72
+ * @param dbc See {@link DBC.decPostcondition }.
73
+ *
74
+ * @returns See {@link DBC.decPostcondition }. */
75
+ static POST(
76
+ equivalent: any,
77
+ equalityPermitted = false,
78
+ invert = false,
79
+ path: string | undefined = undefined,
80
+ hint: string | undefined = undefined,
81
+ dbc: string | undefined = undefined,
82
+ ) {
83
+ return DBC.createPOST(
84
+ COMPARISON.checkAlgorithm,
85
+ [equivalent, equalityPermitted, invert],
86
+ dbc,
87
+ path,
88
+ hint,
89
+ );
90
+ }
91
+ /**
92
+ * A field-decorator factory using the {@link COMPARISON.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
93
+ * by the tagged field.
94
+ *
95
+ * @param equivalent See {@link COMPARISON.checkAlgorithm }.
96
+ * @param equalityPermitted See {@link COMPARISON.checkAlgorithm }.
97
+ * @param path See {@link DBC.decInvariant }.
98
+ * @param hint See {@link DBC.decInvariant }.
99
+ * @param dbc See {@link DBC.decInvariant }.
100
+ *
101
+ * @returns See {@link DBC.decInvariant }. */
102
+ static INVARIANT(
103
+ equivalent: any,
104
+ equalityPermitted = false,
105
+ invert = false,
106
+ path: string | undefined = undefined,
107
+ hint: string | undefined = undefined,
108
+ dbc: string | undefined = undefined,
109
+ ) {
110
+ return DBC.createINVARIANT(
111
+ COMPARISON,
112
+ [equivalent, equalityPermitted, invert],
113
+ dbc,
114
+ path,
115
+ hint,
116
+ );
117
+ }
118
+ // #endregion Condition checking.
119
+ // #region Referenced Condition checking.
120
+ // #region Dynamic usage.
121
+ /**
122
+ * Invokes the {@link COMPARISON.checkAlgorithm } passing the value **toCheck**, {@link COMPARISON.equivalent } and {@link COMPARISON.invert }.
123
+ *
124
+ * @param toCheck See {@link COMPARISON.checkAlgorithm }.
125
+ *
126
+ * @returns See {@link COMPARISON.checkAlgorithm}. */
127
+ public check(toCheck: any) {
128
+ return COMPARISON.checkAlgorithm(
129
+ toCheck,
130
+ this.equivalent,
131
+ this.equalityPermitted,
132
+ this.invert,
133
+ );
134
+ }
135
+ /**
136
+ * Creates this {@link COMPARISON } by setting the protected property {@link COMPARISON.equivalent }, {@link COMPARISON.equalityPermitted } and {@link COMPARISON.invert } used by {@link COMPARISON.check }.
137
+ *
138
+ * @param equivalent See {@link COMPARISON.check }.
139
+ * @param equalityPermitted See {@link COMPARISON.check }.
140
+ * @param invert See {@link COMPARISON.check }. */
141
+ constructor(
142
+ public equivalent: any,
143
+ public equalityPermitted = false,
144
+ public invert = false,
145
+ ) {
146
+ super();
147
+ }
148
+ // #endregion Dynamic usage.
149
+ }