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