@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.
Files changed (50) hide show
  1. package/@tool-box/utils/datatypes/boolean-utils.d.ts +7 -0
  2. package/@tool-box/utils/datatypes/boolean-utils.js +146 -4
  3. package/@tool-box/utils/datatypes/string-utils.d.ts +32 -4
  4. package/@tool-box/utils/datatypes/string-utils.js +303 -14
  5. package/@tool-box/utils/ducts/common.d.ts +49 -0
  6. package/@tool-box/utils/ducts/common.js +36 -3
  7. package/@tool-box/utils/ducts/optional-type.d.ts +85 -0
  8. package/@tool-box/utils/ducts/optional-type.js +79 -0
  9. package/@tool-box/utils/ducts/return-type.d.ts +17 -17
  10. package/@tool-box/utils/ducts/return-type.js +14 -4
  11. package/@tool-box/utils/http-provider/http-provider.d.ts +6 -0
  12. package/@tool-box/utils/http-provider/http-provider.js +43 -14
  13. package/@tool-box/utils/map/map.abstract.d.ts +39 -0
  14. package/@tool-box/utils/map/map.abstract.js +70 -6
  15. package/@tool-box/utils/random/random.d.ts +168 -0
  16. package/@tool-box/utils/random/random.js +235 -0
  17. package/@tool-box/utils/type-guard/guardian.d.ts +450 -7
  18. package/@tool-box/utils/type-guard/guardian.js +539 -35
  19. package/objects/@common/edges/cron-expression.edge.d.ts +30 -2
  20. package/objects/@common/edges/cron-expression.edge.js +77 -5
  21. package/objects/@common/edges/email.edge.d.ts +39 -1
  22. package/objects/@common/edges/email.edge.js +80 -2
  23. package/objects/@common/edges/ulid.sketch.edge.d.ts +48 -1
  24. package/objects/@common/edges/ulid.sketch.edge.js +75 -4
  25. package/objects/@common/edges/url.edge.d.ts +182 -0
  26. package/objects/@common/edges/url.edge.js +249 -0
  27. package/objects/@common/edges/username.edge.d.ts +9 -0
  28. package/objects/@common/edges/username.edge.js +34 -0
  29. package/objects/@common/edges/uuid.sketch.edge.d.ts +97 -1
  30. package/objects/@common/edges/uuid.sketch.edge.js +127 -6
  31. package/objects/amount/amount-value.edge.d.ts +39 -0
  32. package/objects/amount/amount-value.edge.js +69 -0
  33. package/objects/amount/amount.edge.d.ts +378 -2
  34. package/objects/amount/amount.edge.js +493 -4
  35. package/objects/datetime/edges/datetime.edge.d.ts +422 -4
  36. package/objects/datetime/edges/datetime.edge.js +538 -33
  37. package/objects/password/password.edge.d.ts +90 -0
  38. package/objects/password/password.edge.js +140 -6
  39. package/objects/primitives/boolean.edge.sketch.d.ts +105 -3
  40. package/objects/primitives/boolean.edge.sketch.js +132 -6
  41. package/objects/primitives/number.edge.sketch.d.ts +236 -0
  42. package/objects/primitives/number.edge.sketch.js +310 -24
  43. package/objects/primitives/string.edge.sketch.d.ts +148 -0
  44. package/objects/primitives/string.edge.sketch.js +191 -7
  45. package/objects/schedule/schedule.edge.d.ts +194 -0
  46. package/objects/schedule/schedule.edge.js +269 -2
  47. package/objects/time/time.edge.d.ts +285 -2
  48. package/objects/time/time.edge.js +385 -6
  49. package/package.json +1 -1
  50. package/tsconfig.tsbuildinfo +1 -1
@@ -10,35 +10,414 @@ class TimeEdge {
10
10
  this.value = value;
11
11
  this.validate();
12
12
  }
13
+ // ==================== Getters ====================
14
+ /**
15
+ * Retorna as horas do tempo como número inteiro.
16
+ * @returns Número inteiro representando as horas (0-23)
17
+ * @example
18
+ * new TimeEdge("14:30").getHours() // 14
19
+ * new TimeEdge("08:00").getHours() // 8
20
+ */
21
+ getHours() {
22
+ return Number(this.value.split(":")[0]);
23
+ }
24
+ /**
25
+ * Retorna os minutos do tempo como número inteiro.
26
+ * @returns Número inteiro representando os minutos (0-59)
27
+ * @example
28
+ * new TimeEdge("14:30").getMinutes() // 30
29
+ * new TimeEdge("08:05").getMinutes() // 5
30
+ */
31
+ getMinutes() {
32
+ return Number(this.value.split(":")[1]);
33
+ }
34
+ /**
35
+ * Retorna o tempo total convertido em minutos.
36
+ * @returns Total de minutos representados pelo tempo
37
+ * @example
38
+ * new TimeEdge("01:30").toTotalMinutes() // 90
39
+ * new TimeEdge("02:00").toTotalMinutes() // 120
40
+ */
41
+ toTotalMinutes() {
42
+ return this.getHours() * 60 + this.getMinutes();
43
+ }
44
+ /**
45
+ * Retorna o tempo total convertido em segundos.
46
+ * @returns Total de segundos representados pelo tempo
47
+ * @example
48
+ * new TimeEdge("00:01").toTotalSeconds() // 60
49
+ * new TimeEdge("01:00").toTotalSeconds() // 3600
50
+ */
51
+ toTotalSeconds() {
52
+ return this.toTotalMinutes() * 60;
53
+ }
54
+ // ==================== Operações Aritméticas ====================
55
+ /**
56
+ * Subtrai um tempo de outro e retorna uma nova instância.
57
+ * @param time - Tempo a ser subtraído do valor atual
58
+ * @returns Nova instância de TimeEdge com o resultado da subtração
59
+ * @example
60
+ * new TimeEdge("10:30").subtract(new TimeEdge("01:00")) // TimeEdge("09:30")
61
+ * new TimeEdge("08:15").subtract(new TimeEdge("00:30")) // TimeEdge("07:45")
62
+ */
13
63
  subtract(time) {
14
64
  const momentTime = (0, moment_1.default)()
15
65
  .hours(this.getHours())
16
66
  .minutes(this.getMinutes());
17
67
  return new TimeEdge(momentTime.clone().subtract(time.toString()).format("HH:mm"));
18
68
  }
69
+ /**
70
+ * Soma um tempo ao valor atual e retorna uma nova instância.
71
+ * @param time - Tempo a ser somado ao valor atual
72
+ * @returns Nova instância de TimeEdge com o resultado da soma
73
+ * @example
74
+ * new TimeEdge("08:30").add(new TimeEdge("01:00")) // TimeEdge("09:30")
75
+ * new TimeEdge("23:30").add(new TimeEdge("01:00")) // TimeEdge("00:30")
76
+ */
19
77
  add(time) {
20
78
  const momentTime = (0, moment_1.default)()
21
79
  .hours(this.getHours())
22
80
  .minutes(this.getMinutes());
23
81
  return new TimeEdge(momentTime.clone().add(time.toString()).format("HH:mm"));
24
82
  }
83
+ /**
84
+ * Calcula a diferença absoluta entre dois tempos.
85
+ * @param time - Tempo para calcular a diferença
86
+ * @returns Nova instância de TimeEdge com a diferença absoluta
87
+ * @example
88
+ * new TimeEdge("10:00").difference(new TimeEdge("08:30")) // TimeEdge("01:30")
89
+ * new TimeEdge("08:30").difference(new TimeEdge("10:00")) // TimeEdge("01:30")
90
+ */
91
+ difference(time) {
92
+ const diffMinutes = Math.abs(this.toTotalMinutes() - time.toTotalMinutes());
93
+ const hours = Math.floor(diffMinutes / 60)
94
+ .toString()
95
+ .padStart(2, "0");
96
+ const minutes = (diffMinutes % 60).toString().padStart(2, "0");
97
+ return new TimeEdge(`${hours}:${minutes}`);
98
+ }
99
+ /**
100
+ * Multiplica o tempo por um fator numérico e retorna uma nova instância.
101
+ * @param factor - Fator de multiplicação
102
+ * @returns Nova instância de TimeEdge com o tempo multiplicado
103
+ * @example
104
+ * new TimeEdge("01:30").multiply(2) // TimeEdge("03:00")
105
+ * new TimeEdge("00:20").multiply(3) // TimeEdge("01:00")
106
+ */
107
+ multiply(factor) {
108
+ const totalMinutes = Math.round(this.toTotalMinutes() * factor);
109
+ const hours = Math.floor(totalMinutes / 60)
110
+ .toString()
111
+ .padStart(2, "0");
112
+ const minutes = (totalMinutes % 60).toString().padStart(2, "0");
113
+ return new TimeEdge(`${hours}:${minutes}`);
114
+ }
115
+ // ==================== Comparações ====================
116
+ /**
117
+ * Verifica se este tempo é igual a outro.
118
+ * @param time - Tempo para comparação
119
+ * @returns true se os tempos são iguais, false caso contrário
120
+ * @example
121
+ * new TimeEdge("10:30").isEqual(new TimeEdge("10:30")) // true
122
+ * new TimeEdge("10:30").isEqual(new TimeEdge("10:00")) // false
123
+ */
124
+ isEqual(time) {
125
+ return this.value === time.toString();
126
+ }
127
+ /**
128
+ * Verifica se este tempo é diferente de outro.
129
+ * @param time - Tempo para comparação
130
+ * @returns true se os tempos são diferentes, false caso contrário
131
+ * @example
132
+ * new TimeEdge("10:30").isDifferent(new TimeEdge("09:00")) // true
133
+ * new TimeEdge("10:30").isDifferent(new TimeEdge("10:30")) // false
134
+ */
135
+ isDifferent(time) {
136
+ return !this.isEqual(time);
137
+ }
138
+ /**
139
+ * Verifica se este tempo é maior que outro.
140
+ * @param time - Tempo para comparação
141
+ * @returns true se this > time, false caso contrário
142
+ * @example
143
+ * new TimeEdge("10:30").isGreaterThan(new TimeEdge("09:00")) // true
144
+ * new TimeEdge("08:00").isGreaterThan(new TimeEdge("10:00")) // false
145
+ */
146
+ isGreaterThan(time) {
147
+ return this.toTotalMinutes() > time.toTotalMinutes();
148
+ }
149
+ /**
150
+ * Verifica se este tempo é menor que outro.
151
+ * @param time - Tempo para comparação
152
+ * @returns true se this < time, false caso contrário
153
+ * @example
154
+ * new TimeEdge("08:00").isLessThan(new TimeEdge("10:00")) // true
155
+ * new TimeEdge("10:30").isLessThan(new TimeEdge("09:00")) // false
156
+ */
157
+ isLessThan(time) {
158
+ return this.toTotalMinutes() < time.toTotalMinutes();
159
+ }
160
+ /**
161
+ * Verifica se este tempo é maior ou igual a outro.
162
+ * @param time - Tempo para comparação
163
+ * @returns true se this >= time, false caso contrário
164
+ * @example
165
+ * new TimeEdge("10:30").isGreaterThanOrEqual(new TimeEdge("10:30")) // true
166
+ * new TimeEdge("10:30").isGreaterThanOrEqual(new TimeEdge("09:00")) // true
167
+ */
168
+ isGreaterThanOrEqual(time) {
169
+ return this.toTotalMinutes() >= time.toTotalMinutes();
170
+ }
171
+ /**
172
+ * Verifica se este tempo é menor ou igual a outro.
173
+ * @param time - Tempo para comparação
174
+ * @returns true se this <= time, false caso contrário
175
+ * @example
176
+ * new TimeEdge("08:00").isLessThanOrEqual(new TimeEdge("08:00")) // true
177
+ * new TimeEdge("08:00").isLessThanOrEqual(new TimeEdge("10:00")) // true
178
+ */
179
+ isLessThanOrEqual(time) {
180
+ return this.toTotalMinutes() <= time.toTotalMinutes();
181
+ }
182
+ /**
183
+ * Verifica se este tempo está entre dois limites (inclusive).
184
+ * @param start - Tempo mínimo do intervalo
185
+ * @param end - Tempo máximo do intervalo
186
+ * @returns true se o tempo está entre start e end, false caso contrário
187
+ * @example
188
+ * new TimeEdge("10:00").isBetween(new TimeEdge("08:00"), new TimeEdge("12:00")) // true
189
+ * new TimeEdge("14:00").isBetween(new TimeEdge("08:00"), new TimeEdge("12:00")) // false
190
+ */
191
+ isBetween(start, end) {
192
+ return this.isGreaterThanOrEqual(start) && this.isLessThanOrEqual(end);
193
+ }
194
+ // ==================== Validações ====================
195
+ /**
196
+ * Verifica se o tempo representa meia-noite (00:00).
197
+ * @returns true se o tempo é 00:00, false caso contrário
198
+ * @example
199
+ * new TimeEdge("00:00").isMidnight() // true
200
+ * new TimeEdge("12:00").isMidnight() // false
201
+ */
202
+ isMidnight() {
203
+ return this.value === "00:00";
204
+ }
205
+ /**
206
+ * Verifica se o tempo representa o meio-dia (12:00).
207
+ * @returns true se o tempo é 12:00, false caso contrário
208
+ * @example
209
+ * new TimeEdge("12:00").isNoon() // true
210
+ * new TimeEdge("00:00").isNoon() // false
211
+ */
212
+ isNoon() {
213
+ return this.value === "12:00";
214
+ }
215
+ /**
216
+ * Verifica se o tempo está no período da manhã (00:00 até 11:59).
217
+ * @returns true se o tempo é anterior às 12:00, false caso contrário
218
+ * @example
219
+ * new TimeEdge("09:00").isMorning() // true
220
+ * new TimeEdge("13:00").isMorning() // false
221
+ */
222
+ isMorning() {
223
+ return this.getHours() < 12;
224
+ }
225
+ /**
226
+ * Verifica se o tempo está no período da tarde (12:00 até 17:59).
227
+ * @returns true se o tempo está entre 12:00 e 17:59, false caso contrário
228
+ * @example
229
+ * new TimeEdge("14:00").isAfternoon() // true
230
+ * new TimeEdge("20:00").isAfternoon() // false
231
+ */
232
+ isAfternoon() {
233
+ return this.getHours() >= 12 && this.getHours() < 18;
234
+ }
235
+ /**
236
+ * Verifica se o tempo está no período da noite (18:00 até 23:59).
237
+ * @returns true se o tempo é a partir das 18:00, false caso contrário
238
+ * @example
239
+ * new TimeEdge("20:00").isEvening() // true
240
+ * new TimeEdge("14:00").isEvening() // false
241
+ */
242
+ isEvening() {
243
+ return this.getHours() >= 18;
244
+ }
245
+ // ==================== Clonagem e Imutabilidade ====================
246
+ /**
247
+ * Cria uma cópia independente desta instância de TimeEdge.
248
+ * @returns Nova instância com o mesmo valor de tempo
249
+ * @example
250
+ * const time1 = new TimeEdge("10:30");
251
+ * const time2 = time1.clone(); // instância independente com "10:30"
252
+ */
253
+ clone() {
254
+ return new TimeEdge(this.value);
255
+ }
256
+ /**
257
+ * Retorna uma nova instância com as horas alteradas.
258
+ * @param hours - Novo valor de horas (0-23)
259
+ * @returns Nova instância com as horas alteradas
260
+ * @example
261
+ * new TimeEdge("10:30").withHours(15) // TimeEdge("15:30")
262
+ */
263
+ withHours(hours) {
264
+ const paddedHours = hours.toString().padStart(2, "0");
265
+ const paddedMinutes = this.getMinutes().toString().padStart(2, "0");
266
+ return new TimeEdge(`${paddedHours}:${paddedMinutes}`);
267
+ }
268
+ /**
269
+ * Retorna uma nova instância com os minutos alterados.
270
+ * @param minutes - Novo valor de minutos (0-59)
271
+ * @returns Nova instância com os minutos alterados
272
+ * @example
273
+ * new TimeEdge("10:30").withMinutes(45) // TimeEdge("10:45")
274
+ */
275
+ withMinutes(minutes) {
276
+ const paddedHours = this.getHours().toString().padStart(2, "0");
277
+ const paddedMinutes = minutes.toString().padStart(2, "0");
278
+ return new TimeEdge(`${paddedHours}:${paddedMinutes}`);
279
+ }
280
+ // ==================== Formatação ====================
281
+ /**
282
+ * Retorna o tempo como string no formato HH:mm.
283
+ * @returns String no formato "HH:mm"
284
+ * @example
285
+ * new TimeEdge("14:30").toString() // "14:30"
286
+ */
25
287
  toString() {
26
288
  return this.value;
27
289
  }
290
+ /**
291
+ * Retorna o tempo no formato de 12 horas com AM/PM.
292
+ * @returns String no formato "hh:mm AM/PM"
293
+ * @example
294
+ * new TimeEdge("14:30").toFormat12h() // "02:30 PM"
295
+ * new TimeEdge("08:00").toFormat12h() // "08:00 AM"
296
+ */
297
+ toFormat12h() {
298
+ const hours = this.getHours();
299
+ const minutes = this.getMinutes().toString().padStart(2, "0");
300
+ const period = hours >= 12 ? "PM" : "AM";
301
+ const formattedHours = (hours % 12 || 12).toString().padStart(2, "0");
302
+ return `${formattedHours}:${minutes} ${period}`;
303
+ }
304
+ /**
305
+ * Retorna uma representação legível do tempo em horas e minutos por extenso.
306
+ * @returns String descritiva no formato "Xh Ym"
307
+ * @example
308
+ * new TimeEdge("14:30").toReadableString() // "14h 30m"
309
+ * new TimeEdge("08:05").toReadableString() // "8h 5m"
310
+ */
311
+ toReadableString() {
312
+ return `${this.getHours()}h ${this.getMinutes()}m`;
313
+ }
314
+ // ==================== Métodos Estáticos ====================
315
+ /**
316
+ * Cria um TimeEdge representando a hora atual do sistema.
317
+ * @returns Nova instância com o horário atual no formato HH:mm
318
+ * @example
319
+ * TimeEdge.now() // pode retornar TimeEdge("14:35") dependendo da hora atual
320
+ */
321
+ static now() {
322
+ return new TimeEdge((0, moment_1.default)().format("HH:mm"));
323
+ }
324
+ /**
325
+ * Cria um TimeEdge representando a meia-noite (00:00).
326
+ * @returns Nova instância com o valor "00:00"
327
+ * @example
328
+ * TimeEdge.midnight() // TimeEdge("00:00")
329
+ */
330
+ static midnight() {
331
+ return new TimeEdge("00:00");
332
+ }
333
+ /**
334
+ * Cria um TimeEdge representando o meio-dia (12:00).
335
+ * @returns Nova instância com o valor "12:00"
336
+ * @example
337
+ * TimeEdge.noon() // TimeEdge("12:00")
338
+ */
339
+ static noon() {
340
+ return new TimeEdge("12:00");
341
+ }
342
+ /**
343
+ * Cria um TimeEdge a partir de um total de minutos.
344
+ * @param totalMinutes - Total de minutos a converter para HH:mm
345
+ * @returns Nova instância com o tempo correspondente ao total de minutos
346
+ * @example
347
+ * TimeEdge.fromMinutes(90) // TimeEdge("01:30")
348
+ * TimeEdge.fromMinutes(125) // TimeEdge("02:05")
349
+ */
350
+ static fromMinutes(totalMinutes) {
351
+ const hours = Math.floor(totalMinutes / 60)
352
+ .toString()
353
+ .padStart(2, "0");
354
+ const minutes = (totalMinutes % 60).toString().padStart(2, "0");
355
+ return new TimeEdge(`${hours}:${minutes}`);
356
+ }
357
+ /**
358
+ * Retorna o maior tempo de uma lista.
359
+ * @param times - Array de instâncias de TimeEdge para comparação
360
+ * @returns A instância com o maior valor de tempo
361
+ * @throws {Error} Se o array estiver vazio
362
+ * @example
363
+ * TimeEdge.max([new TimeEdge("08:00"), new TimeEdge("14:30"), new TimeEdge("10:00")])
364
+ * // TimeEdge("14:30")
365
+ */
366
+ static max(times) {
367
+ if (times.length === 0) {
368
+ throw new Error("Cannot find max of an empty array of times.");
369
+ }
370
+ return times.reduce((max, time) => (time.isGreaterThan(max) ? time : max));
371
+ }
372
+ /**
373
+ * Retorna o menor tempo de uma lista.
374
+ * @param times - Array de instâncias de TimeEdge para comparação
375
+ * @returns A instância com o menor valor de tempo
376
+ * @throws {Error} Se o array estiver vazio
377
+ * @example
378
+ * TimeEdge.min([new TimeEdge("08:00"), new TimeEdge("14:30"), new TimeEdge("10:00")])
379
+ * // TimeEdge("08:00")
380
+ */
381
+ static min(times) {
382
+ if (times.length === 0) {
383
+ throw new Error("Cannot find min of an empty array of times.");
384
+ }
385
+ return times.reduce((min, time) => (time.isLessThan(min) ? time : min));
386
+ }
387
+ /**
388
+ * Soma uma lista de tempos e retorna o total.
389
+ * @param times - Array de instâncias de TimeEdge para somar
390
+ * @returns Nova instância com a soma total dos tempos
391
+ * @throws {Error} Se o array estiver vazio
392
+ * @example
393
+ * TimeEdge.sumAll([new TimeEdge("01:00"), new TimeEdge("02:30"), new TimeEdge("00:15")])
394
+ * // TimeEdge("03:45")
395
+ */
396
+ static sumAll(times) {
397
+ if (times.length === 0) {
398
+ throw new Error("Cannot sum an empty array of times.");
399
+ }
400
+ const totalMinutes = times.reduce((sum, time) => sum + time.toTotalMinutes(), 0);
401
+ return TimeEdge.fromMinutes(totalMinutes);
402
+ }
403
+ // ==================== Privados ====================
404
+ /**
405
+ * Valida o formato do tempo informado no construtor.
406
+ * @throws {Error} Se o formato não for HH:mm válido
407
+ */
28
408
  validate() {
29
409
  if (!this.isValidTimeFormat(this.value)) {
30
410
  throw new Error("Invalid time format. Please provide time in 'HH:mm' format.");
31
411
  }
32
412
  }
413
+ /**
414
+ * Verifica se uma string está no formato de tempo HH:mm válido.
415
+ * @param value - String a ser validada
416
+ * @returns true se o formato é válido, false caso contrário
417
+ */
33
418
  isValidTimeFormat(value) {
34
419
  const regex = /^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/;
35
420
  return regex.test(value);
36
421
  }
37
- getHours() {
38
- return Number(this.value.split(":")[0]);
39
- }
40
- getMinutes() {
41
- return Number(this.value.split(":").reverse()[0]);
42
- }
43
422
  }
44
423
  exports.TimeEdge = TimeEdge;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlantjs/arch",
3
- "version": "13.3.0",
3
+ "version": "14.0.1",
4
4
  "main": "index.js",
5
5
  "license": "UNLICENSED",
6
6
  "publishConfig": {