@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
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { FalseyValues, IterType, SuccessReturn, ValueReturn } from "./common";
|
|
1
|
+
import { FalseyValues, IterType, SuccessReturn as SuccessReturnSymbol, ValueReturn as ValueReturnSymbol } from "./common";
|
|
2
2
|
import { FailureAbstract } from "../../../objects/failure/edges/failure.abstract";
|
|
3
|
-
export type Success<
|
|
4
|
-
export type Failure<
|
|
5
|
-
export type Return<
|
|
3
|
+
export type Success<TSuccess> = ReturnType<TSuccess, never>;
|
|
4
|
+
export type Failure<TFailure> = ReturnType<never, TFailure>;
|
|
5
|
+
export type Return<TSuccess, TFailure> = ReturnType<TSuccess, TFailure>;
|
|
6
6
|
type From<T> = Exclude<T, Error | FalseyValues>;
|
|
7
|
-
export declare class ReturnType<
|
|
8
|
-
readonly [
|
|
9
|
-
readonly [
|
|
10
|
-
constructor(value:
|
|
11
|
-
[Symbol.iterator](this: Return<
|
|
12
|
-
hasSuccess(this: Return<
|
|
13
|
-
hasFailure(this: Return<
|
|
14
|
-
unwrap(this: Return<
|
|
15
|
-
unwrapFail(this: Return<
|
|
16
|
-
unwrapOr(this: Return<
|
|
17
|
-
unwrapAnyway(this: Return<
|
|
7
|
+
export declare class ReturnType<TSuccess, TFailure> {
|
|
8
|
+
readonly [SuccessReturnSymbol]: boolean;
|
|
9
|
+
readonly [ValueReturnSymbol]: TSuccess | TFailure | undefined;
|
|
10
|
+
constructor(value: TSuccess | TFailure | undefined, hasSuccess: boolean);
|
|
11
|
+
[Symbol.iterator](this: Return<TSuccess, TFailure>): IterType<TSuccess>;
|
|
12
|
+
hasSuccess(this: Return<TSuccess, TFailure>): this is Success<TSuccess>;
|
|
13
|
+
hasFailure(this: Return<TSuccess, TFailure>): this is Failure<TFailure>;
|
|
14
|
+
unwrap(this: Return<TSuccess, TFailure>): TSuccess;
|
|
15
|
+
unwrapFail(this: Return<TSuccess, TFailure>): TFailure;
|
|
16
|
+
unwrapOr(this: Return<TSuccess, TFailure>, def: TSuccess): TSuccess;
|
|
17
|
+
unwrapAnyway(this: Return<TSuccess, TFailure>): TSuccess | TFailure | undefined;
|
|
18
18
|
}
|
|
19
19
|
export declare function Return<T>(val: T): Return<From<T>, (T extends Error ? T : never) | (Extract<FalseyValues, T> extends never ? never : null)>;
|
|
20
|
-
export declare function Success<
|
|
21
|
-
export declare function Failure<
|
|
20
|
+
export declare function Success<TSuccess>(successValue?: TSuccess): Success<TSuccess>;
|
|
21
|
+
export declare function Failure<TFailure extends FailureAbstract | Error | null | undefined>(failureValue?: TFailure): Failure<TFailure>;
|
|
22
22
|
export {};
|
|
@@ -11,9 +11,17 @@ class ReturnType {
|
|
|
11
11
|
this[common_1.SuccessReturn] = hasSuccess;
|
|
12
12
|
}
|
|
13
13
|
[Symbol.iterator]() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
if (!this[common_1.SuccessReturn]) {
|
|
15
|
+
return common_1.EmptyArray[Symbol.iterator]();
|
|
16
|
+
}
|
|
17
|
+
const value = this[common_1.ValueReturn];
|
|
18
|
+
if (value !== null &&
|
|
19
|
+
value !== undefined &&
|
|
20
|
+
typeof value[Symbol.iterator] ===
|
|
21
|
+
"function") {
|
|
22
|
+
return value[Symbol.iterator]();
|
|
23
|
+
}
|
|
24
|
+
return common_1.EmptyArray[Symbol.iterator]();
|
|
17
25
|
}
|
|
18
26
|
hasSuccess() {
|
|
19
27
|
return this[common_1.SuccessReturn];
|
|
@@ -34,7 +42,9 @@ class ReturnType {
|
|
|
34
42
|
return this[common_1.ValueReturn];
|
|
35
43
|
}
|
|
36
44
|
unwrapOr(def) {
|
|
37
|
-
return this[common_1.SuccessReturn]
|
|
45
|
+
return this[common_1.SuccessReturn]
|
|
46
|
+
? this[common_1.ValueReturn]
|
|
47
|
+
: def;
|
|
38
48
|
}
|
|
39
49
|
unwrapAnyway() {
|
|
40
50
|
return this[common_1.ValueReturn];
|
|
@@ -7,5 +7,11 @@ export declare class HttpProvider {
|
|
|
7
7
|
readonly baseUrl: string;
|
|
8
8
|
protected readonly axios: AxiosInstance;
|
|
9
9
|
constructor(baseUrl: string);
|
|
10
|
+
setDefaultHeader(key: string, value: string): void;
|
|
11
|
+
removeDefaultHeader(key: string): void;
|
|
12
|
+
setBearerToken(token: string): void;
|
|
10
13
|
request(request: RequestAbstract): Promise<Return<HttpProviderSuccessResponse, HttpProviderFailureResponse>>;
|
|
14
|
+
private isSuccessStatus;
|
|
15
|
+
private buildFailureFromResponse;
|
|
16
|
+
private extractErrorMessage;
|
|
11
17
|
}
|
|
@@ -8,7 +8,6 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
8
8
|
const return_type_1 = require("../ducts/return-type");
|
|
9
9
|
const http_provider_failure_response_1 = require("./http-provider-failure-response");
|
|
10
10
|
const http_provider_success_response_1 = require("./http-provider-success-response");
|
|
11
|
-
const guardian_1 = require("../type-guard/guardian");
|
|
12
11
|
const http_status_codes_point_1 = require("../../../objects/@common/points/http-status-codes.point");
|
|
13
12
|
function replaceUrlParams(url, params) {
|
|
14
13
|
return url.replace(/:([a-zA-Z0-9_]+)/g, (_, key) => {
|
|
@@ -26,31 +25,61 @@ class HttpProvider {
|
|
|
26
25
|
baseURL: baseUrl,
|
|
27
26
|
});
|
|
28
27
|
}
|
|
28
|
+
setDefaultHeader(key, value) {
|
|
29
|
+
this.axios.defaults.headers.common[key] = value;
|
|
30
|
+
}
|
|
31
|
+
removeDefaultHeader(key) {
|
|
32
|
+
delete this.axios.defaults.headers.common[key];
|
|
33
|
+
}
|
|
34
|
+
setBearerToken(token) {
|
|
35
|
+
this.setDefaultHeader("Authorization", `Bearer ${token}`);
|
|
36
|
+
}
|
|
29
37
|
async request(request) {
|
|
38
|
+
let resolvedUrl = request.url;
|
|
30
39
|
try {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
url = replaceUrlParams(url, request.params);
|
|
40
|
+
if (request.params) {
|
|
41
|
+
resolvedUrl = replaceUrlParams(resolvedUrl, request.params);
|
|
34
42
|
}
|
|
35
43
|
const response = await this.axios.request({
|
|
36
|
-
url,
|
|
44
|
+
url: resolvedUrl,
|
|
37
45
|
method: request.method,
|
|
38
|
-
params:
|
|
46
|
+
params: request.queryParams,
|
|
39
47
|
data: request.payload,
|
|
40
|
-
headers:
|
|
48
|
+
headers: request.headers,
|
|
41
49
|
responseType: request.responseType,
|
|
42
|
-
validateStatus: (
|
|
43
|
-
return true;
|
|
44
|
-
},
|
|
50
|
+
validateStatus: () => true,
|
|
45
51
|
});
|
|
46
|
-
if (
|
|
47
|
-
return (0, return_type_1.Failure)(
|
|
52
|
+
if (!this.isSuccessStatus(response.status)) {
|
|
53
|
+
return (0, return_type_1.Failure)(this.buildFailureFromResponse(response, resolvedUrl));
|
|
48
54
|
}
|
|
49
55
|
return (0, return_type_1.Success)(new http_provider_success_response_1.HttpProviderSuccessResponse(response.status, response.data));
|
|
50
56
|
}
|
|
51
|
-
catch {
|
|
52
|
-
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (axios_1.default.isAxiosError(error) && error.response) {
|
|
59
|
+
return (0, return_type_1.Failure)(this.buildFailureFromResponse(error.response, resolvedUrl));
|
|
60
|
+
}
|
|
61
|
+
return (0, return_type_1.Failure)(new http_provider_failure_response_1.HttpProviderFailureResponse("The request could not be completed. The server is currently unavailable.", http_status_codes_point_1.HttpStatusCodes.SERVICE_UNAVAILABLE, resolvedUrl));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
isSuccessStatus(status) {
|
|
65
|
+
return status >= 200 && status < 300;
|
|
66
|
+
}
|
|
67
|
+
buildFailureFromResponse(response, url) {
|
|
68
|
+
return new http_provider_failure_response_1.HttpProviderFailureResponse(this.extractErrorMessage(response.data, response.statusText), response.status, url);
|
|
69
|
+
}
|
|
70
|
+
extractErrorMessage(data, fallback) {
|
|
71
|
+
if (typeof data === "string" && data.trim().length > 0) {
|
|
72
|
+
return data;
|
|
73
|
+
}
|
|
74
|
+
if (data && typeof data === "object") {
|
|
75
|
+
const maybeMessage = data.message;
|
|
76
|
+
if (typeof maybeMessage === "string" && maybeMessage.trim().length > 0) {
|
|
77
|
+
return maybeMessage;
|
|
78
|
+
}
|
|
53
79
|
}
|
|
80
|
+
return fallback?.trim()
|
|
81
|
+
? fallback
|
|
82
|
+
: "The request failed. Please try again later.";
|
|
54
83
|
}
|
|
55
84
|
}
|
|
56
85
|
exports.HttpProvider = HttpProvider;
|
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
export declare abstract class MapAbstract<K, V> {
|
|
2
2
|
protected abstract map: Map<K, V>;
|
|
3
|
+
/**
|
|
4
|
+
* Mantido por compatibilidade.
|
|
5
|
+
* Retorna o valor mapeado para a chave ou lança erro.
|
|
6
|
+
*/
|
|
3
7
|
toMap(key: K): V;
|
|
8
|
+
/**
|
|
9
|
+
* Retorna o valor mapeado para a chave ou lança erro.
|
|
10
|
+
*/
|
|
11
|
+
get(key: K): V;
|
|
12
|
+
/**
|
|
13
|
+
* Retorna true se a chave existir no map.
|
|
14
|
+
*/
|
|
15
|
+
has(key: K): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Retorna o valor ou undefined.
|
|
18
|
+
*/
|
|
19
|
+
getOrUndefined(key: K): V | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Retorna a quantidade de itens.
|
|
22
|
+
*/
|
|
23
|
+
size(): number;
|
|
24
|
+
/**
|
|
25
|
+
* Retorna true se o map estiver vazio.
|
|
26
|
+
*/
|
|
27
|
+
isEmpty(): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Retorna todas as chaves.
|
|
30
|
+
*/
|
|
31
|
+
keys(): K[];
|
|
32
|
+
/**
|
|
33
|
+
* Retorna todos os valores.
|
|
34
|
+
*/
|
|
35
|
+
values(): V[];
|
|
36
|
+
/**
|
|
37
|
+
* Retorna todas as entradas.
|
|
38
|
+
*/
|
|
39
|
+
entries(): Array<[K, V]>;
|
|
4
40
|
protected getOrDefault(key: K, defaultValue: V): V;
|
|
5
41
|
protected getOrThrow(key: K, errorMessage?: string): V;
|
|
42
|
+
protected set(key: K, value: V): void;
|
|
43
|
+
protected delete(key: K): boolean;
|
|
44
|
+
protected clear(): void;
|
|
6
45
|
}
|
|
@@ -1,20 +1,84 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MapAbstract = void 0;
|
|
4
|
-
const guardian_1 = require("../type-guard/guardian");
|
|
5
4
|
class MapAbstract {
|
|
5
|
+
/**
|
|
6
|
+
* Mantido por compatibilidade.
|
|
7
|
+
* Retorna o valor mapeado para a chave ou lança erro.
|
|
8
|
+
*/
|
|
6
9
|
toMap(key) {
|
|
7
10
|
return this.getOrThrow(key);
|
|
8
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Retorna o valor mapeado para a chave ou lança erro.
|
|
14
|
+
*/
|
|
15
|
+
get(key) {
|
|
16
|
+
return this.getOrThrow(key);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Retorna true se a chave existir no map.
|
|
20
|
+
*/
|
|
21
|
+
has(key) {
|
|
22
|
+
return this.map.has(key);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Retorna o valor ou undefined.
|
|
26
|
+
*/
|
|
27
|
+
getOrUndefined(key) {
|
|
28
|
+
return this.map.get(key);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Retorna a quantidade de itens.
|
|
32
|
+
*/
|
|
33
|
+
size() {
|
|
34
|
+
return this.map.size;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Retorna true se o map estiver vazio.
|
|
38
|
+
*/
|
|
39
|
+
isEmpty() {
|
|
40
|
+
return this.map.size === 0;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Retorna todas as chaves.
|
|
44
|
+
*/
|
|
45
|
+
keys() {
|
|
46
|
+
return Array.from(this.map.keys());
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Retorna todos os valores.
|
|
50
|
+
*/
|
|
51
|
+
values() {
|
|
52
|
+
return Array.from(this.map.values());
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Retorna todas as entradas.
|
|
56
|
+
*/
|
|
57
|
+
entries() {
|
|
58
|
+
return Array.from(this.map.entries());
|
|
59
|
+
}
|
|
9
60
|
getOrDefault(key, defaultValue) {
|
|
10
|
-
|
|
61
|
+
// bug fix: usar has() evita confundir chave existente com valor undefined
|
|
62
|
+
if (!this.map.has(key)) {
|
|
63
|
+
return defaultValue;
|
|
64
|
+
}
|
|
65
|
+
return this.map.get(key);
|
|
11
66
|
}
|
|
12
67
|
getOrThrow(key, errorMessage = "Key not mapped") {
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
throw Error(errorMessage);
|
|
68
|
+
// bug fix: validar existência da chave com has(), não pelo valor retornado
|
|
69
|
+
if (!this.map.has(key)) {
|
|
70
|
+
throw new Error(errorMessage);
|
|
16
71
|
}
|
|
17
|
-
return
|
|
72
|
+
return this.map.get(key);
|
|
73
|
+
}
|
|
74
|
+
set(key, value) {
|
|
75
|
+
this.map.set(key, value);
|
|
76
|
+
}
|
|
77
|
+
delete(key) {
|
|
78
|
+
return this.map.delete(key);
|
|
79
|
+
}
|
|
80
|
+
clear() {
|
|
81
|
+
this.map.clear();
|
|
18
82
|
}
|
|
19
83
|
}
|
|
20
84
|
exports.MapAbstract = MapAbstract;
|
|
@@ -1,5 +1,173 @@
|
|
|
1
1
|
export declare class Random {
|
|
2
|
+
/**
|
|
3
|
+
* Gera um número inteiro aleatório dentro de um intervalo (inclusivo).
|
|
4
|
+
* @param min - Valor mínimo do intervalo
|
|
5
|
+
* @param max - Valor máximo do intervalo
|
|
6
|
+
* @returns Número inteiro aleatório entre min e max
|
|
7
|
+
* @example
|
|
8
|
+
* Random.number(1, 10) // pode retornar qualquer inteiro entre 1 e 10
|
|
9
|
+
*/
|
|
2
10
|
static number(min: number, max: number): number;
|
|
11
|
+
/**
|
|
12
|
+
* Gera um número decimal (float) aleatório dentro de um intervalo.
|
|
13
|
+
* @param min - Valor mínimo do intervalo
|
|
14
|
+
* @param max - Valor máximo do intervalo
|
|
15
|
+
* @param precision - Número de casas decimais (padrão: 2)
|
|
16
|
+
* @returns Número decimal aleatório entre min e max
|
|
17
|
+
* @example
|
|
18
|
+
* Random.float(1, 10) // pode retornar algo como 4.73
|
|
19
|
+
* Random.float(1, 10, 4) // pode retornar algo como 4.7312
|
|
20
|
+
*/
|
|
21
|
+
static float(min: number, max: number, precision?: number): number;
|
|
22
|
+
/**
|
|
23
|
+
* Gera um número inteiro positivo aleatório até um valor máximo.
|
|
24
|
+
* @param max - Valor máximo do intervalo (padrão: 100)
|
|
25
|
+
* @returns Número inteiro positivo aleatório entre 1 e max
|
|
26
|
+
* @example
|
|
27
|
+
* Random.positiveNumber() // pode retornar qualquer inteiro entre 1 e 100
|
|
28
|
+
* Random.positiveNumber(50) // pode retornar qualquer inteiro entre 1 e 50
|
|
29
|
+
*/
|
|
30
|
+
static positiveNumber(max?: number): number;
|
|
31
|
+
/**
|
|
32
|
+
* Gera um número inteiro negativo aleatório até um valor mínimo.
|
|
33
|
+
* @param min - Valor mínimo do intervalo (padrão: -100)
|
|
34
|
+
* @returns Número inteiro negativo aleatório entre min e -1
|
|
35
|
+
* @example
|
|
36
|
+
* Random.negativeNumber() // pode retornar qualquer inteiro entre -100 e -1
|
|
37
|
+
* Random.negativeNumber(-50) // pode retornar qualquer inteiro entre -50 e -1
|
|
38
|
+
*/
|
|
39
|
+
static negativeNumber(min?: number): number;
|
|
40
|
+
/**
|
|
41
|
+
* Retorna um valor aleatório de um enum.
|
|
42
|
+
* @template T - Tipo do enum
|
|
43
|
+
* @param anEnum - Enum do qual será selecionado o valor aleatório
|
|
44
|
+
* @returns Um valor aleatório do enum
|
|
45
|
+
* @example
|
|
46
|
+
* enum Color { Red, Green, Blue }
|
|
47
|
+
* Random.enum(Color) // pode retornar Color.Red, Color.Green ou Color.Blue
|
|
48
|
+
*/
|
|
3
49
|
static enum<T extends Record<string, unknown>>(anEnum: T): T[keyof T];
|
|
50
|
+
/**
|
|
51
|
+
* Retorna um valor aleatório de um enum, excluindo valores específicos.
|
|
52
|
+
* @template T - Tipo do enum
|
|
53
|
+
* @param anEnum - Enum do qual será selecionado o valor aleatório
|
|
54
|
+
* @param excepts - Array de valores do enum que devem ser excluídos da seleção
|
|
55
|
+
* @returns Um valor aleatório do enum que não está nos excepts
|
|
56
|
+
* @throws {Error} Se não houver valores válidos após aplicar as exclusões
|
|
57
|
+
* @example
|
|
58
|
+
* enum Color { Red, Green, Blue }
|
|
59
|
+
* Random.enumExcluding(Color, [Color.Red]) // retorna Green ou Blue
|
|
60
|
+
*/
|
|
4
61
|
static enumExcluding<T extends Record<string, unknown>>(anEnum: T, excepts: Array<T[keyof T]>): T[keyof T];
|
|
62
|
+
/**
|
|
63
|
+
* Gera uma string aleatória de caracteres alfanuméricos.
|
|
64
|
+
* @param length - Comprimento da string a ser gerada (padrão: 8)
|
|
65
|
+
* @returns String aleatória com o comprimento especificado
|
|
66
|
+
* @example
|
|
67
|
+
* Random.string() // pode retornar "aB3xKp9z"
|
|
68
|
+
* Random.string(4) // pode retornar "kR2m"
|
|
69
|
+
*/
|
|
70
|
+
static string(length?: number): string;
|
|
71
|
+
/**
|
|
72
|
+
* Gera uma string aleatória contendo apenas letras (sem números).
|
|
73
|
+
* @param length - Comprimento da string a ser gerada (padrão: 8)
|
|
74
|
+
* @returns String aleatória com apenas letras
|
|
75
|
+
* @example
|
|
76
|
+
* Random.letters() // pode retornar "AbCdEfGh"
|
|
77
|
+
* Random.letters(4) // pode retornar "kRmZ"
|
|
78
|
+
*/
|
|
79
|
+
static letters(length?: number): string;
|
|
80
|
+
/**
|
|
81
|
+
* Gera um UUID v4 aleatório no formato padrão.
|
|
82
|
+
* @returns UUID no formato xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
|
|
83
|
+
* @example
|
|
84
|
+
* Random.uuid() // pode retornar "550e8400-e29b-41d4-a716-446655440000"
|
|
85
|
+
*/
|
|
86
|
+
static uuid(): string;
|
|
87
|
+
/**
|
|
88
|
+
* Gera um valor booleano aleatório (true ou false).
|
|
89
|
+
* @returns true ou false aleatoriamente
|
|
90
|
+
* @example
|
|
91
|
+
* Random.boolean() // pode retornar true ou false
|
|
92
|
+
*/
|
|
93
|
+
static boolean(): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Gera um valor booleano aleatório com uma probabilidade específica de ser true.
|
|
96
|
+
* @param probability - Probabilidade de retornar true (0 a 1, padrão: 0.5)
|
|
97
|
+
* @returns true com a probabilidade fornecida, false caso contrário
|
|
98
|
+
* @example
|
|
99
|
+
* Random.booleanWithProbability(0.8) // 80% de chance de retornar true
|
|
100
|
+
* Random.booleanWithProbability(0.2) // 20% de chance de retornar true
|
|
101
|
+
*/
|
|
102
|
+
static booleanWithProbability(probability?: number): boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Retorna um elemento aleatório de um array.
|
|
105
|
+
* @template T - Tipo dos elementos do array
|
|
106
|
+
* @param array - Array do qual será selecionado um elemento
|
|
107
|
+
* @returns Um elemento aleatório do array
|
|
108
|
+
* @throws {Error} Se o array estiver vazio
|
|
109
|
+
* @example
|
|
110
|
+
* Random.arrayElement([1, 2, 3, 4]) // pode retornar 1, 2, 3 ou 4
|
|
111
|
+
* Random.arrayElement(["a", "b", "c"]) // pode retornar "a", "b" ou "c"
|
|
112
|
+
*/
|
|
113
|
+
static arrayElement<T>(array: T[]): T;
|
|
114
|
+
/**
|
|
115
|
+
* Retorna um elemento aleatório de um array, excluindo valores específicos.
|
|
116
|
+
* @template T - Tipo dos elementos do array
|
|
117
|
+
* @param array - Array do qual será selecionado um elemento
|
|
118
|
+
* @param excepts - Array de valores que devem ser excluídos da seleção
|
|
119
|
+
* @returns Um elemento aleatório do array que não está nos excepts
|
|
120
|
+
* @throws {Error} Se não houver elementos válidos após aplicar as exclusões
|
|
121
|
+
* @example
|
|
122
|
+
* Random.arrayElementExcluding([1, 2, 3, 4], [2, 4]) // pode retornar 1 ou 3
|
|
123
|
+
*/
|
|
124
|
+
static arrayElementExcluding<T>(array: T[], excepts: T[]): T;
|
|
125
|
+
/**
|
|
126
|
+
* Retorna múltiplos elementos aleatórios únicos de um array.
|
|
127
|
+
* @template T - Tipo dos elementos do array
|
|
128
|
+
* @param array - Array do qual serão selecionados os elementos
|
|
129
|
+
* @param count - Quantidade de elementos a retornar
|
|
130
|
+
* @returns Array com elementos aleatórios únicos
|
|
131
|
+
* @throws {Error} Se count for maior que o tamanho do array
|
|
132
|
+
* @example
|
|
133
|
+
* Random.arrayElements([1, 2, 3, 4, 5], 3) // pode retornar [3, 1, 5]
|
|
134
|
+
*/
|
|
135
|
+
static arrayElements<T>(array: T[], count: number): T[];
|
|
136
|
+
/**
|
|
137
|
+
* Retorna uma cópia do array com a ordem dos elementos embaralhada.
|
|
138
|
+
* @template T - Tipo dos elementos do array
|
|
139
|
+
* @param array - Array a ser embaralhado
|
|
140
|
+
* @returns Novo array com os mesmos elementos em ordem aleatória
|
|
141
|
+
* @example
|
|
142
|
+
* Random.shuffle([1, 2, 3, 4]) // pode retornar [3, 1, 4, 2]
|
|
143
|
+
*/
|
|
144
|
+
static shuffle<T>(array: T[]): T[];
|
|
145
|
+
/**
|
|
146
|
+
* Gera uma data aleatória dentro de um intervalo.
|
|
147
|
+
* @param start - Data inicial do intervalo
|
|
148
|
+
* @param end - Data final do intervalo
|
|
149
|
+
* @returns Data aleatória entre start e end
|
|
150
|
+
* @example
|
|
151
|
+
* Random.date(new Date("2020-01-01"), new Date("2024-12-31"))
|
|
152
|
+
* // pode retornar qualquer data entre 2020 e 2024
|
|
153
|
+
*/
|
|
154
|
+
static date(start: Date, end: Date): Date;
|
|
155
|
+
/**
|
|
156
|
+
* Gera uma data aleatória no passado a partir da data atual.
|
|
157
|
+
* @param daysAgo - Quantidade máxima de dias no passado (padrão: 365)
|
|
158
|
+
* @returns Data aleatória entre daysAgo dias atrás e hoje
|
|
159
|
+
* @example
|
|
160
|
+
* Random.pastDate() // data aleatória no último ano
|
|
161
|
+
* Random.pastDate(30) // data aleatória nos últimos 30 dias
|
|
162
|
+
*/
|
|
163
|
+
static pastDate(daysAgo?: number): Date;
|
|
164
|
+
/**
|
|
165
|
+
* Gera uma data aleatória no futuro a partir da data atual.
|
|
166
|
+
* @param daysAhead - Quantidade máxima de dias no futuro (padrão: 365)
|
|
167
|
+
* @returns Data aleatória entre hoje e daysAhead dias à frente
|
|
168
|
+
* @example
|
|
169
|
+
* Random.futureDate() // data aleatória no próximo ano
|
|
170
|
+
* Random.futureDate(30) // data aleatória nos próximos 30 dias
|
|
171
|
+
*/
|
|
172
|
+
static futureDate(daysAhead?: number): Date;
|
|
5
173
|
}
|