xdbc 1.0.209 → 1.0.211
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/__tests__/DBC/IF.test.ts +10 -0
- package/__tests__/DBC/REGEX.test.ts +4 -0
- package/package.json +1 -1
- package/src/DBC/IF.ts +2 -0
- package/src/DBC/REGEX.ts +1 -1
package/__tests__/DBC/IF.test.ts
CHANGED
|
@@ -48,5 +48,15 @@ describe("IF", () => {
|
|
|
48
48
|
test("Should return true when both condition and inCase pass", () => {
|
|
49
49
|
expect(IF.checkAlgorithm("hello", isString, eqHello)).toBe(true);
|
|
50
50
|
});
|
|
51
|
+
|
|
52
|
+
test("Should return true when toCheck is undefined", () => {
|
|
53
|
+
expect(IF.checkAlgorithm(undefined, isString, eqHello)).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("Should return true when toCheck is null", () => {
|
|
57
|
+
expect(IF.checkAlgorithm(null, isString, eqHello)).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
|
|
51
61
|
});
|
|
52
62
|
});
|
|
@@ -10,4 +10,8 @@ describe("REGEX", () => {
|
|
|
10
10
|
test("Should report infringement with 'c' to check", () => {
|
|
11
11
|
expect(typeof regex.check("c")).toBe("string");
|
|
12
12
|
});
|
|
13
|
+
|
|
14
|
+
test("Should not report infringement with empty string", () => {
|
|
15
|
+
expect(regex.check("")).toBe(true);
|
|
16
|
+
});
|
|
13
17
|
});
|
package/package.json
CHANGED
package/src/DBC/IF.ts
CHANGED
|
@@ -24,6 +24,8 @@ export class IF extends DBC {
|
|
|
24
24
|
},
|
|
25
25
|
invert: boolean = false,
|
|
26
26
|
): boolean | string {
|
|
27
|
+
if (toCheck === undefined || toCheck === null) return true;
|
|
28
|
+
|
|
27
29
|
if (invert && condition.check(toCheck) !== true && inCase.check(toCheck) !== true) {
|
|
28
30
|
return `In case that the value does not comply to the condition, it also has to comply to the required contract`;
|
|
29
31
|
}
|
package/src/DBC/REGEX.ts
CHANGED
|
@@ -55,7 +55,7 @@ export class REGEX extends DBC {
|
|
|
55
55
|
toCheck: unknown | null | undefined,
|
|
56
56
|
expression: RegExp,
|
|
57
57
|
): boolean | string {
|
|
58
|
-
if (toCheck === undefined || toCheck === null) return true;
|
|
58
|
+
if (toCheck === undefined || toCheck === null || toCheck === "") return true;
|
|
59
59
|
|
|
60
60
|
if (!expression.test(toCheck as string)) {
|
|
61
61
|
return `Value has to comply to regular expression "${expression}"`;
|