@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
|
@@ -16,5 +16,254 @@ class UrlEdge extends string_edge_sketch_1.StringEdgeSketch {
|
|
|
16
16
|
throw new Error(`${this._url} should be a valid URL.`);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
+
// ==================== Getters ====================
|
|
20
|
+
/**
|
|
21
|
+
* Retorna a URL completa como string.
|
|
22
|
+
* @returns String com a URL completa
|
|
23
|
+
* @example
|
|
24
|
+
* new UrlEdge("https://example.com/path?q=1").toString()
|
|
25
|
+
* // "https://example.com/path?q=1"
|
|
26
|
+
*/
|
|
27
|
+
toString() {
|
|
28
|
+
return this._url;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Retorna o protocolo da URL (sem "://").
|
|
32
|
+
* @returns String com o protocolo
|
|
33
|
+
* @example
|
|
34
|
+
* new UrlEdge("https://example.com").getProtocol() // "https:"
|
|
35
|
+
* new UrlEdge("http://example.com").getProtocol() // "http:"
|
|
36
|
+
*/
|
|
37
|
+
getProtocol() {
|
|
38
|
+
return new URL(this._url).protocol;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Retorna o hostname da URL (sem porta).
|
|
42
|
+
* @returns String com o hostname
|
|
43
|
+
* @example
|
|
44
|
+
* new UrlEdge("https://example.com:8080/path").getHostname() // "example.com"
|
|
45
|
+
*/
|
|
46
|
+
getHostname() {
|
|
47
|
+
return new URL(this._url).hostname;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Retorna o host da URL (hostname + porta, se existir).
|
|
51
|
+
* @returns String com o host
|
|
52
|
+
* @example
|
|
53
|
+
* new UrlEdge("https://example.com:8080/path").getHost() // "example.com:8080"
|
|
54
|
+
* new UrlEdge("https://example.com/path").getHost() // "example.com"
|
|
55
|
+
*/
|
|
56
|
+
getHost() {
|
|
57
|
+
return new URL(this._url).host;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Retorna a porta da URL, se definida.
|
|
61
|
+
* @returns String com a porta ou string vazia se não definida
|
|
62
|
+
* @example
|
|
63
|
+
* new UrlEdge("https://example.com:8080/path").getPort() // "8080"
|
|
64
|
+
* new UrlEdge("https://example.com/path").getPort() // ""
|
|
65
|
+
*/
|
|
66
|
+
getPort() {
|
|
67
|
+
return new URL(this._url).port;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Retorna o pathname da URL.
|
|
71
|
+
* @returns String com o caminho da URL
|
|
72
|
+
* @example
|
|
73
|
+
* new UrlEdge("https://example.com/foo/bar").getPathname() // "/foo/bar"
|
|
74
|
+
* new UrlEdge("https://example.com").getPathname() // "/"
|
|
75
|
+
*/
|
|
76
|
+
getPathname() {
|
|
77
|
+
return new URL(this._url).pathname;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Retorna a query string da URL (incluindo "?").
|
|
81
|
+
* @returns String com a query string ou string vazia se não existir
|
|
82
|
+
* @example
|
|
83
|
+
* new UrlEdge("https://example.com/path?q=1&page=2").getSearch() // "?q=1&page=2"
|
|
84
|
+
* new UrlEdge("https://example.com/path").getSearch() // ""
|
|
85
|
+
*/
|
|
86
|
+
getSearch() {
|
|
87
|
+
return new URL(this._url).search;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Retorna o valor de um parâmetro específico da query string.
|
|
91
|
+
* @param key - Nome do parâmetro a buscar
|
|
92
|
+
* @returns Valor do parâmetro ou null se não existir
|
|
93
|
+
* @example
|
|
94
|
+
* new UrlEdge("https://example.com?q=hello&page=2").getSearchParam("q") // "hello"
|
|
95
|
+
* new UrlEdge("https://example.com?q=hello").getSearchParam("page") // null
|
|
96
|
+
*/
|
|
97
|
+
getSearchParam(key) {
|
|
98
|
+
return new URL(this._url).searchParams.get(key);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Retorna todos os parâmetros da query string como objeto.
|
|
102
|
+
* @returns Objeto com chave/valor de todos os parâmetros
|
|
103
|
+
* @example
|
|
104
|
+
* new UrlEdge("https://example.com?q=hello&page=2").getSearchParams()
|
|
105
|
+
* // { q: "hello", page: "2" }
|
|
106
|
+
*/
|
|
107
|
+
getSearchParams() {
|
|
108
|
+
const params = {};
|
|
109
|
+
new URL(this._url).searchParams.forEach((value, key) => {
|
|
110
|
+
params[key] = value;
|
|
111
|
+
});
|
|
112
|
+
return params;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Retorna o hash/fragmento da URL (incluindo "#").
|
|
116
|
+
* @returns String com o hash ou string vazia se não existir
|
|
117
|
+
* @example
|
|
118
|
+
* new UrlEdge("https://example.com/page#section-1").getHash() // "#section-1"
|
|
119
|
+
* new UrlEdge("https://example.com/page").getHash() // ""
|
|
120
|
+
*/
|
|
121
|
+
getHash() {
|
|
122
|
+
return new URL(this._url).hash;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Retorna a origem da URL (protocolo + host).
|
|
126
|
+
* @returns String com a origem
|
|
127
|
+
* @example
|
|
128
|
+
* new UrlEdge("https://example.com:8080/path?q=1").getOrigin() // "https://example.com:8080"
|
|
129
|
+
*/
|
|
130
|
+
getOrigin() {
|
|
131
|
+
return new URL(this._url).origin;
|
|
132
|
+
}
|
|
133
|
+
// ==================== Verificações ====================
|
|
134
|
+
/**
|
|
135
|
+
* Verifica se a URL usa o protocolo HTTPS.
|
|
136
|
+
* @returns true se o protocolo é HTTPS, false caso contrário
|
|
137
|
+
* @example
|
|
138
|
+
* new UrlEdge("https://example.com").isHttps() // true
|
|
139
|
+
* new UrlEdge("http://example.com").isHttps() // false
|
|
140
|
+
*/
|
|
141
|
+
isHttps() {
|
|
142
|
+
return new URL(this._url).protocol === "https:";
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Verifica se a URL usa o protocolo HTTP.
|
|
146
|
+
* @returns true se o protocolo é HTTP, false caso contrário
|
|
147
|
+
* @example
|
|
148
|
+
* new UrlEdge("http://example.com").isHttp() // true
|
|
149
|
+
* new UrlEdge("https://example.com").isHttp() // false
|
|
150
|
+
*/
|
|
151
|
+
isHttp() {
|
|
152
|
+
return new URL(this._url).protocol === "http:";
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Verifica se a URL possui query string.
|
|
156
|
+
* @returns true se a URL tem parâmetros de query, false caso contrário
|
|
157
|
+
* @example
|
|
158
|
+
* new UrlEdge("https://example.com?q=1").hasSearchParams() // true
|
|
159
|
+
* new UrlEdge("https://example.com").hasSearchParams() // false
|
|
160
|
+
*/
|
|
161
|
+
hasSearchParams() {
|
|
162
|
+
return new URL(this._url).searchParams.size > 0;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Verifica se a URL possui um parâmetro específico na query string.
|
|
166
|
+
* @param key - Nome do parâmetro a verificar
|
|
167
|
+
* @returns true se o parâmetro existe, false caso contrário
|
|
168
|
+
* @example
|
|
169
|
+
* new UrlEdge("https://example.com?q=1").hasSearchParam("q") // true
|
|
170
|
+
* new UrlEdge("https://example.com?q=1").hasSearchParam("page") // false
|
|
171
|
+
*/
|
|
172
|
+
hasSearchParam(key) {
|
|
173
|
+
return new URL(this._url).searchParams.has(key);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Verifica se a URL possui hash/fragmento.
|
|
177
|
+
* @returns true se a URL tem hash, false caso contrário
|
|
178
|
+
* @example
|
|
179
|
+
* new UrlEdge("https://example.com#section").hasHash() // true
|
|
180
|
+
* new UrlEdge("https://example.com").hasHash() // false
|
|
181
|
+
*/
|
|
182
|
+
hasHash() {
|
|
183
|
+
return new URL(this._url).hash.length > 0;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Verifica se esta URL é igual a outra.
|
|
187
|
+
* @param other - UrlEdge ou string para comparação
|
|
188
|
+
* @returns true se as URLs são iguais, false caso contrário
|
|
189
|
+
* @example
|
|
190
|
+
* const url = new UrlEdge("https://example.com");
|
|
191
|
+
* url.isEqual(new UrlEdge("https://example.com")) // true
|
|
192
|
+
* url.isEqual("https://other.com") // false
|
|
193
|
+
*/
|
|
194
|
+
isEqual(other) {
|
|
195
|
+
const comparand = other instanceof UrlEdge ? other.toString() : other;
|
|
196
|
+
return this._url === comparand;
|
|
197
|
+
}
|
|
198
|
+
// ==================== Transformação ====================
|
|
199
|
+
/**
|
|
200
|
+
* Retorna uma nova URL com um parâmetro de query adicionado ou atualizado.
|
|
201
|
+
* @param key - Nome do parâmetro
|
|
202
|
+
* @param value - Valor do parâmetro
|
|
203
|
+
* @returns Nova instância de UrlEdge com o parâmetro adicionado
|
|
204
|
+
* @example
|
|
205
|
+
* new UrlEdge("https://example.com?q=1").withSearchParam("page", "2")
|
|
206
|
+
* // UrlEdge("https://example.com?q=1&page=2")
|
|
207
|
+
*/
|
|
208
|
+
withSearchParam(key, value) {
|
|
209
|
+
const parsed = new URL(this._url);
|
|
210
|
+
parsed.searchParams.set(key, value);
|
|
211
|
+
return new UrlEdge(parsed.toString());
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Retorna uma nova URL sem um parâmetro de query específico.
|
|
215
|
+
* @param key - Nome do parâmetro a remover
|
|
216
|
+
* @returns Nova instância de UrlEdge sem o parâmetro
|
|
217
|
+
* @example
|
|
218
|
+
* new UrlEdge("https://example.com?q=1&page=2").withoutSearchParam("page")
|
|
219
|
+
* // UrlEdge("https://example.com?q=1")
|
|
220
|
+
*/
|
|
221
|
+
withoutSearchParam(key) {
|
|
222
|
+
const parsed = new URL(this._url);
|
|
223
|
+
parsed.searchParams.delete(key);
|
|
224
|
+
return new UrlEdge(parsed.toString());
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Retorna uma nova URL sem a query string.
|
|
228
|
+
* @returns Nova instância de UrlEdge sem query string
|
|
229
|
+
* @example
|
|
230
|
+
* new UrlEdge("https://example.com/path?q=1&page=2").withoutSearch()
|
|
231
|
+
* // UrlEdge("https://example.com/path")
|
|
232
|
+
*/
|
|
233
|
+
withoutSearch() {
|
|
234
|
+
const parsed = new URL(this._url);
|
|
235
|
+
parsed.search = "";
|
|
236
|
+
return new UrlEdge(parsed.toString());
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Retorna uma nova URL sem o hash/fragmento.
|
|
240
|
+
* @returns Nova instância de UrlEdge sem hash
|
|
241
|
+
* @example
|
|
242
|
+
* new UrlEdge("https://example.com/page#section").withoutHash()
|
|
243
|
+
* // UrlEdge("https://example.com/page")
|
|
244
|
+
*/
|
|
245
|
+
withoutHash() {
|
|
246
|
+
const parsed = new URL(this._url);
|
|
247
|
+
parsed.hash = "";
|
|
248
|
+
return new UrlEdge(parsed.toString());
|
|
249
|
+
}
|
|
250
|
+
// ==================== Métodos Estáticos ====================
|
|
251
|
+
/**
|
|
252
|
+
* Verifica se uma string é uma URL válida sem lançar exceção.
|
|
253
|
+
* @param value - String a ser verificada
|
|
254
|
+
* @returns true se a string é uma URL válida, false caso contrário
|
|
255
|
+
* @example
|
|
256
|
+
* UrlEdge.isValid("https://example.com") // true
|
|
257
|
+
* UrlEdge.isValid("not-a-url") // false
|
|
258
|
+
*/
|
|
259
|
+
static isValid(value) {
|
|
260
|
+
try {
|
|
261
|
+
new URL(value);
|
|
262
|
+
return true;
|
|
263
|
+
}
|
|
264
|
+
catch {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
19
268
|
}
|
|
20
269
|
exports.UrlEdge = UrlEdge;
|
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
import { StringEdgeSketch } from "../../primitives/string.edge.sketch";
|
|
2
2
|
export declare class UsernameEdge extends StringEdgeSketch {
|
|
3
|
+
private static readonly pattern;
|
|
4
|
+
constructor(username: string);
|
|
5
|
+
protected validateUsername(): void;
|
|
6
|
+
toString(): string;
|
|
7
|
+
toNormalized(): string;
|
|
8
|
+
isEqual(other: string | UsernameEdge, ignoreCase?: boolean): boolean;
|
|
9
|
+
hasOnlyAlphanumeric(): boolean;
|
|
10
|
+
startsWithLetter(): boolean;
|
|
11
|
+
static isValid(value: string): boolean;
|
|
3
12
|
}
|
|
@@ -3,5 +3,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.UsernameEdge = void 0;
|
|
4
4
|
const string_edge_sketch_1 = require("../../primitives/string.edge.sketch");
|
|
5
5
|
class UsernameEdge extends string_edge_sketch_1.StringEdgeSketch {
|
|
6
|
+
constructor(username) {
|
|
7
|
+
super(username);
|
|
8
|
+
this.validateUsername();
|
|
9
|
+
}
|
|
10
|
+
validateUsername() {
|
|
11
|
+
if (!UsernameEdge.pattern.test(this.toString())) {
|
|
12
|
+
throw new TypeError(`${this.constructor.name} should be valid (3-30, letters/numbers/._-, no separator at start/end).`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
// ==================== Getters ====================
|
|
16
|
+
toString() {
|
|
17
|
+
return super.toString();
|
|
18
|
+
}
|
|
19
|
+
toNormalized() {
|
|
20
|
+
return this.toString().toLowerCase();
|
|
21
|
+
}
|
|
22
|
+
// ==================== Verificações ====================
|
|
23
|
+
isEqual(other, ignoreCase = true) {
|
|
24
|
+
const comparand = other instanceof UsernameEdge ? other.toString() : other.trim();
|
|
25
|
+
return ignoreCase
|
|
26
|
+
? this.toString().toLowerCase() === comparand.toLowerCase()
|
|
27
|
+
: this.toString() === comparand;
|
|
28
|
+
}
|
|
29
|
+
hasOnlyAlphanumeric() {
|
|
30
|
+
return /^[a-zA-Z0-9]+$/.test(this.toString());
|
|
31
|
+
}
|
|
32
|
+
startsWithLetter() {
|
|
33
|
+
return /^[a-zA-Z]/.test(this.toString());
|
|
34
|
+
}
|
|
35
|
+
// ==================== Métodos Estáticos ====================
|
|
36
|
+
static isValid(value) {
|
|
37
|
+
return UsernameEdge.pattern.test(value.trim());
|
|
38
|
+
}
|
|
6
39
|
}
|
|
7
40
|
exports.UsernameEdge = UsernameEdge;
|
|
41
|
+
UsernameEdge.pattern = /^(?=.{3,30}$)[a-zA-Z0-9](?:[a-zA-Z0-9._-]*[a-zA-Z0-9])?$/;
|
|
@@ -2,6 +2,102 @@ export declare abstract class UuidSketchEdge {
|
|
|
2
2
|
private readonly value;
|
|
3
3
|
private static readonly pattern;
|
|
4
4
|
constructor(value?: string);
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Retorna o UUID como string.
|
|
7
|
+
* @returns String no formato UUID v4
|
|
8
|
+
* @example
|
|
9
|
+
* new MyUuidEdge("550e8400-e29b-41d4-a716-446655440000").toString()
|
|
10
|
+
* // "550e8400-e29b-41d4-a716-446655440000"
|
|
11
|
+
*/
|
|
6
12
|
toString(): string;
|
|
13
|
+
/**
|
|
14
|
+
* Retorna o UUID sem hífens.
|
|
15
|
+
* @returns String de 32 caracteres hexadecimais sem separadores
|
|
16
|
+
* @example
|
|
17
|
+
* new MyUuidEdge("550e8400-e29b-41d4-a716-446655440000").toRaw()
|
|
18
|
+
* // "550e8400e29b41d4a716446655440000"
|
|
19
|
+
*/
|
|
20
|
+
toRaw(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Retorna os segmentos do UUID separados em um array.
|
|
23
|
+
* @returns Array com 5 segmentos do UUID
|
|
24
|
+
* @example
|
|
25
|
+
* new MyUuidEdge("550e8400-e29b-41d4-a716-446655440000").toSegments()
|
|
26
|
+
* // ["550e8400", "e29b", "41d4", "a716", "446655440000"]
|
|
27
|
+
*/
|
|
28
|
+
toSegments(): string[];
|
|
29
|
+
/**
|
|
30
|
+
* Verifica se este UUID é igual a outro.
|
|
31
|
+
* @param other - UuidSketchEdge para comparação
|
|
32
|
+
* @returns true se os UUIDs são iguais, false caso contrário
|
|
33
|
+
* @example
|
|
34
|
+
* const id = new MyUuidEdge("550e8400-e29b-41d4-a716-446655440000");
|
|
35
|
+
* id.isEqual(id) // true
|
|
36
|
+
*/
|
|
37
|
+
isEqual(other: UuidSketchEdge): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Verifica se este UUID é diferente de outro.
|
|
40
|
+
* @param other - UuidSketchEdge para comparação
|
|
41
|
+
* @returns true se os UUIDs são diferentes, false caso contrário
|
|
42
|
+
* @example
|
|
43
|
+
* const a = new MyUuidEdge("550e8400-e29b-41d4-a716-446655440000");
|
|
44
|
+
* const b = new MyUuidEdge("661f9511-f3ac-52e5-b827-557766551111");
|
|
45
|
+
* a.isDifferent(b) // true
|
|
46
|
+
*/
|
|
47
|
+
isDifferent(other: UuidSketchEdge): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated Use `isEqual` instead.
|
|
50
|
+
* Verifica se este UUID é igual a outro.
|
|
51
|
+
* @param other - UuidSketchEdge para comparação
|
|
52
|
+
* @returns true se os UUIDs são iguais, false caso contrário
|
|
53
|
+
*/
|
|
54
|
+
equals(other: UuidSketchEdge): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Verifica se o UUID está em letras maiúsculas.
|
|
57
|
+
* @returns true se todos os caracteres alfabéticos são maiúsculos
|
|
58
|
+
* @example
|
|
59
|
+
* new MyUuidEdge("550E8400-E29B-41D4-A716-446655440000").isUpperCase() // true
|
|
60
|
+
* new MyUuidEdge("550e8400-e29b-41d4-a716-446655440000").isUpperCase() // false
|
|
61
|
+
*/
|
|
62
|
+
isUpperCase(): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Verifica se o UUID está em letras minúsculas.
|
|
65
|
+
* @returns true se todos os caracteres alfabéticos são minúsculos
|
|
66
|
+
* @example
|
|
67
|
+
* new MyUuidEdge("550e8400-e29b-41d4-a716-446655440000").isLowerCase() // true
|
|
68
|
+
* new MyUuidEdge("550E8400-E29B-41D4-A716-446655440000").isLowerCase() // false
|
|
69
|
+
*/
|
|
70
|
+
isLowerCase(): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Retorna o UUID em letras maiúsculas como string.
|
|
73
|
+
* @returns UUID em maiúsculas
|
|
74
|
+
* @example
|
|
75
|
+
* new MyUuidEdge("550e8400-e29b-41d4-a716-446655440000").toUpperCase()
|
|
76
|
+
* // "550E8400-E29B-41D4-A716-446655440000"
|
|
77
|
+
*/
|
|
78
|
+
toUpperCase(): string;
|
|
79
|
+
/**
|
|
80
|
+
* Retorna o UUID em letras minúsculas como string.
|
|
81
|
+
* @returns UUID em minúsculas
|
|
82
|
+
* @example
|
|
83
|
+
* new MyUuidEdge("550E8400-E29B-41D4-A716-446655440000").toLowerCase()
|
|
84
|
+
* // "550e8400-e29b-41d4-a716-446655440000"
|
|
85
|
+
*/
|
|
86
|
+
toLowerCase(): string;
|
|
87
|
+
/**
|
|
88
|
+
* Verifica se uma string é um UUID válido sem lançar exceção.
|
|
89
|
+
* @param value - String a ser verificada
|
|
90
|
+
* @returns true se a string é um UUID válido, false caso contrário
|
|
91
|
+
* @example
|
|
92
|
+
* UuidSketchEdge.isValid("550e8400-e29b-41d4-a716-446655440000") // true
|
|
93
|
+
* UuidSketchEdge.isValid("invalid-uuid") // false
|
|
94
|
+
*/
|
|
95
|
+
static isValid(value: string): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Gera uma nova string UUID v4 sem instanciar a classe.
|
|
98
|
+
* @returns String no formato UUID v4
|
|
99
|
+
* @example
|
|
100
|
+
* UuidSketchEdge.generate() // "a3f8c210-4d92-11ec-81d3-0242ac130003"
|
|
101
|
+
*/
|
|
102
|
+
static generate(): string;
|
|
7
103
|
}
|
|
@@ -7,18 +7,139 @@ exports.UuidSketchEdge = void 0;
|
|
|
7
7
|
const react_native_uuid_1 = __importDefault(require("react-native-uuid"));
|
|
8
8
|
const index_1 = require("../../../index");
|
|
9
9
|
class UuidSketchEdge {
|
|
10
|
-
constructor(value = react_native_uuid_1.default.v4()) {
|
|
10
|
+
constructor(value = String(react_native_uuid_1.default.v4())) {
|
|
11
11
|
this.value = value;
|
|
12
|
-
if (!UuidSketchEdge.pattern.test(value)) {
|
|
12
|
+
if (!UuidSketchEdge.pattern.test(this.value)) {
|
|
13
13
|
throw new TypeError("The provided UUID is invalid. Please ensure it is in the correct format");
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
// ==================== Getters ====================
|
|
17
|
+
/**
|
|
18
|
+
* Retorna o UUID como string.
|
|
19
|
+
* @returns String no formato UUID v4
|
|
20
|
+
* @example
|
|
21
|
+
* new MyUuidEdge("550e8400-e29b-41d4-a716-446655440000").toString()
|
|
22
|
+
* // "550e8400-e29b-41d4-a716-446655440000"
|
|
23
|
+
*/
|
|
19
24
|
toString() {
|
|
20
25
|
return this.value;
|
|
21
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Retorna o UUID sem hífens.
|
|
29
|
+
* @returns String de 32 caracteres hexadecimais sem separadores
|
|
30
|
+
* @example
|
|
31
|
+
* new MyUuidEdge("550e8400-e29b-41d4-a716-446655440000").toRaw()
|
|
32
|
+
* // "550e8400e29b41d4a716446655440000"
|
|
33
|
+
*/
|
|
34
|
+
toRaw() {
|
|
35
|
+
return this.value.replace(/-/g, "");
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Retorna os segmentos do UUID separados em um array.
|
|
39
|
+
* @returns Array com 5 segmentos do UUID
|
|
40
|
+
* @example
|
|
41
|
+
* new MyUuidEdge("550e8400-e29b-41d4-a716-446655440000").toSegments()
|
|
42
|
+
* // ["550e8400", "e29b", "41d4", "a716", "446655440000"]
|
|
43
|
+
*/
|
|
44
|
+
toSegments() {
|
|
45
|
+
return this.value.split("-");
|
|
46
|
+
}
|
|
47
|
+
// ==================== Comparações ====================
|
|
48
|
+
/**
|
|
49
|
+
* Verifica se este UUID é igual a outro.
|
|
50
|
+
* @param other - UuidSketchEdge para comparação
|
|
51
|
+
* @returns true se os UUIDs são iguais, false caso contrário
|
|
52
|
+
* @example
|
|
53
|
+
* const id = new MyUuidEdge("550e8400-e29b-41d4-a716-446655440000");
|
|
54
|
+
* id.isEqual(id) // true
|
|
55
|
+
*/
|
|
56
|
+
isEqual(other) {
|
|
57
|
+
return index_1._.isEqual(this.value, other.toString());
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Verifica se este UUID é diferente de outro.
|
|
61
|
+
* @param other - UuidSketchEdge para comparação
|
|
62
|
+
* @returns true se os UUIDs são diferentes, false caso contrário
|
|
63
|
+
* @example
|
|
64
|
+
* const a = new MyUuidEdge("550e8400-e29b-41d4-a716-446655440000");
|
|
65
|
+
* const b = new MyUuidEdge("661f9511-f3ac-52e5-b827-557766551111");
|
|
66
|
+
* a.isDifferent(b) // true
|
|
67
|
+
*/
|
|
68
|
+
isDifferent(other) {
|
|
69
|
+
return !this.isEqual(other);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* @deprecated Use `isEqual` instead.
|
|
73
|
+
* Verifica se este UUID é igual a outro.
|
|
74
|
+
* @param other - UuidSketchEdge para comparação
|
|
75
|
+
* @returns true se os UUIDs são iguais, false caso contrário
|
|
76
|
+
*/
|
|
77
|
+
equals(other) {
|
|
78
|
+
return this.isEqual(other);
|
|
79
|
+
}
|
|
80
|
+
// ==================== Verificações ====================
|
|
81
|
+
/**
|
|
82
|
+
* Verifica se o UUID está em letras maiúsculas.
|
|
83
|
+
* @returns true se todos os caracteres alfabéticos são maiúsculos
|
|
84
|
+
* @example
|
|
85
|
+
* new MyUuidEdge("550E8400-E29B-41D4-A716-446655440000").isUpperCase() // true
|
|
86
|
+
* new MyUuidEdge("550e8400-e29b-41d4-a716-446655440000").isUpperCase() // false
|
|
87
|
+
*/
|
|
88
|
+
isUpperCase() {
|
|
89
|
+
return this.value === this.value.toUpperCase();
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Verifica se o UUID está em letras minúsculas.
|
|
93
|
+
* @returns true se todos os caracteres alfabéticos são minúsculos
|
|
94
|
+
* @example
|
|
95
|
+
* new MyUuidEdge("550e8400-e29b-41d4-a716-446655440000").isLowerCase() // true
|
|
96
|
+
* new MyUuidEdge("550E8400-E29B-41D4-A716-446655440000").isLowerCase() // false
|
|
97
|
+
*/
|
|
98
|
+
isLowerCase() {
|
|
99
|
+
return this.value === this.value.toLowerCase();
|
|
100
|
+
}
|
|
101
|
+
// ==================== Transformação ====================
|
|
102
|
+
/**
|
|
103
|
+
* Retorna o UUID em letras maiúsculas como string.
|
|
104
|
+
* @returns UUID em maiúsculas
|
|
105
|
+
* @example
|
|
106
|
+
* new MyUuidEdge("550e8400-e29b-41d4-a716-446655440000").toUpperCase()
|
|
107
|
+
* // "550E8400-E29B-41D4-A716-446655440000"
|
|
108
|
+
*/
|
|
109
|
+
toUpperCase() {
|
|
110
|
+
return this.value.toUpperCase();
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Retorna o UUID em letras minúsculas como string.
|
|
114
|
+
* @returns UUID em minúsculas
|
|
115
|
+
* @example
|
|
116
|
+
* new MyUuidEdge("550E8400-E29B-41D4-A716-446655440000").toLowerCase()
|
|
117
|
+
* // "550e8400-e29b-41d4-a716-446655440000"
|
|
118
|
+
*/
|
|
119
|
+
toLowerCase() {
|
|
120
|
+
return this.value.toLowerCase();
|
|
121
|
+
}
|
|
122
|
+
// ==================== Métodos Estáticos ====================
|
|
123
|
+
/**
|
|
124
|
+
* Verifica se uma string é um UUID válido sem lançar exceção.
|
|
125
|
+
* @param value - String a ser verificada
|
|
126
|
+
* @returns true se a string é um UUID válido, false caso contrário
|
|
127
|
+
* @example
|
|
128
|
+
* UuidSketchEdge.isValid("550e8400-e29b-41d4-a716-446655440000") // true
|
|
129
|
+
* UuidSketchEdge.isValid("invalid-uuid") // false
|
|
130
|
+
*/
|
|
131
|
+
static isValid(value) {
|
|
132
|
+
return UuidSketchEdge.pattern.test(value);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Gera uma nova string UUID v4 sem instanciar a classe.
|
|
136
|
+
* @returns String no formato UUID v4
|
|
137
|
+
* @example
|
|
138
|
+
* UuidSketchEdge.generate() // "a3f8c210-4d92-11ec-81d3-0242ac130003"
|
|
139
|
+
*/
|
|
140
|
+
static generate() {
|
|
141
|
+
return String(react_native_uuid_1.default.v4());
|
|
142
|
+
}
|
|
22
143
|
}
|
|
23
144
|
exports.UuidSketchEdge = UuidSketchEdge;
|
|
24
|
-
UuidSketchEdge.pattern = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
145
|
+
UuidSketchEdge.pattern = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { NumberEdgeSketch } from "../primitives/number.edge.sketch";
|
|
2
|
+
export declare class AmountValueEdge extends NumberEdgeSketch {
|
|
3
|
+
constructor(value: number);
|
|
4
|
+
/**
|
|
5
|
+
* Retorna o valor em centavos.
|
|
6
|
+
* Ex.: 10.25 -> 1025
|
|
7
|
+
*/
|
|
8
|
+
toCents(): number;
|
|
9
|
+
/**
|
|
10
|
+
* Formata o valor monetário.
|
|
11
|
+
*/
|
|
12
|
+
toCurrency(locale?: string, currency?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Indica se possui mais de 2 casas decimais.
|
|
15
|
+
*/
|
|
16
|
+
hasMoreThanTwoDecimals(): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Retorna novo AmountValueEdge somando com outro valor.
|
|
19
|
+
*/
|
|
20
|
+
plus(value: number | AmountValueEdge): AmountValueEdge;
|
|
21
|
+
/**
|
|
22
|
+
* Retorna novo AmountValueEdge subtraindo outro valor.
|
|
23
|
+
*/
|
|
24
|
+
minus(value: number | AmountValueEdge): AmountValueEdge;
|
|
25
|
+
/**
|
|
26
|
+
* Cria AmountValueEdge a partir de centavos.
|
|
27
|
+
*/
|
|
28
|
+
static fromCents(cents: number): AmountValueEdge;
|
|
29
|
+
/**
|
|
30
|
+
* Cria AmountValueEdge zerado.
|
|
31
|
+
*/
|
|
32
|
+
static zero(): AmountValueEdge;
|
|
33
|
+
/**
|
|
34
|
+
* Verifica se um número pode ser usado como amount.
|
|
35
|
+
*/
|
|
36
|
+
static isValid(value: number): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Bug fix: NumberEdgeSketch valida NaN, mas permite Infinity.
|
|
39
|
+
* Para amount monetário, restringimos para número finito.
|
|
40
|
+
*/
|
|
41
|
+
private validateAmount;
|
|
42
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AmountValueEdge = void 0;
|
|
4
|
+
const number_edge_sketch_1 = require("../primitives/number.edge.sketch");
|
|
5
|
+
class AmountValueEdge extends number_edge_sketch_1.NumberEdgeSketch {
|
|
6
|
+
constructor(value) {
|
|
7
|
+
super(value);
|
|
8
|
+
this.validateAmount();
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Retorna o valor em centavos.
|
|
12
|
+
* Ex.: 10.25 -> 1025
|
|
13
|
+
*/
|
|
14
|
+
toCents() {
|
|
15
|
+
return Math.round(this.toNumber() * 100);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Formata o valor monetário.
|
|
19
|
+
*/
|
|
20
|
+
toCurrency(locale = "pt-BR", currency = "BRL") {
|
|
21
|
+
return new Intl.NumberFormat(locale, {
|
|
22
|
+
style: "currency",
|
|
23
|
+
currency,
|
|
24
|
+
}).format(this.toNumber());
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Indica se possui mais de 2 casas decimais.
|
|
28
|
+
*/
|
|
29
|
+
hasMoreThanTwoDecimals() {
|
|
30
|
+
return !Number.isInteger(this.toNumber() * 100);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Retorna novo AmountValueEdge somando com outro valor.
|
|
34
|
+
*/
|
|
35
|
+
plus(value) {
|
|
36
|
+
const operand = value instanceof AmountValueEdge ? value.toNumber() : value;
|
|
37
|
+
const resultInCents = this.toCents() + Math.round(operand * 100);
|
|
38
|
+
return AmountValueEdge.fromCents(resultInCents);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Retorna novo AmountValueEdge subtraindo outro valor.
|
|
42
|
+
*/
|
|
43
|
+
minus(value) {
|
|
44
|
+
const operand = value instanceof AmountValueEdge ? value.toNumber() : value;
|
|
45
|
+
const resultInCents = this.toCents() - Math.round(operand * 100);
|
|
46
|
+
return AmountValueEdge.fromCents(resultInCents);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Cria AmountValueEdge a partir de centavos.
|
|
50
|
+
*/
|
|
51
|
+
static fromCents(cents) {
|
|
52
|
+
return new AmountValueEdge(cents / 100);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Cria AmountValueEdge zerado.
|
|
56
|
+
*/
|
|
57
|
+
static zero() {
|
|
58
|
+
return new AmountValueEdge(0);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Verifica se um número pode ser usado como amount.
|
|
62
|
+
*/
|
|
63
|
+
static isValid(value) {
|
|
64
|
+
return Number.isFinite(value);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Bug fix: NumberEdgeSketch valida NaN, mas permite Infinity.
|
|
68
|
+
* Para amount monetário, restringimos para número finito.
|
|
69
|
+
*/
|
|
70
|
+
validateAmount() {
|
|
71
|
+
if (!Number.isFinite(this.toNumber())) {
|
|
72
|
+
throw new TypeError(`${this.constructor.name} should be a finite number.`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.AmountValueEdge = AmountValueEdge;
|