@atlantjs/arch 13.2.0 → 14.0.0
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/convert-units/convert-units.d.ts +14 -5
- package/@tool-box/utils/convert-units/convert-units.js +100 -8
- 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 +20 -4
- package/@tool-box/utils/datatypes/string-utils.js +300 -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 +42 -0
- package/objects/amount/amount-value.edge.js +76 -0
- package/objects/amount/amount.edge.d.ts +389 -11
- package/objects/amount/amount.edge.js +543 -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
|
@@ -3,18 +3,209 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports._ = void 0;
|
|
4
4
|
const guardian_exception_1 = require("./guardian-exception");
|
|
5
5
|
class Guardian {
|
|
6
|
+
// ==================== Operações Lógicas ====================
|
|
7
|
+
/**
|
|
8
|
+
* Verifica se todos os valores booleanos passados são verdadeiros.
|
|
9
|
+
* @param args - Valores booleanos a serem verificados
|
|
10
|
+
* @returns true se todos os valores são true, false caso contrário
|
|
11
|
+
* @example
|
|
12
|
+
* Guardian.and(true, true, true) // true
|
|
13
|
+
* Guardian.and(true, false, true) // false
|
|
14
|
+
*/
|
|
6
15
|
static and(...args) {
|
|
7
16
|
return args.every((func) => func);
|
|
8
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Verifica se pelo menos um dos valores booleanos passados é verdadeiro.
|
|
20
|
+
* @param args - Valores booleanos a serem verificados
|
|
21
|
+
* @returns true se pelo menos um valor é true, false caso contrário
|
|
22
|
+
* @example
|
|
23
|
+
* Guardian.or(false, false, true) // true
|
|
24
|
+
* Guardian.or(false, false, false) // false
|
|
25
|
+
*/
|
|
9
26
|
static or(...args) {
|
|
10
27
|
return args.some((func) => func);
|
|
11
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Retorna um valor baseado em uma condição booleana (ternário).
|
|
31
|
+
* @template TTrue - Tipo do valor a retornar se a condição for verdadeira
|
|
32
|
+
* @template TFalse - Tipo do valor a retornar se a condição for falsa
|
|
33
|
+
* @param condition - Condição a ser avaliada
|
|
34
|
+
* @param returnIfTrue - Valor retornado quando a condição é true
|
|
35
|
+
* @param returnIfFalse - Valor retornado quando a condição é false
|
|
36
|
+
* @returns O valor correspondente à condição
|
|
37
|
+
* @example
|
|
38
|
+
* Guardian.ternaryCondition(5 > 3, "maior", "menor") // "maior"
|
|
39
|
+
*/
|
|
40
|
+
static ternaryCondition(condition, returnIfTrue, returnIfFalse) {
|
|
41
|
+
return condition ? returnIfTrue : returnIfFalse;
|
|
42
|
+
}
|
|
43
|
+
// ==================== Comparações Numéricas ====================
|
|
44
|
+
/**
|
|
45
|
+
* Verifica se um número é maior que uma referência.
|
|
46
|
+
* @param value - Valor a ser comparado
|
|
47
|
+
* @param reference - Valor de referência para comparação
|
|
48
|
+
* @returns true se value > reference, false caso contrário
|
|
49
|
+
* @example
|
|
50
|
+
* Guardian.greaterThan(10, 5) // true
|
|
51
|
+
*/
|
|
12
52
|
static greaterThan(value, reference) {
|
|
13
53
|
return value > reference;
|
|
14
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Verifica se um número é menor que uma referência.
|
|
57
|
+
* @param value - Valor a ser comparado
|
|
58
|
+
* @param reference - Valor de referência para comparação
|
|
59
|
+
* @returns true se value < reference, false caso contrário
|
|
60
|
+
* @example
|
|
61
|
+
* Guardian.lessThan(3, 5) // true
|
|
62
|
+
*/
|
|
15
63
|
static lessThan(value, reference) {
|
|
16
64
|
return value < reference;
|
|
17
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Verifica se um número é maior ou igual a uma referência.
|
|
68
|
+
* @param value - Valor a ser comparado
|
|
69
|
+
* @param reference - Valor de referência para comparação
|
|
70
|
+
* @returns true se value >= reference, false caso contrário
|
|
71
|
+
* @example
|
|
72
|
+
* Guardian.greaterThanOrEqual(5, 5) // true
|
|
73
|
+
*/
|
|
74
|
+
static greaterThanOrEqual(value, reference) {
|
|
75
|
+
return value >= reference;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Verifica se um número é menor ou igual a uma referência.
|
|
79
|
+
* @param value - Valor a ser comparado
|
|
80
|
+
* @param reference - Valor de referência para comparação
|
|
81
|
+
* @returns true se value <= reference, false caso contrário
|
|
82
|
+
* @example
|
|
83
|
+
* Guardian.lessThanOrEqual(5, 5) // true
|
|
84
|
+
*/
|
|
85
|
+
static lessThanOrEqual(value, reference) {
|
|
86
|
+
return value <= reference;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Verifica se um valor numérico está entre um mínimo e máximo (inclusive).
|
|
90
|
+
* @param value - Valor numérico ou string a ser verificado
|
|
91
|
+
* @param min - Valor mínimo da faixa
|
|
92
|
+
* @param max - Valor máximo da faixa
|
|
93
|
+
* @returns true se value está entre min e max, false caso contrário
|
|
94
|
+
* @throws {GuardianException} Se min > max ou se value está vazio
|
|
95
|
+
* @example
|
|
96
|
+
* Guardian.isBetween(5, 1, 10) // true
|
|
97
|
+
* Guardian.isBetween("5", 1, 10) // true
|
|
98
|
+
*/
|
|
99
|
+
static isBetween(value, min, max) {
|
|
100
|
+
if (min > max)
|
|
101
|
+
throw new guardian_exception_1.GuardianException(`Max ${max} should be greater than min ${min}.`);
|
|
102
|
+
if (Guardian.isEmpty(value)) {
|
|
103
|
+
throw new guardian_exception_1.GuardianException("Cannot check length of a value. Provided value is empty");
|
|
104
|
+
}
|
|
105
|
+
const valueLength = Guardian.isNumber(value) ? value : Number(value);
|
|
106
|
+
return valueLength >= min && valueLength <= max;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Verifica se um número é positivo (maior que zero).
|
|
110
|
+
* @param value - Número a ser verificado
|
|
111
|
+
* @returns true se value > 0, false caso contrário
|
|
112
|
+
* @example
|
|
113
|
+
* Guardian.isPositive(5) // true
|
|
114
|
+
* Guardian.isPositive(-5) // false
|
|
115
|
+
*/
|
|
116
|
+
static isPositive(value) {
|
|
117
|
+
return value > 0;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Verifica se um número é negativo (menor que zero).
|
|
121
|
+
* @param value - Número a ser verificado
|
|
122
|
+
* @returns true se value < 0, false caso contrário
|
|
123
|
+
* @example
|
|
124
|
+
* Guardian.isNegative(-5) // true
|
|
125
|
+
* Guardian.isNegative(5) // false
|
|
126
|
+
*/
|
|
127
|
+
static isNegative(value) {
|
|
128
|
+
return value < 0;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Verifica se um número é zero.
|
|
132
|
+
* @param value - Número a ser verificado
|
|
133
|
+
* @returns true se value === 0, false caso contrário
|
|
134
|
+
* @example
|
|
135
|
+
* Guardian.isZero(0) // true
|
|
136
|
+
* Guardian.isZero(5) // false
|
|
137
|
+
*/
|
|
138
|
+
static isZero(value) {
|
|
139
|
+
return value === 0;
|
|
140
|
+
}
|
|
141
|
+
// ==================== Validação de Números ====================
|
|
142
|
+
/**
|
|
143
|
+
* Verifica se um valor é um número inteiro.
|
|
144
|
+
* @param value - Valor a ser verificado
|
|
145
|
+
* @returns true se value é um número inteiro, false caso contrário
|
|
146
|
+
* @example
|
|
147
|
+
* Guardian.isInteger(5) // true
|
|
148
|
+
* Guardian.isInteger(5.5) // false
|
|
149
|
+
*/
|
|
150
|
+
static isInteger(value) {
|
|
151
|
+
return Number.isInteger(value);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Verifica se um valor é um número decimal (ponto flutuante).
|
|
155
|
+
* @param value - Valor a ser verificado
|
|
156
|
+
* @returns true se value é um número decimal, false caso contrário
|
|
157
|
+
* @example
|
|
158
|
+
* Guardian.isFloat(5.5) // true
|
|
159
|
+
* Guardian.isFloat(5) // false
|
|
160
|
+
*/
|
|
161
|
+
static isFloat(value) {
|
|
162
|
+
return typeof value === "number" && !Number.isInteger(value);
|
|
163
|
+
}
|
|
164
|
+
// ==================== Validação de Valores Vazios/Preenchidos ====================
|
|
165
|
+
/**
|
|
166
|
+
* Verifica se um valor está vazio (null, undefined, string vazia, array vazio, objeto vazio).
|
|
167
|
+
* @param value - Valor a ser verificado
|
|
168
|
+
* @returns true se value está vazio, false caso contrário
|
|
169
|
+
* @example
|
|
170
|
+
* Guardian.isEmpty(null) // true
|
|
171
|
+
* Guardian.isEmpty("") // true
|
|
172
|
+
* Guardian.isEmpty([]) // true
|
|
173
|
+
* Guardian.isEmpty({}) // true
|
|
174
|
+
* Guardian.isEmpty("texto") // false
|
|
175
|
+
*/
|
|
176
|
+
static isEmpty(value) {
|
|
177
|
+
if (Guardian.isNullOrUndefined(value)) {
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
if (Guardian.isString(value) || Guardian.isArray(value)) {
|
|
181
|
+
return value.length === 0;
|
|
182
|
+
}
|
|
183
|
+
if (Guardian.isObject(value)) {
|
|
184
|
+
return Object.keys(value).length === 0;
|
|
185
|
+
}
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Verifica se um valor não está vazio.
|
|
190
|
+
* @param value - Valor a ser verificado
|
|
191
|
+
* @returns true se value não está vazio, false caso contrário
|
|
192
|
+
* @example
|
|
193
|
+
* Guardian.isNotEmpty("texto") // true
|
|
194
|
+
* Guardian.isNotEmpty("") // false
|
|
195
|
+
*/
|
|
196
|
+
static isNotEmpty(value) {
|
|
197
|
+
return !Guardian.isEmpty(value);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Verifica se um array está vazio.
|
|
201
|
+
* @template T - Tipo dos elementos do array
|
|
202
|
+
* @param value - Array a ser verificado
|
|
203
|
+
* @returns true se o array está vazio, false caso contrário
|
|
204
|
+
* @throws {GuardianException} Se value não for um array
|
|
205
|
+
* @example
|
|
206
|
+
* Guardian.isEmptyArray([]) // true
|
|
207
|
+
* Guardian.isEmptyArray([1, 2]) // false
|
|
208
|
+
*/
|
|
18
209
|
static isEmptyArray(value) {
|
|
19
210
|
if (Guardian.isArray(value).falsy()) {
|
|
20
211
|
throw new guardian_exception_1.GuardianException("The value is not an array");
|
|
@@ -24,6 +215,16 @@ class Guardian {
|
|
|
24
215
|
}
|
|
25
216
|
return value.length === 0;
|
|
26
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Verifica se um array possui elementos (não está vazio).
|
|
220
|
+
* @template T - Tipo dos elementos do array
|
|
221
|
+
* @param value - Array a ser verificado
|
|
222
|
+
* @returns true se o array possui elementos, false caso contrário
|
|
223
|
+
* @throws {GuardianException} Se value não for um array
|
|
224
|
+
* @example
|
|
225
|
+
* Guardian.isFilledArray([1, 2]) // true
|
|
226
|
+
* Guardian.isFilledArray([]) // false
|
|
227
|
+
*/
|
|
27
228
|
static isFilledArray(value) {
|
|
28
229
|
if (Guardian.isNullOrUndefined(value)) {
|
|
29
230
|
return false;
|
|
@@ -33,42 +234,141 @@ class Guardian {
|
|
|
33
234
|
}
|
|
34
235
|
return value.length !== 0;
|
|
35
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Verifica se um array possui exatamente um comprimento específico.
|
|
239
|
+
* @template T - Tipo dos elementos do array
|
|
240
|
+
* @param value - Array a ser verificado
|
|
241
|
+
* @param reference - Comprimento esperado do array
|
|
242
|
+
* @returns true se o array possui exatamente o comprimento especificado, false caso contrário
|
|
243
|
+
* @throws {GuardianException} Se value não for um array
|
|
244
|
+
* @example
|
|
245
|
+
* Guardian.isLengthArray([1, 2, 3], 3) // true
|
|
246
|
+
* Guardian.isLengthArray([1, 2], 3) // false
|
|
247
|
+
*/
|
|
36
248
|
static isLengthArray(value, reference) {
|
|
37
249
|
if (Guardian.isArray(value).falsy()) {
|
|
38
250
|
throw new guardian_exception_1.GuardianException("The value is not an array");
|
|
39
251
|
}
|
|
40
252
|
return value?.length === reference;
|
|
41
253
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
254
|
+
// ==================== Validação de Nulos e Indefinidos ====================
|
|
255
|
+
/**
|
|
256
|
+
* Verifica se um valor é undefined.
|
|
257
|
+
* @param value - Valor a ser verificado
|
|
258
|
+
* @returns true se value é undefined, false caso contrário
|
|
259
|
+
* @example
|
|
260
|
+
* Guardian.isUndefined(undefined) // true
|
|
261
|
+
* Guardian.isUndefined(null) // false
|
|
262
|
+
*/
|
|
54
263
|
static isUndefined(value) {
|
|
55
264
|
return value === undefined;
|
|
56
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* Verifica se um valor não é undefined.
|
|
268
|
+
* @param value - Valor a ser verificado
|
|
269
|
+
* @returns true se value não é undefined, false caso contrário
|
|
270
|
+
* @example
|
|
271
|
+
* Guardian.isNotUndefined(null) // true
|
|
272
|
+
* Guardian.isNotUndefined(undefined) // false
|
|
273
|
+
*/
|
|
57
274
|
static isNotUndefined(value) {
|
|
58
275
|
return value !== undefined;
|
|
59
276
|
}
|
|
277
|
+
/**
|
|
278
|
+
* Verifica se um valor é null.
|
|
279
|
+
* @param value - Valor a ser verificado
|
|
280
|
+
* @returns true se value é null, false caso contrário
|
|
281
|
+
* @example
|
|
282
|
+
* Guardian.isNull(null) // true
|
|
283
|
+
* Guardian.isNull(undefined) // false
|
|
284
|
+
*/
|
|
60
285
|
static isNull(value) {
|
|
61
286
|
return value === null;
|
|
62
287
|
}
|
|
288
|
+
/**
|
|
289
|
+
* Verifica se um valor não é null.
|
|
290
|
+
* @param value - Valor a ser verificado
|
|
291
|
+
* @returns true se value não é null, false caso contrário
|
|
292
|
+
* @example
|
|
293
|
+
* Guardian.isNotNull(undefined) // true
|
|
294
|
+
* Guardian.isNotNull(null) // false
|
|
295
|
+
*/
|
|
63
296
|
static isNotNull(value) {
|
|
64
297
|
return value !== null;
|
|
65
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* Verifica se um valor é null ou undefined.
|
|
301
|
+
* @param value - Valor a ser verificado
|
|
302
|
+
* @returns true se value é null ou undefined, false caso contrário
|
|
303
|
+
* @example
|
|
304
|
+
* Guardian.isNullOrUndefined(null) // true
|
|
305
|
+
* Guardian.isNullOrUndefined(undefined) // true
|
|
306
|
+
* Guardian.isNullOrUndefined("") // false
|
|
307
|
+
*/
|
|
308
|
+
static isNullOrUndefined(value) {
|
|
309
|
+
if (value === null || value === undefined)
|
|
310
|
+
return true;
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Verifica se um valor não é null e não é undefined.
|
|
315
|
+
* @param value - Valor a ser verificado
|
|
316
|
+
* @returns true se value não é null e não é undefined, false caso contrário
|
|
317
|
+
* @example
|
|
318
|
+
* Guardian.isNotNullOrUndefined("texto") // true
|
|
319
|
+
* Guardian.isNotNullOrUndefined(null) // false
|
|
320
|
+
*/
|
|
321
|
+
static isNotNullOrUndefined(value) {
|
|
322
|
+
if (value === undefined || value === null)
|
|
323
|
+
return false;
|
|
324
|
+
return true;
|
|
325
|
+
}
|
|
326
|
+
// ==================== Comparações de Igualdade ====================
|
|
327
|
+
/**
|
|
328
|
+
* Verifica se dois valores são iguais usando comparação estrita (===).
|
|
329
|
+
* @param valueA - Primeiro valor a ser comparado
|
|
330
|
+
* @param valueB - Segundo valor a ser comparado
|
|
331
|
+
* @returns true se valueA === valueB, false caso contrário
|
|
332
|
+
* @example
|
|
333
|
+
* Guardian.isEqual(5, 5) // true
|
|
334
|
+
* Guardian.isEqual(5, "5") // false
|
|
335
|
+
*/
|
|
66
336
|
static isEqual(valueA, valueB) {
|
|
67
337
|
return valueA === valueB;
|
|
68
338
|
}
|
|
339
|
+
/**
|
|
340
|
+
* Verifica se dois valores são diferentes usando comparação estrita (!==).
|
|
341
|
+
* @param valueA - Primeiro valor a ser comparado
|
|
342
|
+
* @param valueB - Segundo valor a ser comparado
|
|
343
|
+
* @returns true se valueA !== valueB, false caso contrário
|
|
344
|
+
* @example
|
|
345
|
+
* Guardian.isDifferent(5, "5") // true
|
|
346
|
+
* Guardian.isDifferent(5, 5) // false
|
|
347
|
+
*/
|
|
69
348
|
static isDifferent(valueA, valueB) {
|
|
70
349
|
return valueA !== valueB;
|
|
71
350
|
}
|
|
351
|
+
/**
|
|
352
|
+
* Verifica se todos os valores de um array são iguais.
|
|
353
|
+
* @template T - Tipo dos valores no array
|
|
354
|
+
* @param values - Array de valores a ser verificado
|
|
355
|
+
* @returns true se todos os valores são iguais, false caso contrário
|
|
356
|
+
* @example
|
|
357
|
+
* Guardian.allEqual([5, 5, 5]) // true
|
|
358
|
+
* Guardian.allEqual([5, 5, 3]) // false
|
|
359
|
+
*/
|
|
360
|
+
static allEqual(values) {
|
|
361
|
+
return values.every((v) => Guardian.isEqual(v, values[0]));
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Verifica se um valor específico existe em uma coleção de valores.
|
|
365
|
+
* @param reference - Valor a ser procurado
|
|
366
|
+
* @param anyValues - Array de valores onde procurar
|
|
367
|
+
* @returns true se reference existe em anyValues, false caso contrário
|
|
368
|
+
* @example
|
|
369
|
+
* Guardian.isAnyOf(3, [1, 2, 3, 4]) // true
|
|
370
|
+
* Guardian.isAnyOf(5, [1, 2, 3, 4]) // false
|
|
371
|
+
*/
|
|
72
372
|
static isAnyOf(reference, anyValues) {
|
|
73
373
|
for (const value of anyValues) {
|
|
74
374
|
if (Guardian.isEqual(reference, value)) {
|
|
@@ -77,45 +377,249 @@ class Guardian {
|
|
|
77
377
|
}
|
|
78
378
|
return false;
|
|
79
379
|
}
|
|
80
|
-
|
|
81
|
-
|
|
380
|
+
// ==================== Validação de Strings ====================
|
|
381
|
+
/**
|
|
382
|
+
* Verifica se uma string é um endereço de email válido.
|
|
383
|
+
* @param value - String a ser validada como email
|
|
384
|
+
* @returns true se value é um email válido, false caso contrário
|
|
385
|
+
* @example
|
|
386
|
+
* Guardian.isEmail("user@example.com") // true
|
|
387
|
+
* Guardian.isEmail("invalid-email") // false
|
|
388
|
+
*/
|
|
389
|
+
static isEmail(value) {
|
|
390
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
|
|
82
391
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
392
|
+
/**
|
|
393
|
+
* Verifica se uma string é uma URL válida.
|
|
394
|
+
* @param value - String a ser validada como URL
|
|
395
|
+
* @returns true se value é uma URL válida, false caso contrário
|
|
396
|
+
* @example
|
|
397
|
+
* Guardian.isURL("https://example.com") // true
|
|
398
|
+
* Guardian.isURL("not a url") // false
|
|
399
|
+
*/
|
|
400
|
+
static isURL(value) {
|
|
401
|
+
try {
|
|
402
|
+
new URL(value);
|
|
403
|
+
return true;
|
|
404
|
+
}
|
|
405
|
+
catch {
|
|
406
|
+
return false;
|
|
88
407
|
}
|
|
89
|
-
const valueLength = Guardian.isNumber(value) ? value : Number(value);
|
|
90
|
-
return valueLength >= min && valueLength <= max;
|
|
91
408
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
409
|
+
/**
|
|
410
|
+
* Verifica se uma string é um UUID (Universally Unique Identifier) válido.
|
|
411
|
+
* @param value - String a ser validada como UUID
|
|
412
|
+
* @returns true se value é um UUID válido, false caso contrário
|
|
413
|
+
* @example
|
|
414
|
+
* Guardian.isUUID("550e8400-e29b-41d4-a716-446655440000") // true
|
|
415
|
+
* Guardian.isUUID("invalid-uuid") // false
|
|
416
|
+
*/
|
|
417
|
+
static isUUID(value) {
|
|
418
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
|
|
96
419
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
420
|
+
// ==================== Validação de Tipos Compostos ====================
|
|
421
|
+
/**
|
|
422
|
+
* Verifica se um valor é do tipo booleano.
|
|
423
|
+
* @param value - Valor a ser verificado
|
|
424
|
+
* @returns true se value é um booleano, false caso contrário
|
|
425
|
+
* @example
|
|
426
|
+
* Guardian.isBoolean(true) // true
|
|
427
|
+
* Guardian.isBoolean(1) // false
|
|
428
|
+
*/
|
|
429
|
+
static isBoolean(value) {
|
|
430
|
+
return typeof value === "boolean";
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Verifica se um valor é uma função.
|
|
434
|
+
* @param value - Valor a ser verificado
|
|
435
|
+
* @returns true se value é uma função, false caso contrário
|
|
436
|
+
* @example
|
|
437
|
+
* Guardian.isFunction(() => {}) // true
|
|
438
|
+
* Guardian.isFunction("função") // false
|
|
439
|
+
*/
|
|
440
|
+
static isFunction(value) {
|
|
441
|
+
return typeof value === "function";
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Verifica se um valor é um objeto Date válido.
|
|
445
|
+
* @param value - Valor a ser verificado
|
|
446
|
+
* @returns true se value é uma data válida, false caso contrário
|
|
447
|
+
* @example
|
|
448
|
+
* Guardian.isDate(new Date()) // true
|
|
449
|
+
* Guardian.isDate(new Date("invalid")) // false
|
|
450
|
+
* Guardian.isDate("2024-01-01") // false
|
|
451
|
+
*/
|
|
452
|
+
static isDate(value) {
|
|
453
|
+
return value instanceof Date && !Number.isNaN(value.getTime());
|
|
454
|
+
}
|
|
455
|
+
// ==================== Validação de Coleções ====================
|
|
456
|
+
/**
|
|
457
|
+
* Verifica se todos os elementos de um array satisfazem um predicado.
|
|
458
|
+
* @template T - Tipo dos elementos do array
|
|
459
|
+
* @param array - Array a ser verificado
|
|
460
|
+
* @param predicate - Função que retorna true/false para cada elemento
|
|
461
|
+
* @returns true se todos os elementos satisfazem o predicado, false caso contrário
|
|
462
|
+
* @example
|
|
463
|
+
* Guardian.isEveryOf([2, 4, 6], x => x % 2 === 0) // true
|
|
464
|
+
* Guardian.isEveryOf([2, 3, 6], x => x % 2 === 0) // false
|
|
465
|
+
*/
|
|
466
|
+
static isEveryOf(array, predicate) {
|
|
467
|
+
return array.every(predicate);
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Verifica se pelo menos um elemento de um array satisfaz um predicado.
|
|
471
|
+
* @template T - Tipo dos elementos do array
|
|
472
|
+
* @param array - Array a ser verificado
|
|
473
|
+
* @param predicate - Função que retorna true/false para cada elemento
|
|
474
|
+
* @returns true se pelo menos um elemento satisfaz o predicado, false caso contrário
|
|
475
|
+
* @example
|
|
476
|
+
* Guardian.isSomeOf([1, 2, 4], x => x % 2 === 0) // true
|
|
477
|
+
* Guardian.isSomeOf([1, 3, 5], x => x % 2 === 0) // false
|
|
478
|
+
*/
|
|
479
|
+
static isSomeOf(array, predicate) {
|
|
480
|
+
return array.some(predicate);
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Verifica se um valor que possui propriedade length tem exatamente o comprimento específico.
|
|
484
|
+
* @template T - Tipo do valor com propriedade length
|
|
485
|
+
* @param value - Valor a ser verificado
|
|
486
|
+
* @param length - Comprimento esperado
|
|
487
|
+
* @returns true se o comprimento é exatamente o especificado, false caso contrário
|
|
488
|
+
* @example
|
|
489
|
+
* Guardian.hasLength("hello", 5) // true
|
|
490
|
+
* Guardian.hasLength([1, 2, 3], 3) // true
|
|
491
|
+
* Guardian.hasLength([1, 2], 3) // false
|
|
492
|
+
*/
|
|
493
|
+
static hasLength(value, length) {
|
|
494
|
+
return value.length === length;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Verifica se um valor existe dentro de uma coleção.
|
|
498
|
+
* @template T - Tipo dos valores
|
|
499
|
+
* @param value - Valor a ser procurado
|
|
500
|
+
* @param collection - Coleção onde procurar
|
|
501
|
+
* @returns true se value está na coleção, false caso contrário
|
|
502
|
+
* @example
|
|
503
|
+
* Guardian.isWithin(3, [1, 2, 3, 4]) // true
|
|
504
|
+
* Guardian.isWithin(5, [1, 2, 3, 4]) // false
|
|
505
|
+
*/
|
|
506
|
+
static isWithin(value, collection) {
|
|
507
|
+
return collection.includes(value);
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Verifica se um valor não existe dentro de uma coleção.
|
|
511
|
+
* @template T - Tipo dos valores
|
|
512
|
+
* @param value - Valor a ser procurado
|
|
513
|
+
* @param collection - Coleção onde procurar
|
|
514
|
+
* @returns true se value não está na coleção, false caso contrário
|
|
515
|
+
* @example
|
|
516
|
+
* Guardian.isNotWithin(5, [1, 2, 3, 4]) // true
|
|
517
|
+
* Guardian.isNotWithin(3, [1, 2, 3, 4]) // false
|
|
518
|
+
*/
|
|
519
|
+
static isNotWithin(value, collection) {
|
|
520
|
+
return !collection.includes(value);
|
|
521
|
+
}
|
|
522
|
+
// ==================== Validação de Objetos ====================
|
|
523
|
+
/**
|
|
524
|
+
* Verifica se um objeto possui uma propriedade específica (própria ou herdada).
|
|
525
|
+
* @template T - Tipo do objeto
|
|
526
|
+
* @param value - Objeto a ser verificado
|
|
527
|
+
* @param property - Nome da propriedade a procurar
|
|
528
|
+
* @returns true se o objeto possui a propriedade, false caso contrário
|
|
529
|
+
* @example
|
|
530
|
+
* Guardian.hasProperty({ name: "João" }, "name") // true
|
|
531
|
+
* Guardian.hasProperty({ name: "João" }, "age") // false
|
|
532
|
+
*/
|
|
533
|
+
static hasProperty(value, property) {
|
|
534
|
+
return property in value;
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Verifica se um objeto possui uma propriedade própria (não herdada).
|
|
538
|
+
* @template T - Tipo do objeto
|
|
539
|
+
* @param value - Objeto a ser verificado
|
|
540
|
+
* @param property - Nome da propriedade a procurar
|
|
541
|
+
* @returns true se o objeto possui a propriedade própria, false caso contrário
|
|
542
|
+
* @example
|
|
543
|
+
* Guardian.hasOwnProperty({ name: "João" }, "name") // true
|
|
544
|
+
* Guardian.hasOwnProperty({ name: "João" }, "toString") // false
|
|
545
|
+
*/
|
|
546
|
+
static hasOwnProperty(value, property) {
|
|
547
|
+
return Object.prototype.hasOwnProperty.call(value, property);
|
|
548
|
+
}
|
|
549
|
+
// ==================== Validação de Tipos ====================
|
|
550
|
+
/**
|
|
551
|
+
* Verifica se um valor é do tipo primitivo especificado.
|
|
552
|
+
* @template T - Tipo esperado do valor
|
|
553
|
+
* @param value - Valor a ser verificado
|
|
554
|
+
* @param type - Tipo primitivo esperado (string, number, boolean, etc)
|
|
555
|
+
* @returns true se value é do tipo especificado, false caso contrário
|
|
556
|
+
* @example
|
|
557
|
+
* Guardian.isTypeOf("hello", "string") // true
|
|
558
|
+
* Guardian.isTypeOf(42, "number") // true
|
|
559
|
+
* Guardian.isTypeOf(42, "string") // false
|
|
560
|
+
*/
|
|
561
|
+
static isTypeOf(value, type) {
|
|
562
|
+
return Guardian.isEqual(typeof value, type);
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Verifica se um valor não é do tipo primitivo especificado.
|
|
566
|
+
* @template T - Tipo esperado do valor
|
|
567
|
+
* @param value - Valor a ser verificado
|
|
568
|
+
* @param type - Tipo primitivo a ser descartado
|
|
569
|
+
* @returns true se value não é do tipo especificado, false caso contrário
|
|
570
|
+
* @example
|
|
571
|
+
* Guardian.isNotTypeOf(42, "string") // true
|
|
572
|
+
* Guardian.isNotTypeOf("hello", "string") // false
|
|
573
|
+
*/
|
|
574
|
+
static isNotTypeOf(value, type) {
|
|
575
|
+
return Guardian.isDifferent(typeof value, type);
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Verifica se um valor é uma instância de uma classe/construtor específico.
|
|
579
|
+
* @template T - Tipo esperado da instância
|
|
580
|
+
* @param value - Valor a ser verificado
|
|
581
|
+
* @param instance - Construtor/classe a ser verificado
|
|
582
|
+
* @returns true se value é uma instância de instance, false caso contrário
|
|
583
|
+
* @example
|
|
584
|
+
* Guardian.isInstanceOf(new Date(), Date) // true
|
|
585
|
+
* Guardian.isInstanceOf(new Date(), Array) // false
|
|
586
|
+
* Guardian.isInstanceOf(new User(), User) // true
|
|
587
|
+
*/
|
|
588
|
+
static isInstanceOf(value, instance) {
|
|
589
|
+
return value instanceof instance;
|
|
101
590
|
}
|
|
591
|
+
// ==================== Métodos Privados ====================
|
|
592
|
+
/**
|
|
593
|
+
* Verifica se um valor é do tipo numérico.
|
|
594
|
+
* @param value - Valor a ser verificado
|
|
595
|
+
* @returns true se value é um número, false caso contrário
|
|
596
|
+
*/
|
|
102
597
|
static isNumber(value) {
|
|
103
598
|
return typeof value === "number";
|
|
104
599
|
}
|
|
600
|
+
/**
|
|
601
|
+
* Verifica se um valor é do tipo string.
|
|
602
|
+
* @param value - Valor a ser verificado
|
|
603
|
+
* @returns true se value é uma string, false caso contrário
|
|
604
|
+
*/
|
|
105
605
|
static isString(value) {
|
|
106
606
|
return typeof value === "string";
|
|
107
607
|
}
|
|
608
|
+
/**
|
|
609
|
+
* Verifica se um valor é um array.
|
|
610
|
+
* @param value - Valor a ser verificado
|
|
611
|
+
* @returns true se value é um array, false caso contrário
|
|
612
|
+
*/
|
|
108
613
|
static isArray(value) {
|
|
109
614
|
return Array.isArray(value);
|
|
110
615
|
}
|
|
616
|
+
/**
|
|
617
|
+
* Verifica se um valor é um objeto.
|
|
618
|
+
* @param value - Valor a ser verificado
|
|
619
|
+
* @returns true se value é um objeto, false caso contrário
|
|
620
|
+
*/
|
|
111
621
|
static isObject(value) {
|
|
112
622
|
return typeof value === "object";
|
|
113
623
|
}
|
|
114
|
-
static isTypeOf(value, type) {
|
|
115
|
-
return Guardian.isEqual(typeof value, type);
|
|
116
|
-
}
|
|
117
|
-
static isNotTypeOf(value, type) {
|
|
118
|
-
return Guardian.isDifferent(typeof value, type);
|
|
119
|
-
}
|
|
120
624
|
}
|
|
121
625
|
exports._ = Guardian;
|
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
import { StringEdgeSketch } from "../../primitives/string.edge.sketch";
|
|
2
2
|
export declare class CronExpressionEdge extends StringEdgeSketch {
|
|
3
|
-
|
|
4
|
-
constructor(_expression: string);
|
|
3
|
+
constructor(expression: string);
|
|
5
4
|
protected validateCronExpression(): void;
|
|
5
|
+
/**
|
|
6
|
+
* Retorna a expressão cron.
|
|
7
|
+
*/
|
|
8
|
+
toString(): string;
|
|
9
|
+
/**
|
|
10
|
+
* Retorna os campos da expressão cron.
|
|
11
|
+
*/
|
|
12
|
+
getFields(): string[];
|
|
13
|
+
/**
|
|
14
|
+
* Compara com outra expressão cron (string ou edge).
|
|
15
|
+
*/
|
|
16
|
+
isEqual(other: string | CronExpressionEdge): boolean;
|
|
17
|
+
isDifferent(other: string | CronExpressionEdge): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Retorna a próxima execução a partir de uma data base.
|
|
20
|
+
*/
|
|
21
|
+
nextDate(fromDate?: Date): Date;
|
|
22
|
+
/**
|
|
23
|
+
* Retorna a execução anterior a partir de uma data base.
|
|
24
|
+
*/
|
|
25
|
+
previousDate(fromDate?: Date): Date;
|
|
26
|
+
/**
|
|
27
|
+
* Retorna as próximas N execuções.
|
|
28
|
+
*/
|
|
29
|
+
nextDates(count: number, fromDate?: Date): Date[];
|
|
30
|
+
/**
|
|
31
|
+
* Valida expressão cron sem lançar exceção.
|
|
32
|
+
*/
|
|
33
|
+
static isValid(expression: string): boolean;
|
|
6
34
|
}
|