@atlantjs/arch 13.3.0 → 14.0.1
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/@tool-box/utils/datatypes/boolean-utils.d.ts +7 -0
- package/@tool-box/utils/datatypes/boolean-utils.js +146 -4
- package/@tool-box/utils/datatypes/string-utils.d.ts +32 -4
- package/@tool-box/utils/datatypes/string-utils.js +303 -14
- package/@tool-box/utils/ducts/common.d.ts +49 -0
- package/@tool-box/utils/ducts/common.js +36 -3
- package/@tool-box/utils/ducts/optional-type.d.ts +85 -0
- package/@tool-box/utils/ducts/optional-type.js +79 -0
- package/@tool-box/utils/ducts/return-type.d.ts +17 -17
- package/@tool-box/utils/ducts/return-type.js +14 -4
- package/@tool-box/utils/http-provider/http-provider.d.ts +6 -0
- package/@tool-box/utils/http-provider/http-provider.js +43 -14
- package/@tool-box/utils/map/map.abstract.d.ts +39 -0
- package/@tool-box/utils/map/map.abstract.js +70 -6
- package/@tool-box/utils/random/random.d.ts +168 -0
- package/@tool-box/utils/random/random.js +235 -0
- package/@tool-box/utils/type-guard/guardian.d.ts +450 -7
- package/@tool-box/utils/type-guard/guardian.js +539 -35
- package/objects/@common/edges/cron-expression.edge.d.ts +30 -2
- package/objects/@common/edges/cron-expression.edge.js +77 -5
- package/objects/@common/edges/email.edge.d.ts +39 -1
- package/objects/@common/edges/email.edge.js +80 -2
- package/objects/@common/edges/ulid.sketch.edge.d.ts +48 -1
- package/objects/@common/edges/ulid.sketch.edge.js +75 -4
- package/objects/@common/edges/url.edge.d.ts +182 -0
- package/objects/@common/edges/url.edge.js +249 -0
- package/objects/@common/edges/username.edge.d.ts +9 -0
- package/objects/@common/edges/username.edge.js +34 -0
- package/objects/@common/edges/uuid.sketch.edge.d.ts +97 -1
- package/objects/@common/edges/uuid.sketch.edge.js +127 -6
- package/objects/amount/amount-value.edge.d.ts +39 -0
- package/objects/amount/amount-value.edge.js +69 -0
- package/objects/amount/amount.edge.d.ts +378 -2
- package/objects/amount/amount.edge.js +493 -4
- package/objects/datetime/edges/datetime.edge.d.ts +422 -4
- package/objects/datetime/edges/datetime.edge.js +538 -33
- package/objects/password/password.edge.d.ts +90 -0
- package/objects/password/password.edge.js +140 -6
- package/objects/primitives/boolean.edge.sketch.d.ts +105 -3
- package/objects/primitives/boolean.edge.sketch.js +132 -6
- package/objects/primitives/number.edge.sketch.d.ts +236 -0
- package/objects/primitives/number.edge.sketch.js +310 -24
- package/objects/primitives/string.edge.sketch.d.ts +148 -0
- package/objects/primitives/string.edge.sketch.js +191 -7
- package/objects/schedule/schedule.edge.d.ts +194 -0
- package/objects/schedule/schedule.edge.js +269 -2
- package/objects/time/time.edge.d.ts +285 -2
- package/objects/time/time.edge.js +385 -6
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,8 +1,98 @@
|
|
|
1
1
|
import { PasswordPolicyResultPolygon } from "./password.polygon";
|
|
2
|
+
import { ValidationStepResult } from "./validation-step.type";
|
|
2
3
|
export declare class PasswordEdge {
|
|
3
4
|
private readonly password;
|
|
4
5
|
private readonly validationSteps;
|
|
5
6
|
constructor(password: string);
|
|
6
7
|
protected validate(password: string): PasswordPolicyResultPolygon;
|
|
8
|
+
/**
|
|
9
|
+
* Retorna a senha como string.
|
|
10
|
+
* @returns String interna da senha
|
|
11
|
+
* @example
|
|
12
|
+
* new PasswordEdge("Abc@123").toString() // "Abc@123"
|
|
13
|
+
*/
|
|
7
14
|
toString(): string;
|
|
15
|
+
/**
|
|
16
|
+
* Retorna o comprimento da senha.
|
|
17
|
+
* @returns Número de caracteres da senha
|
|
18
|
+
* @example
|
|
19
|
+
* new PasswordEdge("Abc@123").length() // 7
|
|
20
|
+
*/
|
|
21
|
+
length(): number;
|
|
22
|
+
/**
|
|
23
|
+
* Verifica se a senha contém ao menos uma letra maiúscula.
|
|
24
|
+
* @returns true se contém ao menos uma letra maiúscula, false caso contrário
|
|
25
|
+
* @example
|
|
26
|
+
* new PasswordEdge("Abc@123").hasUpperCase() // true
|
|
27
|
+
* new PasswordEdge("abc@123").hasUpperCase() // false
|
|
28
|
+
*/
|
|
29
|
+
hasUpperCase(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Verifica se a senha contém ao menos uma letra minúscula.
|
|
32
|
+
* @returns true se contém ao menos uma letra minúscula, false caso contrário
|
|
33
|
+
* @example
|
|
34
|
+
* new PasswordEdge("Abc@123").hasLowerCase() // true
|
|
35
|
+
* new PasswordEdge("ABC@123").hasLowerCase() // false
|
|
36
|
+
*/
|
|
37
|
+
hasLowerCase(): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Verifica se a senha contém ao menos um dígito numérico.
|
|
40
|
+
* @returns true se contém ao menos um número, false caso contrário
|
|
41
|
+
* @example
|
|
42
|
+
* new PasswordEdge("Abc@123").hasNumber() // true
|
|
43
|
+
* new PasswordEdge("Abcdef@").hasNumber() // false
|
|
44
|
+
*/
|
|
45
|
+
hasNumber(): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Verifica se a senha contém ao menos um caractere especial.
|
|
48
|
+
* @returns true se contém ao menos um caractere especial, false caso contrário
|
|
49
|
+
* @example
|
|
50
|
+
* new PasswordEdge("Abc@123").hasSpecialChar() // true
|
|
51
|
+
* new PasswordEdge("Abc1234").hasSpecialChar() // false
|
|
52
|
+
*/
|
|
53
|
+
hasSpecialChar(): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Verifica se a senha contém espaços.
|
|
56
|
+
* @returns true se contém ao menos um espaço, false caso contrário
|
|
57
|
+
* @example
|
|
58
|
+
* new PasswordEdge("Abc @123").hasWhitespace() // true
|
|
59
|
+
* new PasswordEdge("Abc@123").hasWhitespace() // false
|
|
60
|
+
*/
|
|
61
|
+
hasWhitespace(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Verifica se a senha é igual a outra.
|
|
64
|
+
* @param password - String ou PasswordEdge para comparação
|
|
65
|
+
* @returns true se as senhas são iguais, false caso contrário
|
|
66
|
+
* @example
|
|
67
|
+
* new PasswordEdge("Abc@123").isEqual(new PasswordEdge("Abc@123")) // true
|
|
68
|
+
* new PasswordEdge("Abc@123").isEqual("Abc@123") // true
|
|
69
|
+
* new PasswordEdge("Abc@123").isEqual("xyz@999") // false
|
|
70
|
+
*/
|
|
71
|
+
isEqual(password: string | PasswordEdge): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Avalia a força da senha com base em critérios de complexidade.
|
|
74
|
+
* @returns "weak" | "medium" | "strong" conforme a pontuação
|
|
75
|
+
* @example
|
|
76
|
+
* new PasswordEdge("abc@123").strength() // "weak"
|
|
77
|
+
* new PasswordEdge("Abcd@123").strength() // "medium"
|
|
78
|
+
* new PasswordEdge("Abcd@1234!X").strength() // "strong"
|
|
79
|
+
*/
|
|
80
|
+
strength(): "weak" | "medium" | "strong";
|
|
81
|
+
/**
|
|
82
|
+
* Retorna o resultado detalhado de cada etapa de validação da senha.
|
|
83
|
+
* @returns Array com o resultado de cada ValidationStep
|
|
84
|
+
* @example
|
|
85
|
+
* new PasswordEdge("Abc@123").validationResults()
|
|
86
|
+
* // [{ name: "WithAtLeastOneLetterStep", valid: true }, ...]
|
|
87
|
+
*/
|
|
88
|
+
validationResults(): ValidationStepResult[];
|
|
89
|
+
/**
|
|
90
|
+
* Verifica se uma string é uma senha válida sem lançar exceção.
|
|
91
|
+
* @param password - String a ser verificada
|
|
92
|
+
* @returns true se a senha é válida, false caso contrário
|
|
93
|
+
* @example
|
|
94
|
+
* PasswordEdge.isValid("Abc@123") // true
|
|
95
|
+
* PasswordEdge.isValid("abc") // false
|
|
96
|
+
*/
|
|
97
|
+
static isValid(password: string): boolean;
|
|
8
98
|
}
|
|
@@ -16,8 +16,9 @@ class PasswordEdge {
|
|
|
16
16
|
new with_length_step_1.WithLengthStep({ min: 6, max: 999 }),
|
|
17
17
|
];
|
|
18
18
|
const { valid, validationStepsResults } = this.validate(this.password);
|
|
19
|
-
if (valid
|
|
20
|
-
|
|
19
|
+
if (!valid) {
|
|
20
|
+
// 🐛 fix: valid é boolean, não tem método .falsy()
|
|
21
|
+
throw new TypeError(`Password is invalid: ${validationStepsResults.map((result) => result.name).join(", ")}`);
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
validate(password) {
|
|
@@ -29,13 +30,146 @@ class PasswordEdge {
|
|
|
29
30
|
validationStepsResults.push(step.validate(password));
|
|
30
31
|
}
|
|
31
32
|
const valid = validationStepsResults.every((result) => result.valid);
|
|
32
|
-
return {
|
|
33
|
-
valid,
|
|
34
|
-
validationStepsResults,
|
|
35
|
-
};
|
|
33
|
+
return { valid, validationStepsResults };
|
|
36
34
|
}
|
|
35
|
+
// ==================== Getters ====================
|
|
36
|
+
/**
|
|
37
|
+
* Retorna a senha como string.
|
|
38
|
+
* @returns String interna da senha
|
|
39
|
+
* @example
|
|
40
|
+
* new PasswordEdge("Abc@123").toString() // "Abc@123"
|
|
41
|
+
*/
|
|
37
42
|
toString() {
|
|
38
43
|
return this.password;
|
|
39
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Retorna o comprimento da senha.
|
|
47
|
+
* @returns Número de caracteres da senha
|
|
48
|
+
* @example
|
|
49
|
+
* new PasswordEdge("Abc@123").length() // 7
|
|
50
|
+
*/
|
|
51
|
+
length() {
|
|
52
|
+
return this.password.length;
|
|
53
|
+
}
|
|
54
|
+
// ==================== Verificações ====================
|
|
55
|
+
/**
|
|
56
|
+
* Verifica se a senha contém ao menos uma letra maiúscula.
|
|
57
|
+
* @returns true se contém ao menos uma letra maiúscula, false caso contrário
|
|
58
|
+
* @example
|
|
59
|
+
* new PasswordEdge("Abc@123").hasUpperCase() // true
|
|
60
|
+
* new PasswordEdge("abc@123").hasUpperCase() // false
|
|
61
|
+
*/
|
|
62
|
+
hasUpperCase() {
|
|
63
|
+
return /[A-Z]/.test(this.password);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Verifica se a senha contém ao menos uma letra minúscula.
|
|
67
|
+
* @returns true se contém ao menos uma letra minúscula, false caso contrário
|
|
68
|
+
* @example
|
|
69
|
+
* new PasswordEdge("Abc@123").hasLowerCase() // true
|
|
70
|
+
* new PasswordEdge("ABC@123").hasLowerCase() // false
|
|
71
|
+
*/
|
|
72
|
+
hasLowerCase() {
|
|
73
|
+
return /[a-z]/.test(this.password);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Verifica se a senha contém ao menos um dígito numérico.
|
|
77
|
+
* @returns true se contém ao menos um número, false caso contrário
|
|
78
|
+
* @example
|
|
79
|
+
* new PasswordEdge("Abc@123").hasNumber() // true
|
|
80
|
+
* new PasswordEdge("Abcdef@").hasNumber() // false
|
|
81
|
+
*/
|
|
82
|
+
hasNumber() {
|
|
83
|
+
return /[0-9]/.test(this.password);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Verifica se a senha contém ao menos um caractere especial.
|
|
87
|
+
* @returns true se contém ao menos um caractere especial, false caso contrário
|
|
88
|
+
* @example
|
|
89
|
+
* new PasswordEdge("Abc@123").hasSpecialChar() // true
|
|
90
|
+
* new PasswordEdge("Abc1234").hasSpecialChar() // false
|
|
91
|
+
*/
|
|
92
|
+
hasSpecialChar() {
|
|
93
|
+
return /[^a-zA-Z0-9]/.test(this.password);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Verifica se a senha contém espaços.
|
|
97
|
+
* @returns true se contém ao menos um espaço, false caso contrário
|
|
98
|
+
* @example
|
|
99
|
+
* new PasswordEdge("Abc @123").hasWhitespace() // true
|
|
100
|
+
* new PasswordEdge("Abc@123").hasWhitespace() // false
|
|
101
|
+
*/
|
|
102
|
+
hasWhitespace() {
|
|
103
|
+
return /\s/.test(this.password);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Verifica se a senha é igual a outra.
|
|
107
|
+
* @param password - String ou PasswordEdge para comparação
|
|
108
|
+
* @returns true se as senhas são iguais, false caso contrário
|
|
109
|
+
* @example
|
|
110
|
+
* new PasswordEdge("Abc@123").isEqual(new PasswordEdge("Abc@123")) // true
|
|
111
|
+
* new PasswordEdge("Abc@123").isEqual("Abc@123") // true
|
|
112
|
+
* new PasswordEdge("Abc@123").isEqual("xyz@999") // false
|
|
113
|
+
*/
|
|
114
|
+
isEqual(password) {
|
|
115
|
+
const comparand = password instanceof PasswordEdge ? password.toString() : password;
|
|
116
|
+
return this.password === comparand;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Avalia a força da senha com base em critérios de complexidade.
|
|
120
|
+
* @returns "weak" | "medium" | "strong" conforme a pontuação
|
|
121
|
+
* @example
|
|
122
|
+
* new PasswordEdge("abc@123").strength() // "weak"
|
|
123
|
+
* new PasswordEdge("Abcd@123").strength() // "medium"
|
|
124
|
+
* new PasswordEdge("Abcd@1234!X").strength() // "strong"
|
|
125
|
+
*/
|
|
126
|
+
strength() {
|
|
127
|
+
let score = 0;
|
|
128
|
+
if (this.hasUpperCase())
|
|
129
|
+
score++;
|
|
130
|
+
if (this.hasLowerCase())
|
|
131
|
+
score++;
|
|
132
|
+
if (this.hasNumber())
|
|
133
|
+
score++;
|
|
134
|
+
if (this.hasSpecialChar())
|
|
135
|
+
score++;
|
|
136
|
+
if (this.password.length >= 10)
|
|
137
|
+
score++;
|
|
138
|
+
if (this.password.length >= 16)
|
|
139
|
+
score++;
|
|
140
|
+
if (score <= 2)
|
|
141
|
+
return "weak";
|
|
142
|
+
if (score <= 4)
|
|
143
|
+
return "medium";
|
|
144
|
+
return "strong";
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Retorna o resultado detalhado de cada etapa de validação da senha.
|
|
148
|
+
* @returns Array com o resultado de cada ValidationStep
|
|
149
|
+
* @example
|
|
150
|
+
* new PasswordEdge("Abc@123").validationResults()
|
|
151
|
+
* // [{ name: "WithAtLeastOneLetterStep", valid: true }, ...]
|
|
152
|
+
*/
|
|
153
|
+
validationResults() {
|
|
154
|
+
return this.validate(this.password).validationStepsResults;
|
|
155
|
+
}
|
|
156
|
+
// ==================== Métodos Estáticos ====================
|
|
157
|
+
/**
|
|
158
|
+
* Verifica se uma string é uma senha válida sem lançar exceção.
|
|
159
|
+
* @param password - String a ser verificada
|
|
160
|
+
* @returns true se a senha é válida, false caso contrário
|
|
161
|
+
* @example
|
|
162
|
+
* PasswordEdge.isValid("Abc@123") // true
|
|
163
|
+
* PasswordEdge.isValid("abc") // false
|
|
164
|
+
*/
|
|
165
|
+
static isValid(password) {
|
|
166
|
+
try {
|
|
167
|
+
new PasswordEdge(password);
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
40
174
|
}
|
|
41
175
|
exports.PasswordEdge = PasswordEdge;
|
|
@@ -1,7 +1,109 @@
|
|
|
1
1
|
export declare abstract class BooleanEdgeSketch {
|
|
2
2
|
private value;
|
|
3
3
|
constructor(value: boolean);
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Retorna o valor booleano interno.
|
|
6
|
+
* @returns Booleano interno do edge
|
|
7
|
+
* @example
|
|
8
|
+
* new MyBooleanEdge(true).toPoint() // true
|
|
9
|
+
*/
|
|
10
|
+
toBoolean(): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Retorna o valor como string.
|
|
13
|
+
* @returns "true" ou "false"
|
|
14
|
+
* @example
|
|
15
|
+
* new MyBooleanEdge(true).toString() // "true"
|
|
16
|
+
* new MyBooleanEdge(false).toString() // "false"
|
|
17
|
+
*/
|
|
18
|
+
toString(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Retorna o valor como número (1 para true, 0 para false).
|
|
21
|
+
* @returns 1 se true, 0 se false
|
|
22
|
+
* @example
|
|
23
|
+
* new MyBooleanEdge(true).toNumber() // 1
|
|
24
|
+
* new MyBooleanEdge(false).toNumber() // 0
|
|
25
|
+
*/
|
|
26
|
+
toNumber(): number;
|
|
27
|
+
/**
|
|
28
|
+
* Verifica se este valor é igual a outro.
|
|
29
|
+
* @param value - Booleano ou BooleanEdgeSketch para comparação
|
|
30
|
+
* @returns true se os valores são iguais, false caso contrário
|
|
31
|
+
* @example
|
|
32
|
+
* new MyBooleanEdge(true).isEqual(true) // true
|
|
33
|
+
* new MyBooleanEdge(true).isEqual(false) // false
|
|
34
|
+
*/
|
|
35
|
+
isEqual(value: boolean | BooleanEdgeSketch): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Verifica se este valor é diferente de outro.
|
|
38
|
+
* @param value - Booleano ou BooleanEdgeSketch para comparação
|
|
39
|
+
* @returns true se os valores são diferentes, false caso contrário
|
|
40
|
+
* @example
|
|
41
|
+
* new MyBooleanEdge(true).isDifferent(false) // true
|
|
42
|
+
* new MyBooleanEdge(true).isDifferent(true) // false
|
|
43
|
+
*/
|
|
44
|
+
isDifferent(value: boolean | BooleanEdgeSketch): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Verifica se o valor é true.
|
|
47
|
+
* @returns true se o valor interno é true, false caso contrário
|
|
48
|
+
* @example
|
|
49
|
+
* new MyBooleanEdge(true).isTrue() // true
|
|
50
|
+
* new MyBooleanEdge(false).isTrue() // false
|
|
51
|
+
*/
|
|
52
|
+
isTrue(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Verifica se o valor é false.
|
|
55
|
+
* @returns true se o valor interno é false, false caso contrário
|
|
56
|
+
* @example
|
|
57
|
+
* new MyBooleanEdge(false).isFalse() // true
|
|
58
|
+
* new MyBooleanEdge(true).isFalse() // false
|
|
59
|
+
*/
|
|
60
|
+
isFalse(): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Retorna o valor negado (NOT lógico).
|
|
63
|
+
* @returns Negação do valor interno
|
|
64
|
+
* @example
|
|
65
|
+
* new MyBooleanEdge(true).negate() // false
|
|
66
|
+
* new MyBooleanEdge(false).negate() // true
|
|
67
|
+
*/
|
|
68
|
+
negate(): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Realiza AND lógico entre este valor e outro.
|
|
71
|
+
* @param value - Booleano ou BooleanEdgeSketch para operação
|
|
72
|
+
* @returns Resultado do AND lógico
|
|
73
|
+
* @example
|
|
74
|
+
* new MyBooleanEdge(true).and(true) // true
|
|
75
|
+
* new MyBooleanEdge(true).and(false) // false
|
|
76
|
+
* new MyBooleanEdge(false).and(true) // false
|
|
77
|
+
*/
|
|
78
|
+
and(value: boolean | BooleanEdgeSketch): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Realiza OR lógico entre este valor e outro.
|
|
81
|
+
* @param value - Booleano ou BooleanEdgeSketch para operação
|
|
82
|
+
* @returns Resultado do OR lógico
|
|
83
|
+
* @example
|
|
84
|
+
* new MyBooleanEdge(true).or(false) // true
|
|
85
|
+
* new MyBooleanEdge(false).or(false) // false
|
|
86
|
+
* new MyBooleanEdge(false).or(true) // true
|
|
87
|
+
*/
|
|
88
|
+
or(value: boolean | BooleanEdgeSketch): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Realiza XOR lógico (OU exclusivo) entre este valor e outro.
|
|
91
|
+
* @param value - Booleano ou BooleanEdgeSketch para operação
|
|
92
|
+
* @returns true se os valores são diferentes, false se iguais
|
|
93
|
+
* @example
|
|
94
|
+
* new MyBooleanEdge(true).xor(false) // true
|
|
95
|
+
* new MyBooleanEdge(true).xor(true) // false
|
|
96
|
+
* new MyBooleanEdge(false).xor(false) // false
|
|
97
|
+
*/
|
|
98
|
+
xor(value: boolean | BooleanEdgeSketch): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Retorna um valor baseado no estado booleano (ternário tipado).
|
|
101
|
+
* @param onTrue - Valor retornado se true
|
|
102
|
+
* @param onFalse - Valor retornado se false
|
|
103
|
+
* @returns onTrue se value é true, onFalse caso contrário
|
|
104
|
+
* @example
|
|
105
|
+
* new MyBooleanEdge(true).fold("yes", "no") // "yes"
|
|
106
|
+
* new MyBooleanEdge(false).fold("yes", "no") // "no"
|
|
107
|
+
*/
|
|
108
|
+
fold<T>(onTrue: T, onFalse: T): T;
|
|
7
109
|
}
|
|
@@ -5,17 +5,143 @@ class BooleanEdgeSketch {
|
|
|
5
5
|
constructor(value) {
|
|
6
6
|
this.value = value;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
// ==================== Getters ====================
|
|
9
|
+
/**
|
|
10
|
+
* Retorna o valor booleano interno.
|
|
11
|
+
* @returns Booleano interno do edge
|
|
12
|
+
* @example
|
|
13
|
+
* new MyBooleanEdge(true).toPoint() // true
|
|
14
|
+
*/
|
|
15
|
+
toBoolean() {
|
|
9
16
|
return this.value;
|
|
10
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Retorna o valor como string.
|
|
20
|
+
* @returns "true" ou "false"
|
|
21
|
+
* @example
|
|
22
|
+
* new MyBooleanEdge(true).toString() // "true"
|
|
23
|
+
* new MyBooleanEdge(false).toString() // "false"
|
|
24
|
+
*/
|
|
25
|
+
toString() {
|
|
26
|
+
return String(this.value);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Retorna o valor como número (1 para true, 0 para false).
|
|
30
|
+
* @returns 1 se true, 0 se false
|
|
31
|
+
* @example
|
|
32
|
+
* new MyBooleanEdge(true).toNumber() // 1
|
|
33
|
+
* new MyBooleanEdge(false).toNumber() // 0
|
|
34
|
+
*/
|
|
35
|
+
toNumber() {
|
|
36
|
+
return this.value ? 1 : 0;
|
|
37
|
+
}
|
|
38
|
+
// ==================== Comparações ====================
|
|
39
|
+
/**
|
|
40
|
+
* Verifica se este valor é igual a outro.
|
|
41
|
+
* @param value - Booleano ou BooleanEdgeSketch para comparação
|
|
42
|
+
* @returns true se os valores são iguais, false caso contrário
|
|
43
|
+
* @example
|
|
44
|
+
* new MyBooleanEdge(true).isEqual(true) // true
|
|
45
|
+
* new MyBooleanEdge(true).isEqual(false) // false
|
|
46
|
+
*/
|
|
11
47
|
isEqual(value) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
return this.value === value;
|
|
48
|
+
const comparand = value instanceof BooleanEdgeSketch ? value.toBoolean() : value;
|
|
49
|
+
return this.value === comparand;
|
|
16
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Verifica se este valor é diferente de outro.
|
|
53
|
+
* @param value - Booleano ou BooleanEdgeSketch para comparação
|
|
54
|
+
* @returns true se os valores são diferentes, false caso contrário
|
|
55
|
+
* @example
|
|
56
|
+
* new MyBooleanEdge(true).isDifferent(false) // true
|
|
57
|
+
* new MyBooleanEdge(true).isDifferent(true) // false
|
|
58
|
+
*/
|
|
17
59
|
isDifferent(value) {
|
|
18
|
-
|
|
60
|
+
const comparand = value instanceof BooleanEdgeSketch ? value.toBoolean() : value;
|
|
61
|
+
return this.value !== comparand;
|
|
62
|
+
}
|
|
63
|
+
// ==================== Verificações ====================
|
|
64
|
+
/**
|
|
65
|
+
* Verifica se o valor é true.
|
|
66
|
+
* @returns true se o valor interno é true, false caso contrário
|
|
67
|
+
* @example
|
|
68
|
+
* new MyBooleanEdge(true).isTrue() // true
|
|
69
|
+
* new MyBooleanEdge(false).isTrue() // false
|
|
70
|
+
*/
|
|
71
|
+
isTrue() {
|
|
72
|
+
return this.value === true;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Verifica se o valor é false.
|
|
76
|
+
* @returns true se o valor interno é false, false caso contrário
|
|
77
|
+
* @example
|
|
78
|
+
* new MyBooleanEdge(false).isFalse() // true
|
|
79
|
+
* new MyBooleanEdge(true).isFalse() // false
|
|
80
|
+
*/
|
|
81
|
+
isFalse() {
|
|
82
|
+
return this.value === false;
|
|
83
|
+
}
|
|
84
|
+
// ==================== Operações Lógicas ====================
|
|
85
|
+
/**
|
|
86
|
+
* Retorna o valor negado (NOT lógico).
|
|
87
|
+
* @returns Negação do valor interno
|
|
88
|
+
* @example
|
|
89
|
+
* new MyBooleanEdge(true).negate() // false
|
|
90
|
+
* new MyBooleanEdge(false).negate() // true
|
|
91
|
+
*/
|
|
92
|
+
negate() {
|
|
93
|
+
return !this.value;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Realiza AND lógico entre este valor e outro.
|
|
97
|
+
* @param value - Booleano ou BooleanEdgeSketch para operação
|
|
98
|
+
* @returns Resultado do AND lógico
|
|
99
|
+
* @example
|
|
100
|
+
* new MyBooleanEdge(true).and(true) // true
|
|
101
|
+
* new MyBooleanEdge(true).and(false) // false
|
|
102
|
+
* new MyBooleanEdge(false).and(true) // false
|
|
103
|
+
*/
|
|
104
|
+
and(value) {
|
|
105
|
+
const operand = value instanceof BooleanEdgeSketch ? value.toBoolean() : value;
|
|
106
|
+
return this.value && operand;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Realiza OR lógico entre este valor e outro.
|
|
110
|
+
* @param value - Booleano ou BooleanEdgeSketch para operação
|
|
111
|
+
* @returns Resultado do OR lógico
|
|
112
|
+
* @example
|
|
113
|
+
* new MyBooleanEdge(true).or(false) // true
|
|
114
|
+
* new MyBooleanEdge(false).or(false) // false
|
|
115
|
+
* new MyBooleanEdge(false).or(true) // true
|
|
116
|
+
*/
|
|
117
|
+
or(value) {
|
|
118
|
+
const operand = value instanceof BooleanEdgeSketch ? value.toBoolean() : value;
|
|
119
|
+
return this.value || operand;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Realiza XOR lógico (OU exclusivo) entre este valor e outro.
|
|
123
|
+
* @param value - Booleano ou BooleanEdgeSketch para operação
|
|
124
|
+
* @returns true se os valores são diferentes, false se iguais
|
|
125
|
+
* @example
|
|
126
|
+
* new MyBooleanEdge(true).xor(false) // true
|
|
127
|
+
* new MyBooleanEdge(true).xor(true) // false
|
|
128
|
+
* new MyBooleanEdge(false).xor(false) // false
|
|
129
|
+
*/
|
|
130
|
+
xor(value) {
|
|
131
|
+
const operand = value instanceof BooleanEdgeSketch ? value.toBoolean() : value;
|
|
132
|
+
return this.value !== operand;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Retorna um valor baseado no estado booleano (ternário tipado).
|
|
136
|
+
* @param onTrue - Valor retornado se true
|
|
137
|
+
* @param onFalse - Valor retornado se false
|
|
138
|
+
* @returns onTrue se value é true, onFalse caso contrário
|
|
139
|
+
* @example
|
|
140
|
+
* new MyBooleanEdge(true).fold("yes", "no") // "yes"
|
|
141
|
+
* new MyBooleanEdge(false).fold("yes", "no") // "no"
|
|
142
|
+
*/
|
|
143
|
+
fold(onTrue, onFalse) {
|
|
144
|
+
return this.value ? onTrue : onFalse;
|
|
19
145
|
}
|
|
20
146
|
}
|
|
21
147
|
exports.BooleanEdgeSketch = BooleanEdgeSketch;
|