@atlantjs/arch 13.3.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.
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 +20 -4
  4. package/@tool-box/utils/datatypes/string-utils.js +300 -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
@@ -6,4 +6,11 @@ interface Boolean {
6
6
  not(): boolean;
7
7
  and(value: boolean): boolean;
8
8
  or(value: boolean): boolean;
9
+ xor(value: boolean): boolean;
10
+ nand(value: boolean): boolean;
11
+ nor(value: boolean): boolean;
12
+ implies(value: boolean): boolean;
13
+ toNumber(): number;
14
+ toString(): string;
15
+ toggle(): boolean;
9
16
  }
@@ -1,22 +1,164 @@
1
1
  "use strict";
2
+ /**
3
+ * Verifica se o valor booleano é verdadeiro (true).
4
+ * @returns true se o valor é true, false caso contrário
5
+ * @example
6
+ * (true).truthy() // true
7
+ * (false).truthy() // false
8
+ */
2
9
  Boolean.prototype.truthy = function () {
3
- return this === true;
10
+ return this.valueOf() === true;
4
11
  };
12
+ /**
13
+ * Verifica se o valor booleano é falso (false ou undefined).
14
+ * @returns true se o valor é false ou undefined, false caso contrário
15
+ * @example
16
+ * (false).falsy() // true
17
+ * (true).falsy() // false
18
+ */
5
19
  Boolean.prototype.falsy = function () {
6
- return this === false || this === undefined;
20
+ return this.valueOf() === false || this.valueOf() === undefined;
7
21
  };
22
+ /**
23
+ * Retorna o valor booleano negado (inversão lógica).
24
+ * @returns true se o valor é false, false se o valor é true
25
+ * @example
26
+ * (true).not() // false
27
+ * (false).not() // true
28
+ */
8
29
  Boolean.prototype.not = function () {
9
30
  return !this.valueOf();
10
31
  };
32
+ /**
33
+ * Realiza a operação lógica AND (E) entre este valor e outro.
34
+ * Retorna true somente se ambos os valores forem true.
35
+ * @param value - Segundo operando booleano
36
+ * @returns true se ambos são true, false caso contrário
37
+ * @example
38
+ * (true).and(true) // true
39
+ * (true).and(false) // false
40
+ * (false).and(true) // false
41
+ */
11
42
  Boolean.prototype.and = function (value) {
12
43
  return this.valueOf() === true && value === true;
13
44
  };
45
+ /**
46
+ * Realiza a operação lógica OR (OU) entre este valor e outro.
47
+ * Retorna true se pelo menos um dos valores for true.
48
+ * @param value - Segundo operando booleano
49
+ * @returns true se pelo menos um é true, false caso contrário
50
+ * @example
51
+ * (true).or(false) // true
52
+ * (false).or(false) // false
53
+ * (false).or(true) // true
54
+ */
14
55
  Boolean.prototype.or = function (value) {
15
56
  return this.valueOf() === true || value === true;
16
57
  };
58
+ /**
59
+ * Verifica se este valor booleano é igual a outro.
60
+ * @param value - Valor booleano para comparação
61
+ * @returns true se os valores são iguais, false caso contrário
62
+ * @example
63
+ * (true).equal(true) // true
64
+ * (true).equal(false) // false
65
+ */
17
66
  Boolean.prototype.equal = function (value) {
18
- return this === value;
67
+ return this.valueOf() === value;
19
68
  };
69
+ /**
70
+ * Verifica se este valor booleano é diferente de outro.
71
+ * @param value - Valor booleano para comparação
72
+ * @returns true se os valores são diferentes, false caso contrário
73
+ * @example
74
+ * (true).different(false) // true
75
+ * (true).different(true) // false
76
+ */
20
77
  Boolean.prototype.different = function (value) {
21
- return this !== value;
78
+ return this.valueOf() !== value;
79
+ };
80
+ /**
81
+ * Realiza a operação lógica XOR (OU exclusivo) entre este valor e outro.
82
+ * Retorna true somente se exatamente um dos valores for true.
83
+ * @param value - Segundo operando booleano
84
+ * @returns true se exatamente um é true, false caso contrário
85
+ * @example
86
+ * (true).xor(false) // true
87
+ * (true).xor(true) // false
88
+ * (false).xor(false) // false
89
+ */
90
+ Boolean.prototype.xor = function (value) {
91
+ return this.valueOf() !== value;
92
+ };
93
+ /**
94
+ * Realiza a operação lógica NAND (NÃO-E) entre este valor e outro.
95
+ * Retorna false somente se ambos os valores forem true.
96
+ * @param value - Segundo operando booleano
97
+ * @returns false se ambos são true, true caso contrário
98
+ * @example
99
+ * (true).nand(true) // false
100
+ * (true).nand(false) // true
101
+ * (false).nand(false) // true
102
+ */
103
+ Boolean.prototype.nand = function (value) {
104
+ return !(this.valueOf() === true && value === true);
105
+ };
106
+ /**
107
+ * Realiza a operação lógica NOR (NÃO-OU) entre este valor e outro.
108
+ * Retorna true somente se ambos os valores forem false.
109
+ * @param value - Segundo operando booleano
110
+ * @returns true se ambos são false, false caso contrário
111
+ * @example
112
+ * (false).nor(false) // true
113
+ * (true).nor(false) // false
114
+ * (true).nor(true) // false
115
+ */
116
+ Boolean.prototype.nor = function (value) {
117
+ return !(this.valueOf() === true || value === true);
118
+ };
119
+ /**
120
+ * Realiza a operação lógica de implicação (→) entre este valor e outro.
121
+ * Retorna false somente se este valor é true e o outro é false.
122
+ * @param value - Consequente da implicação
123
+ * @returns false se this é true e value é false, true caso contrário
124
+ * @example
125
+ * (true).implies(true) // true
126
+ * (true).implies(false) // false
127
+ * (false).implies(true) // true
128
+ * (false).implies(false) // true
129
+ */
130
+ Boolean.prototype.implies = function (value) {
131
+ return !this.valueOf() || value;
132
+ };
133
+ /**
134
+ * Converte o valor booleano para número.
135
+ * true é convertido para 1, false para 0.
136
+ * @returns 1 se o valor é true, 0 se o valor é false
137
+ * @example
138
+ * (true).toNumber() // 1
139
+ * (false).toNumber() // 0
140
+ */
141
+ Boolean.prototype.toNumber = function () {
142
+ return this.valueOf() ? 1 : 0;
143
+ };
144
+ /**
145
+ * Converte o valor booleano para string.
146
+ * @returns "true" se o valor é true, "false" se o valor é false
147
+ * @example
148
+ * (true).toString() // "true"
149
+ * (false).toString() // "false"
150
+ */
151
+ Boolean.prototype.toString = function () {
152
+ return this.valueOf() ? "true" : "false";
153
+ };
154
+ /**
155
+ * Retorna o valor booleano invertido sem alterar o original.
156
+ * Equivalente a `.not()`, porém semânticamente indica alternância de estado.
157
+ * @returns true se o valor é false, false se o valor é true
158
+ * @example
159
+ * (true).toggle() // false
160
+ * (false).toggle() // true
161
+ */
162
+ Boolean.prototype.toggle = function () {
163
+ return !this.valueOf();
22
164
  };
@@ -1,14 +1,30 @@
1
1
  interface String {
2
2
  toKebabCase(): string;
3
3
  toSnakeCase(): string;
4
+ toCamelCase(): string;
4
5
  toPascalCase(): string;
5
- sanitize(): string;
6
- capitalize(): string;
7
6
  toTitleCase(): string;
8
- contains(substring: string): boolean;
9
- truncate(length: number): String;
7
+ capitalize(): string;
8
+ sanitize(): string;
9
+ truncate(length: number): string;
10
10
  removeWhitespace(): string;
11
+ contains(substring: string): boolean;
12
+ startsWith(substring: string): boolean;
13
+ endsWith(substring: string): boolean;
11
14
  isEmpty(): boolean;
12
15
  isFilled(): boolean;
16
+ isPalindrome(): boolean;
17
+ isNumeric(): boolean;
18
+ isEmail(): boolean;
19
+ isURL(): boolean;
20
+ isUUID(): boolean;
21
+ countOccurrences(substring: string): number;
22
+ toBase64(): string;
13
23
  fromBase64(): string;
24
+ reverse(): string;
25
+ repeat(times: number): string;
26
+ padStart(length: number, char?: string): string;
27
+ padEnd(length: number, char?: string): string;
28
+ replaceAll(search: string | RegExp, replacement: string | ((substring: string, ...args: any[]) => string)): string;
14
29
  }
30
+ declare function escapeRegExp(value: string): string;
@@ -1,38 +1,324 @@
1
1
  "use strict";
2
+ // ==================== Transformação de Casing ====================
3
+ /**
4
+ * Converte a string para o formato kebab-case.
5
+ * Separa palavras com hífen e converte tudo para minúsculas.
6
+ * @returns String no formato kebab-case
7
+ * @example
8
+ * "helloWorld".toKebabCase() // "hello-world"
9
+ * "FooBarBaz".toKebabCase() // "foo-bar-baz"
10
+ */
2
11
  String.prototype.toKebabCase = function () {
3
12
  return this.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
4
13
  };
14
+ /**
15
+ * Converte a string para o formato snake_case.
16
+ * Separa palavras com underscore e converte tudo para minúsculas.
17
+ * @returns String no formato snake_case
18
+ * @example
19
+ * "helloWorld".toSnakeCase() // "hello_world"
20
+ * "FooBarBaz".toSnakeCase() // "foo_bar_baz"
21
+ */
5
22
  String.prototype.toSnakeCase = function () {
6
23
  return this.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
7
24
  };
25
+ /**
26
+ * Converte a string para o formato camelCase.
27
+ * Remove espaços e capitaliza a primeira letra de cada palavra, exceto a primeira.
28
+ * @returns String no formato camelCase
29
+ * @example
30
+ * "hello world".toCamelCase() // "helloWorld"
31
+ * "foo bar baz".toCamelCase() // "fooBarBaz"
32
+ */
33
+ String.prototype.toCamelCase = function () {
34
+ return this.valueOf()
35
+ .replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, (match, index) => index === 0 ? match.toLowerCase() : match.toUpperCase())
36
+ .replace(/\s+/g, "");
37
+ };
38
+ /**
39
+ * Converte a string para o formato PascalCase.
40
+ * Remove espaços e capitaliza a primeira letra de cada palavra.
41
+ * @returns String no formato PascalCase
42
+ * @example
43
+ * "hello world".toPascalCase() // "HelloWorld"
44
+ * "foo bar baz".toPascalCase() // "FooBarBaz"
45
+ */
8
46
  String.prototype.toPascalCase = function () {
9
- return this.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, (match) => match.toUpperCase()).replace(/\s+/g, "");
47
+ return this.valueOf()
48
+ .replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, (match) => match.toUpperCase())
49
+ .replace(/\s+/g, "");
10
50
  };
11
- String.prototype.sanitize = function () {
12
- return this.replace(/\s+/g, " ").trim();
51
+ /**
52
+ * Converte a string para o formato Title Case.
53
+ * Capitaliza a primeira letra de cada palavra, mantendo as demais em minúsculo.
54
+ * @returns String no formato Title Case
55
+ * @example
56
+ * "hello world".toTitleCase() // "Hello World"
57
+ * "the quick brown fox".toTitleCase() // "The Quick Brown Fox"
58
+ */
59
+ String.prototype.toTitleCase = function () {
60
+ return this.valueOf()
61
+ .toLowerCase()
62
+ .replace(/(?:^|\s)\w/g, (match) => match.toUpperCase());
13
63
  };
64
+ /**
65
+ * Capitaliza a primeira letra de cada palavra da string.
66
+ * @returns String com a primeira letra de cada palavra em maiúsculo
67
+ * @example
68
+ * "hello world".capitalize() // "Hello World"
69
+ * "foo BAR".capitalize() // "Foo Bar"
70
+ */
14
71
  String.prototype.capitalize = function () {
15
- return this.split(" ")
72
+ return this.valueOf()
73
+ .split(" ")
16
74
  .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
17
75
  .join(" ");
18
76
  };
19
- String.prototype.contains = function (substring) {
20
- return this.indexOf(substring) !== -1;
77
+ // ==================== Manipulação ====================
78
+ /**
79
+ * Remove espaços extras e faz trim na string.
80
+ * Substitui múltiplos espaços consecutivos por um único espaço.
81
+ * @returns String sem espaços extras
82
+ * @example
83
+ * " hello world ".sanitize() // "hello world"
84
+ * "foo bar".sanitize() // "foo bar"
85
+ */
86
+ String.prototype.sanitize = function () {
87
+ return this.valueOf().replace(/\s+/g, " ").trim();
21
88
  };
89
+ /**
90
+ * Trunca a string para um comprimento máximo, adicionando "..." ao final.
91
+ * Se a string já for menor ou igual ao comprimento, retorna sem alteração.
92
+ * @param length - Comprimento máximo da string resultante (incluindo "...")
93
+ * @returns String truncada com "..." se necessário
94
+ * @example
95
+ * "Hello World".truncate(8) // "Hello..."
96
+ * "Hi".truncate(8) // "Hi"
97
+ */
22
98
  String.prototype.truncate = function (length) {
23
- if (this.length <= length)
24
- return this;
25
- return `${this.substring(0, length - 3)}...`;
99
+ if (this.valueOf().length <= length)
100
+ return this.valueOf();
101
+ return `${this.valueOf().substring(0, length - 3)}...`;
26
102
  };
103
+ /**
104
+ * Remove todos os espaços em branco da string.
105
+ * @returns String sem nenhum espaço em branco
106
+ * @example
107
+ * "hello world".removeWhitespace() // "helloworld"
108
+ * " foo bar ".removeWhitespace() // "foobar"
109
+ */
27
110
  String.prototype.removeWhitespace = function () {
28
- return this.replace(/\s+/g, "");
111
+ return this.valueOf().replace(/\s+/g, "");
29
112
  };
30
- String.prototype.isEmpty = function () {
31
- return this.length === 0;
113
+ /**
114
+ * Inverte os caracteres da string.
115
+ * @returns String com os caracteres em ordem inversa
116
+ * @example
117
+ * "hello".reverse() // "olleh"
118
+ * "abcd".reverse() // "dcba"
119
+ */
120
+ String.prototype.reverse = function () {
121
+ return this.valueOf().split("").reverse().join("");
122
+ };
123
+ /**
124
+ * Repete a string um número específico de vezes.
125
+ * @param times - Número de vezes que a string será repetida
126
+ * @returns String repetida o número de vezes especificado
127
+ * @example
128
+ * "ab".repeat(3) // "ababab"
129
+ * "ha".repeat(2) // "haha"
130
+ */
131
+ String.prototype.repeat = function (times) {
132
+ return this.valueOf().repeat(times);
133
+ };
134
+ /**
135
+ * Preenche o início da string com um caractere até atingir o comprimento especificado.
136
+ * @param length - Comprimento total desejado da string
137
+ * @param char - Caractere de preenchimento (padrão: " ")
138
+ * @returns String preenchida à esquerda
139
+ * @example
140
+ * "5".padStart(3, "0") // "005"
141
+ * "hi".padStart(5) // " hi"
142
+ */
143
+ String.prototype.padStart = function (length, char = " ") {
144
+ return this.valueOf().padStart(length, char);
145
+ };
146
+ /**
147
+ * Preenche o final da string com um caractere até atingir o comprimento especificado.
148
+ * @param length - Comprimento total desejado da string
149
+ * @param char - Caractere de preenchimento (padrão: " ")
150
+ * @returns String preenchida à direita
151
+ * @example
152
+ * "5".padEnd(3, "0") // "500"
153
+ * "hi".padEnd(5) // "hi "
154
+ */
155
+ String.prototype.padEnd = function (length, char = " ") {
156
+ return this.valueOf().padEnd(length, char);
157
+ };
158
+ function escapeRegExp(value) {
159
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
160
+ }
161
+ /**
162
+ * Substitui todas as ocorrências de uma substring por outra.
163
+ * @param search - Substring/RegExp a ser substituída
164
+ * @param replacement - String de substituição ou função de substituição
165
+ * @returns Nova string com todas as ocorrências substituídas
166
+ * @example
167
+ * "foo bar foo".replaceAll("foo", "baz") // "baz bar baz"
168
+ */
169
+ String.prototype.replaceAll = function (search, replacement) {
170
+ const source = this.valueOf();
171
+ if (search instanceof RegExp) {
172
+ const flags = search.flags.includes("g")
173
+ ? search.flags
174
+ : `${search.flags}g`;
175
+ return source.replace(new RegExp(search.source, flags), replacement);
176
+ }
177
+ const literalGlobalRegex = new RegExp(escapeRegExp(search), "g");
178
+ return source.replace(literalGlobalRegex, replacement);
179
+ };
180
+ // ==================== Verificação de Conteúdo ====================
181
+ /**
182
+ * Verifica se a string contém uma substring específica.
183
+ * @param substring - Substring a ser procurada
184
+ * @returns true se a substring foi encontrada, false caso contrário
185
+ * @example
186
+ * "hello world".contains("world") // true
187
+ * "hello world".contains("foo") // false
188
+ */
189
+ String.prototype.contains = function (substring) {
190
+ return this.valueOf().indexOf(substring) !== -1;
32
191
  };
192
+ /**
193
+ * Verifica se a string começa com uma substring específica.
194
+ * @param substring - Substring a ser verificada no início
195
+ * @returns true se a string começa com a substring, false caso contrário
196
+ * @example
197
+ * "hello world".startsWith("hello") // true
198
+ * "hello world".startsWith("world") // false
199
+ */
200
+ String.prototype.startsWith = function (substring) {
201
+ return this.valueOf().startsWith(substring);
202
+ };
203
+ /**
204
+ * Verifica se a string termina com uma substring específica.
205
+ * @param substring - Substring a ser verificada no final
206
+ * @returns true se a string termina com a substring, false caso contrário
207
+ * @example
208
+ * "hello world".endsWith("world") // true
209
+ * "hello world".endsWith("hello") // false
210
+ */
211
+ String.prototype.endsWith = function (substring) {
212
+ return this.valueOf().endsWith(substring);
213
+ };
214
+ /**
215
+ * Conta o número de ocorrências de uma substring na string.
216
+ * @param substring - Substring a ser contada
217
+ * @returns Número de ocorrências encontradas
218
+ * @example
219
+ * "hello world hello".countOccurrences("hello") // 2
220
+ * "aaaa".countOccurrences("aa") // 2
221
+ */
222
+ String.prototype.countOccurrences = function (substring) {
223
+ if (substring.length === 0)
224
+ return 0;
225
+ return this.valueOf().split(substring).length - 1;
226
+ };
227
+ // ==================== Validações ====================
228
+ /**
229
+ * Verifica se a string está vazia (sem nenhum caractere).
230
+ * @returns true se a string não possui caracteres, false caso contrário
231
+ * @example
232
+ * "".isEmpty() // true
233
+ * "hello".isEmpty() // false
234
+ */
33
235
  String.prototype.isEmpty = function () {
34
- return this.length > 0;
236
+ return this.valueOf().length === 0;
237
+ };
238
+ /**
239
+ * Verifica se a string possui conteúdo (não está vazia).
240
+ * @returns true se a string possui pelo menos um caractere, false caso contrário
241
+ * @example
242
+ * "hello".isFilled() // true
243
+ * "".isFilled() // false
244
+ */
245
+ String.prototype.isFilled = function () {
246
+ return this.valueOf().length > 0;
247
+ };
248
+ /**
249
+ * Verifica se a string é um palíndromo (lida da mesma forma de frente para trás).
250
+ * @returns true se a string é um palíndromo, false caso contrário
251
+ * @example
252
+ * "racecar".isPalindrome() // true
253
+ * "hello".isPalindrome() // false
254
+ */
255
+ String.prototype.isPalindrome = function () {
256
+ const clean = this.valueOf().toLowerCase().removeWhitespace();
257
+ return clean === clean.split("").reverse().join("");
258
+ };
259
+ /**
260
+ * Verifica se a string representa um valor numérico válido.
261
+ * @returns true se a string pode ser convertida para número, false caso contrário
262
+ * @example
263
+ * "42".isNumeric() // true
264
+ * "3.14".isNumeric() // true
265
+ * "hello".isNumeric() // false
266
+ */
267
+ String.prototype.isNumeric = function () {
268
+ return !Number.isNaN(Number(this.valueOf())) && this.valueOf().isFilled();
269
+ };
270
+ /**
271
+ * Verifica se a string é um endereço de e-mail válido.
272
+ * @returns true se a string é um e-mail válido, false caso contrário
273
+ * @example
274
+ * "user@example.com".isEmail() // true
275
+ * "invalid-email".isEmail() // false
276
+ */
277
+ String.prototype.isEmail = function () {
278
+ return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(this.valueOf());
279
+ };
280
+ /**
281
+ * Verifica se a string é uma URL válida.
282
+ * @returns true se a string é uma URL válida, false caso contrário
283
+ * @example
284
+ * "https://example.com".isURL() // true
285
+ * "not a url".isURL() // false
286
+ */
287
+ String.prototype.isURL = function () {
288
+ try {
289
+ new URL(this.valueOf());
290
+ return true;
291
+ }
292
+ catch {
293
+ return false;
294
+ }
295
+ };
296
+ /**
297
+ * Verifica se a string é um UUID (Universally Unique Identifier) válido.
298
+ * @returns true se a string é um UUID válido, false caso contrário
299
+ * @example
300
+ * "550e8400-e29b-41d4-a716-446655440000".isUUID() // true
301
+ * "invalid-uuid".isUUID() // false
302
+ */
303
+ String.prototype.isUUID = function () {
304
+ return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(this.valueOf());
305
+ };
306
+ // ==================== Conversão ====================
307
+ /**
308
+ * Converte a string para o formato Base64.
309
+ * @returns String codificada em Base64
310
+ * @example
311
+ * "hello".toBase64() // "aGVsbG8="
312
+ */
313
+ String.prototype.toBase64 = function () {
314
+ return btoa(this.valueOf());
35
315
  };
316
+ /**
317
+ * Decodifica a string do formato Base64.
318
+ * @returns String decodificada do Base64
319
+ * @example
320
+ * "aGVsbG8=".fromBase64() // "hello"
321
+ */
36
322
  String.prototype.fromBase64 = function () {
37
- return atob(this.toString());
323
+ return atob(this.valueOf());
38
324
  };
@@ -1,9 +1,58 @@
1
+ /**
2
+ * Symbol que representa o estado de sucesso em estruturas de dutos.
3
+ * @example
4
+ * const isSuccess = result[SuccessReturn];
5
+ */
1
6
  export declare const SuccessReturn: unique symbol;
7
+ /**
8
+ * Symbol que representa o valor encapsulado em estruturas de dutos.
9
+ * @example
10
+ * const value = result[ValueReturn];
11
+ */
2
12
  export declare const ValueReturn: unique symbol;
13
+ /**
14
+ * Symbol utilitário para armazenar referência de função/valor.
15
+ * @example
16
+ * const fnHolder = { [FnVal]: () => "ok" };
17
+ */
3
18
  export declare const FnVal: unique symbol;
19
+ /**
20
+ * Array vazio imutável para reuso seguro.
21
+ * @example
22
+ * for (const item of EmptyArray) {
23
+ * // não executa
24
+ * }
25
+ */
4
26
  export declare const EmptyArray: readonly any[];
27
+ /**
28
+ * Conjunto de valores considerados falsey no domínio de dutos.
29
+ * @example
30
+ * const x: FalseyValues = "";
31
+ * const y: FalseyValues = 0;
32
+ */
5
33
  export type FalseyValues = false | null | undefined | 0 | 0n | "";
34
+ /**
35
+ * Verifica se um valor deve ser tratado como "truthy".
36
+ * - Para Date, valida se o timestamp é válido (não-NaN).
37
+ * - Para demais tipos, usa coerção booleana.
38
+ *
39
+ * @param val Valor a ser verificado.
40
+ * @returns true quando o valor é considerado válido/truthy.
41
+ * @example
42
+ * isTruthy("abc"); // true
43
+ * isTruthy(""); // false
44
+ * isTruthy(new Date()); // true
45
+ * isTruthy(new Date("invalid")); // false
46
+ */
6
47
  export declare function isTruthy(val: unknown): boolean;
48
+ /**
49
+ * Extrai o tipo do iterador de um tipo iterável.
50
+ * Retorna `unknown` quando o tipo não for iterável.
51
+ *
52
+ * @example
53
+ * type A = IterType<string[]>; // ArrayIterator<string>
54
+ * type B = IterType<number>; // unknown
55
+ */
7
56
  export type IterType<T> = T extends {
8
57
  [Symbol.iterator](): infer I;
9
58
  } ? I : unknown;
@@ -3,12 +3,45 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EmptyArray = exports.FnVal = exports.ValueReturn = exports.SuccessReturn = void 0;
4
4
  exports.isTruthy = isTruthy;
5
5
  const guardian_1 = require("../type-guard/guardian");
6
+ /**
7
+ * Symbol que representa o estado de sucesso em estruturas de dutos.
8
+ * @example
9
+ * const isSuccess = result[SuccessReturn];
10
+ */
6
11
  exports.SuccessReturn = Symbol("SuccessReturn");
12
+ /**
13
+ * Symbol que representa o valor encapsulado em estruturas de dutos.
14
+ * @example
15
+ * const value = result[ValueReturn];
16
+ */
7
17
  exports.ValueReturn = Symbol("ValueReturn");
18
+ /**
19
+ * Symbol utilitário para armazenar referência de função/valor.
20
+ * @example
21
+ * const fnHolder = { [FnVal]: () => "ok" };
22
+ */
8
23
  exports.FnVal = Symbol("FnVal");
24
+ /**
25
+ * Array vazio imutável para reuso seguro.
26
+ * @example
27
+ * for (const item of EmptyArray) {
28
+ * // não executa
29
+ * }
30
+ */
9
31
  exports.EmptyArray = Object.freeze([]);
32
+ /**
33
+ * Verifica se um valor deve ser tratado como "truthy".
34
+ * - Para Date, valida se o timestamp é válido (não-NaN).
35
+ * - Para demais tipos, usa coerção booleana.
36
+ *
37
+ * @param val Valor a ser verificado.
38
+ * @returns true quando o valor é considerado válido/truthy.
39
+ * @example
40
+ * isTruthy("abc"); // true
41
+ * isTruthy(""); // false
42
+ * isTruthy(new Date()); // true
43
+ * isTruthy(new Date("invalid")); // false
44
+ */
10
45
  function isTruthy(val) {
11
- return val instanceof Date
12
- ? guardian_1._.isEqual(val.getTime(), val.getTime())
13
- : !!val;
46
+ return val instanceof Date ? guardian_1._.isEqual(val.getTime(), val.getTime()) : !!val;
14
47
  }