xdbc 1.0.81 → 1.0.83

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,86 @@
1
+ import { DBC } from "../DBC.js";
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 GREATER extends DBC {
8
+ // #region Condition checking.
9
+ /**
10
+ * Checks if the value "toCheck" is nb 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
+ static checkAlgorithm(toCheck, equivalent, equalityPermitted, invert) {
18
+ if (equalityPermitted && !invert && toCheck <= equivalent) {
19
+ return `Value has to to be greater than or equal to "${equivalent}"`;
20
+ }
21
+ if (equalityPermitted && invert && toCheck >= equivalent) {
22
+ return `Value must not to be less than or equal to "${equivalent}"`;
23
+ }
24
+ if (!invert && toCheck < equivalent) {
25
+ return `Value has to to be greater than "${equivalent}"`;
26
+ }
27
+ if (invert && toCheck > equivalent) {
28
+ return `Value must not to be less than "${equivalent}"`;
29
+ }
30
+ return true;
31
+ }
32
+ /**
33
+ * A parameter-decorator factory using the {@link GREATER.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
34
+ * by the tagged parameter.
35
+ *
36
+ * @param equivalent See {@link GREATER.checkAlgorithm }.
37
+ * @param equalityPermitted See {@link GREATER.checkAlgorithm }.
38
+ * @param path See {@link DBC.decPrecondition }.
39
+ * @param dbc See {@link DBC.decPrecondition }.
40
+ *
41
+ * @returns See {@link DBC.decPrecondition }. */
42
+ static PRE(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
43
+ return DBC.decPrecondition((value, target, methodName, parameterIndex) => {
44
+ return GREATER.checkAlgorithm(value, equivalent, equalityPermitted, invert);
45
+ }, dbc, path);
46
+ }
47
+ /**
48
+ * A method-decorator factory using the {@link GREATER.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
49
+ * by the tagged method's returnvalue.
50
+ *
51
+ * @param equivalent See {@link GREATER.checkAlgorithm }.
52
+ * @param equalityPermitted See {@link GREATER.checkAlgorithm }.
53
+ * @param path See {@link DBC.Postcondition }.
54
+ * @param dbc See {@link DBC.decPostcondition }.
55
+ *
56
+ * @returns See {@link DBC.decPostcondition }. */
57
+ static POST(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
58
+ return DBC.decPostcondition((value, target, propertyKey) => {
59
+ return GREATER.checkAlgorithm(value, equalityPermitted, equivalent, invert);
60
+ }, dbc, path);
61
+ }
62
+ // #endregion Condition checking.
63
+ // #region Referenced Condition checking.
64
+ // #region Dynamic usage.
65
+ /**
66
+ * Invokes the {@link GREATER.checkAlgorithm } passing the value "toCheck", {@link GREATER.equivalent } and {@link GREATER.invert }.
67
+ *
68
+ * @param toCheck See {@link GREATER.checkAlgorithm }.
69
+ *
70
+ * @returns See {@link GREATER.checkAlgorithm}. */
71
+ check(toCheck) {
72
+ return GREATER.checkAlgorithm(toCheck, this.equivalent, this.equalityPermitted, this.invert);
73
+ }
74
+ /**
75
+ * Creates this {@link GREATER } by setting the protected property {@link GREATER.equivalent }, {@link GREATER.equalityPermitted } and {@link GREATER.invert } used by {@link GREATER.check }.
76
+ *
77
+ * @param equivalent See {@link GREATER.check }.
78
+ * @param equalityPermitted See {@link GREATER.check }.
79
+ * @param invert See {@link GREATER.check }. */
80
+ constructor(equivalent, equalityPermitted = false, invert = false) {
81
+ super();
82
+ this.equivalent = equivalent;
83
+ this.equalityPermitted = equalityPermitted;
84
+ this.invert = invert;
85
+ }
86
+ }
package/dist/DBC/REGEX.js CHANGED
@@ -94,6 +94,7 @@ export class REGEX extends DBC {
94
94
  }
95
95
  /** Stores often used {@link RegExp }s. */
96
96
  REGEX.stdExp = {
97
+ eMail: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/i,
97
98
  property: /^[$_A-Za-z][$_A-Za-z0-9]*$/,
98
99
  url: /^(?:(?:http:|https?|ftp):\/\/)?(?:\S+(?::\S*)?@)?(?:localhost|(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,})(?::\d{2,5})?(?:\/(?:[\w\-\.]*\/)*[\w\-\.]+(?:\?\S*)?(?:#\S*)?)?$/i,
99
100
  keyPath: /^([a-zA-Z_$][a-zA-Z0-9_$]*\.)*[a-zA-Z_$][a-zA-Z0-9_$]*$/,
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.81",
2
+ "version": "1.0.83",
3
3
  "name": "xdbc",
4
4
  "scripts": {
5
5
  "format": "biome format ./src --write",
@@ -0,0 +1,127 @@
1
+ import { DBC } from "../DBC.js";
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 GREATER extends DBC {
8
+ // #region Condition checking.
9
+ /**
10
+ * Checks if the value "toCheck" is nb 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
+ static checkAlgorithm(toCheck, equivalent, equalityPermitted, invert) {
18
+ if (equalityPermitted && !invert && toCheck <= equivalent) {
19
+ return `Value has to to be greater than or equal to "${equivalent}"`;
20
+ }
21
+
22
+ if (equalityPermitted && invert && toCheck >= equivalent) {
23
+ return `Value must not to be less than or equal to "${equivalent}"`;
24
+ }
25
+
26
+ if (!invert && toCheck < equivalent) {
27
+ return `Value has to to be greater than "${equivalent}"`;
28
+ }
29
+
30
+ if (invert && toCheck > equivalent) {
31
+ return `Value must not to be less than "${equivalent}"`;
32
+ }
33
+
34
+ return true;
35
+ }
36
+ /**
37
+ * A parameter-decorator factory using the {@link GREATER.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
38
+ * by the tagged parameter.
39
+ *
40
+ * @param equivalent See {@link GREATER.checkAlgorithm }.
41
+ * @param equalityPermitted See {@link GREATER.checkAlgorithm }.
42
+ * @param path See {@link DBC.decPrecondition }.
43
+ * @param dbc See {@link DBC.decPrecondition }.
44
+ *
45
+ * @returns See {@link DBC.decPrecondition }. */
46
+ static PRE(
47
+ equivalent,
48
+ equalityPermitted = false,
49
+ invert = false,
50
+ path = undefined,
51
+ dbc = "WaXCode.DBC",
52
+ ) {
53
+ return DBC.decPrecondition(
54
+ (value, target, methodName, parameterIndex) => {
55
+ return GREATER.checkAlgorithm(
56
+ value,
57
+ equivalent,
58
+ equalityPermitted,
59
+ invert,
60
+ );
61
+ },
62
+ dbc,
63
+ path,
64
+ );
65
+ }
66
+ /**
67
+ * A method-decorator factory using the {@link GREATER.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
68
+ * by the tagged method's returnvalue.
69
+ *
70
+ * @param equivalent See {@link GREATER.checkAlgorithm }.
71
+ * @param equalityPermitted See {@link GREATER.checkAlgorithm }.
72
+ * @param path See {@link DBC.Postcondition }.
73
+ * @param dbc See {@link DBC.decPostcondition }.
74
+ *
75
+ * @returns See {@link DBC.decPostcondition }. */
76
+ static POST(
77
+ equivalent,
78
+ equalityPermitted = false,
79
+ invert = false,
80
+ path = undefined,
81
+ dbc = "WaXCode.DBC",
82
+ ) {
83
+ return DBC.decPostcondition(
84
+ (value, target, propertyKey) => {
85
+ return GREATER.checkAlgorithm(
86
+ value,
87
+ equalityPermitted,
88
+ equivalent,
89
+ invert,
90
+ );
91
+ },
92
+ dbc,
93
+ path,
94
+ );
95
+ }
96
+ // #endregion Condition checking.
97
+ // #region Referenced Condition checking.
98
+ // #region Dynamic usage.
99
+ /**
100
+ * Invokes the {@link GREATER.checkAlgorithm } passing the value "toCheck", {@link GREATER.equivalent } and {@link GREATER.invert }.
101
+ *
102
+ * @param toCheck See {@link GREATER.checkAlgorithm }.
103
+ *
104
+ * @returns See {@link GREATER.checkAlgorithm}. */
105
+ check(toCheck) {
106
+ return GREATER.checkAlgorithm(
107
+ toCheck,
108
+ this.equivalent,
109
+ this.equalityPermitted,
110
+ this.invert,
111
+ );
112
+ }
113
+ /**
114
+ * Creates this {@link GREATER } by setting the protected property {@link GREATER.equivalent }, {@link GREATER.equalityPermitted } and {@link GREATER.invert } used by {@link GREATER.check }.
115
+ *
116
+ * @param equivalent See {@link GREATER.check }.
117
+ * @param equalityPermitted See {@link GREATER.check }.
118
+ * @param invert See {@link GREATER.check }. */
119
+ constructor(
120
+ public equivalent,
121
+ public equalityPermitted = false,
122
+ public invert = false,
123
+ ) {
124
+ super();
125
+ }
126
+ // #endregion Dynamic usage.
127
+ }
package/src/DBC/REGEX.ts CHANGED
@@ -7,6 +7,7 @@ import { DBC } from "../DBC.js";
7
7
  export class REGEX extends DBC {
8
8
  /** Stores often used {@link RegExp }s. */
9
9
  public static stdExp = {
10
+ eMail: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/i,
10
11
  property: /^[$_A-Za-z][$_A-Za-z0-9]*$/,
11
12
  url: /^(?:(?:http:|https?|ftp):\/\/)?(?:\S+(?::\S*)?@)?(?:localhost|(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,})(?::\d{2,5})?(?:\/(?:[\w\-\.]*\/)*[\w\-\.]+(?:\?\S*)?(?:#\S*)?)?$/i,
12
13
  keyPath: /^([a-zA-Z_$][a-zA-Z0-9_$]*\.)*[a-zA-Z_$][a-zA-Z0-9_$]*$/,