@atlantjs/arch 15.6.7 → 15.7.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.
- package/index.js +60 -0
- package/package.json +5 -3
- package/tsconfig-lib.json +1 -0
- package/{tsconfig.tsbuildinfo → tsconfig.build.tsbuildinfo} +1 -1
- package/src/@tool-box/tests/builder.abstract.util.js +0 -39
- package/src/@tool-box/tests/builders/datetime/datetime.edge.builder.js +0 -15
- package/src/@tool-box/tests/builders/failures/dummies/failure.dummy.js +0 -13
- package/src/@tool-box/tests/builders/failures/failure.builder.js +0 -17
- package/src/@tool-box/tests/builders/metadata/metadata-uv.builder.js +0 -18
- package/src/@tool-box/tests/builders/metadata/metadata.edge.builder.js +0 -15
- package/src/@tool-box/tests/builders/user/email.edge.builder.js +0 -15
- package/src/@tool-box/tests/builders/user/username.edge.builder.js +0 -15
- package/src/@tool-box/tests/faker/faker.js +0 -208
- package/src/@tool-box/utils/convert-units/convert-units.js +0 -154
- package/src/@tool-box/utils/datatypes/boolean-utils.js +0 -155
- package/src/@tool-box/utils/datatypes/generic-types.js +0 -3
- package/src/@tool-box/utils/datatypes/plainify.js +0 -2
- package/src/@tool-box/utils/datatypes/string-utils.js +0 -292
- package/src/@tool-box/utils/datetime/mappers/month.mapper.js +0 -58
- package/src/@tool-box/utils/datetime/mappers/points/month-abbreviation.enum.js +0 -18
- package/src/@tool-box/utils/datetime/mappers/points/month-number.enum.js +0 -18
- package/src/@tool-box/utils/ducts/common.js +0 -47
- package/src/@tool-box/utils/ducts/optional-type.js +0 -128
- package/src/@tool-box/utils/ducts/return-type.js +0 -67
- package/src/@tool-box/utils/http-provider/http-provider-failure-response.js +0 -19
- package/src/@tool-box/utils/http-provider/http-provider-success-response.js +0 -20
- package/src/@tool-box/utils/http-provider/http-provider.js +0 -85
- package/src/@tool-box/utils/logger/index.js +0 -31
- package/src/@tool-box/utils/map/map.abstract.js +0 -84
- package/src/@tool-box/utils/random/random.js +0 -260
- package/src/@tool-box/utils/type-guard/guardian-exception.js +0 -6
- package/src/@tool-box/utils/type-guard/guardian.js +0 -625
- package/src/@tool-box/utils/type-guard/guardian.type.js +0 -2
- package/src/@tool-box/utils/validators/is-cron-expression.js +0 -39
- package/src/@tool-box/utils/validators/is-date-string.js +0 -42
- package/src/@tool-box/utils/validators/is-password-match.js +0 -27
- package/src/@tool-box/utils/validators/is-password-policy.validator.js +0 -30
- package/src/@tool-box/utils/validators/is-schedule.js +0 -43
- package/src/@tool-box/utils/validators/is-time-string.js +0 -39
- package/src/@tool-box/utils/validators/is-ulid.js +0 -39
- package/src/index.js +0 -179
- package/src/objects/@common/edges/email.edge.js +0 -94
- package/src/objects/@common/edges/ulid.sketch.edge.js +0 -91
- package/src/objects/@common/edges/url.edge.js +0 -269
- package/src/objects/@common/edges/username.edge.js +0 -41
- package/src/objects/@common/edges/uuid.sketch.edge.js +0 -145
- package/src/objects/@common/points/environment.point.js +0 -10
- package/src/objects/@common/points/header-token-name.point.js +0 -10
- package/src/objects/@common/points/http-status-codes.point.js +0 -244
- package/src/objects/amount/amount-value.edge.js +0 -76
- package/src/objects/amount/amount.edge.js +0 -626
- package/src/objects/amount/amount.polygon.js +0 -2
- package/src/objects/amount/amount.uv.js +0 -29
- package/src/objects/amount/points/duration-unit.point.js +0 -15
- package/src/objects/amount/points/energy-unit.point.js +0 -10
- package/src/objects/amount/points/length-unit.point.js +0 -10
- package/src/objects/amount/points/mass-unit.point.js +0 -11
- package/src/objects/amount/points/month-name.point.js +0 -18
- package/src/objects/amount/points/object-unit.point.js +0 -7
- package/src/objects/amount/points/units.point.js +0 -2
- package/src/objects/amount/points/volume-unit.point.js +0 -8
- package/src/objects/amount/points/week-day.point.js +0 -13
- package/src/objects/datetime/edges/datetime.edge.js +0 -672
- package/src/objects/datetime/edges/locale/day/day-name-to-english.mapper.js +0 -19
- package/src/objects/datetime/edges/locale/day/day-name-to-portuguese.mapper.js +0 -19
- package/src/objects/datetime/edges/locale/day/today-to-language.mapper.js +0 -15
- package/src/objects/datetime/edges/locale/holidays-country.type.js +0 -2
- package/src/objects/datetime/edges/locale/month/month-to-english.mapper.js +0 -24
- package/src/objects/datetime/edges/locale/month/month-to-portuguese.mapper.js +0 -24
- package/src/objects/datetime/points/month-name.enum.js +0 -18
- package/src/objects/datetime/points/week-day.enum.js +0 -13
- package/src/objects/failure/edges/failure.abstract.js +0 -24
- package/src/objects/failure/edges/failure.abstract.polygon.js +0 -2
- package/src/objects/language/points/language.point.js +0 -135
- package/src/objects/metadata/metadata.edge.js +0 -25
- package/src/objects/metadata/metadata.polygon.js +0 -2
- package/src/objects/metadata/metadata.uv.js +0 -29
- package/src/objects/password/password.edge.js +0 -175
- package/src/objects/password/password.polygon.js +0 -2
- package/src/objects/password/steps/not-allowing-consecutive-chars-step.js +0 -34
- package/src/objects/password/steps/not-allowing-date-step.js +0 -61
- package/src/objects/password/steps/not-allowing-phone-step.js +0 -27
- package/src/objects/password/steps/not-allowing-repeated-chars-step.js +0 -34
- package/src/objects/password/steps/not-allowing-string-step.js +0 -19
- package/src/objects/password/steps/not-allowing-these-chars-step.js +0 -17
- package/src/objects/password/steps/numeric-step.js +0 -13
- package/src/objects/password/steps/with-at-least-one-letter-step.js +0 -14
- package/src/objects/password/steps/with-at-least-one-number-digit-step.js +0 -14
- package/src/objects/password/steps/with-at-least-one-special-char-step.js +0 -14
- package/src/objects/password/steps/with-length-step.js +0 -18
- package/src/objects/password/validation-step.js +0 -9
- package/src/objects/password/validation-step.type.js +0 -2
- package/src/objects/primitives/boolean.edge.sketch.js +0 -147
- package/src/objects/primitives/datetime.edge.sketch.js +0 -7
- package/src/objects/primitives/number.edge.sketch.js +0 -346
- package/src/objects/primitives/string.edge.sketch.js +0 -218
- package/src/objects/scheduling/scheduling.edge.failure.js +0 -14
- package/src/objects/scheduling/scheduling.edge.js +0 -280
- package/src/objects/time/time.edge.js +0 -447
- package/src/objects-interface/edges/edge.abstract.js +0 -6
- package/src/objects-interface/face.abstract.js +0 -6
- package/src/objects-interface/solid.abstract.js +0 -11
- package/src/objects-interface/uv.abstract.js +0 -6
- package/src/objects-interface/vertices/vertex.abstract.js +0 -11
- package/src/shared/payload.abstract.js +0 -6
- package/src/shared/request.abstract.js +0 -3
- package/src/shared/response.abstract.js +0 -6
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NotAllowingRepeatedCharsStep = void 0;
|
|
4
|
-
const validation_step_1 = require("#/objects/password/validation-step");
|
|
5
|
-
class NotAllowingRepeatedCharsStep extends validation_step_1.ValidationStep {
|
|
6
|
-
constructor(options) {
|
|
7
|
-
super();
|
|
8
|
-
this.options = options;
|
|
9
|
-
}
|
|
10
|
-
validate(password) {
|
|
11
|
-
return {
|
|
12
|
-
valid: this.getMaxNumberOfRepeatedChars(password) <=
|
|
13
|
-
this.options.maxAllowedRepeatedChars,
|
|
14
|
-
name: this.name,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
getMaxNumberOfRepeatedChars(password) {
|
|
18
|
-
let numberOfRepeatedChars = 1;
|
|
19
|
-
let maxNumberOfRepeatedChars = 1;
|
|
20
|
-
for (let i = 1; i < password.length; i++) {
|
|
21
|
-
const previousChar = password[i - 1];
|
|
22
|
-
const char = password[i];
|
|
23
|
-
if (previousChar === char) {
|
|
24
|
-
numberOfRepeatedChars += 1;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
maxNumberOfRepeatedChars = Math.max(numberOfRepeatedChars, maxNumberOfRepeatedChars);
|
|
28
|
-
numberOfRepeatedChars = 1;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return Math.max(numberOfRepeatedChars, maxNumberOfRepeatedChars);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.NotAllowingRepeatedCharsStep = NotAllowingRepeatedCharsStep;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NotAllowingStringStep = void 0;
|
|
4
|
-
const validation_step_1 = require("#/objects/password/validation-step");
|
|
5
|
-
class NotAllowingStringStep extends validation_step_1.ValidationStep {
|
|
6
|
-
constructor(forbiddenString) {
|
|
7
|
-
super();
|
|
8
|
-
this.forbiddenString = forbiddenString;
|
|
9
|
-
}
|
|
10
|
-
validate(password) {
|
|
11
|
-
return {
|
|
12
|
-
valid: !password
|
|
13
|
-
.toLowerCase()
|
|
14
|
-
.includes(this.forbiddenString.toLowerCase()),
|
|
15
|
-
name: this.name,
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.NotAllowingStringStep = NotAllowingStringStep;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NotAllowingTheseCharsStep = void 0;
|
|
4
|
-
const validation_step_1 = require("#/objects/password/validation-step");
|
|
5
|
-
class NotAllowingTheseCharsStep extends validation_step_1.ValidationStep {
|
|
6
|
-
constructor(options) {
|
|
7
|
-
super();
|
|
8
|
-
this.options = options;
|
|
9
|
-
}
|
|
10
|
-
validate(password) {
|
|
11
|
-
return {
|
|
12
|
-
valid: this.options.notAllowedCharsList.every((char) => !password.toLowerCase().includes(char.toLowerCase())),
|
|
13
|
-
name: this.name,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.NotAllowingTheseCharsStep = NotAllowingTheseCharsStep;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NumericStep = void 0;
|
|
4
|
-
const validation_step_1 = require("#/objects/password/validation-step");
|
|
5
|
-
class NumericStep extends validation_step_1.ValidationStep {
|
|
6
|
-
validate(password) {
|
|
7
|
-
return {
|
|
8
|
-
valid: /^\d+$/.test(password),
|
|
9
|
-
name: this.name,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
exports.NumericStep = NumericStep;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WithAtLeastOneLetterStep = void 0;
|
|
4
|
-
const validation_step_1 = require("#/objects/password/validation-step");
|
|
5
|
-
class WithAtLeastOneLetterStep extends validation_step_1.ValidationStep {
|
|
6
|
-
validate(password) {
|
|
7
|
-
const regex = /[a-zA-Z]/;
|
|
8
|
-
return {
|
|
9
|
-
valid: regex.test(password),
|
|
10
|
-
name: this.name,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
exports.WithAtLeastOneLetterStep = WithAtLeastOneLetterStep;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WithAtLeastOneNumberDigitStep = void 0;
|
|
4
|
-
const validation_step_1 = require("#/objects/password/validation-step");
|
|
5
|
-
class WithAtLeastOneNumberDigitStep extends validation_step_1.ValidationStep {
|
|
6
|
-
validate(password) {
|
|
7
|
-
const regex = /\d/;
|
|
8
|
-
return {
|
|
9
|
-
valid: regex.test(password),
|
|
10
|
-
name: this.name,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
exports.WithAtLeastOneNumberDigitStep = WithAtLeastOneNumberDigitStep;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WithAtLeastOneSpecialCharStep = void 0;
|
|
4
|
-
const validation_step_1 = require("#/objects/password/validation-step");
|
|
5
|
-
class WithAtLeastOneSpecialCharStep extends validation_step_1.ValidationStep {
|
|
6
|
-
validate(password) {
|
|
7
|
-
const regex = /[ `!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/;
|
|
8
|
-
return {
|
|
9
|
-
valid: regex.test(password),
|
|
10
|
-
name: this.name,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
exports.WithAtLeastOneSpecialCharStep = WithAtLeastOneSpecialCharStep;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WithLengthStep = void 0;
|
|
4
|
-
const validation_step_1 = require("#/objects/password/validation-step");
|
|
5
|
-
class WithLengthStep extends validation_step_1.ValidationStep {
|
|
6
|
-
constructor(options) {
|
|
7
|
-
super();
|
|
8
|
-
this.options = options;
|
|
9
|
-
}
|
|
10
|
-
validate(password) {
|
|
11
|
-
return {
|
|
12
|
-
valid: password.length >= this.options.min &&
|
|
13
|
-
password.length <= this.options.max,
|
|
14
|
-
name: this.name,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.WithLengthStep = WithLengthStep;
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BooleanEdgeSketch = void 0;
|
|
4
|
-
class BooleanEdgeSketch {
|
|
5
|
-
constructor(value) {
|
|
6
|
-
this.value = value;
|
|
7
|
-
}
|
|
8
|
-
// ==================== Getters ====================
|
|
9
|
-
/**
|
|
10
|
-
* Retorna o valor booleano interno.
|
|
11
|
-
* @returns Booleano interno do edge
|
|
12
|
-
* @example
|
|
13
|
-
* new MyBooleanEdge(true).toPoint() // true
|
|
14
|
-
*/
|
|
15
|
-
toBoolean() {
|
|
16
|
-
return this.value;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Retorna o valor como string.
|
|
20
|
-
* @returns "true" ou "false"
|
|
21
|
-
* @example
|
|
22
|
-
* new MyBooleanEdge(true).toString() // "true"
|
|
23
|
-
* new MyBooleanEdge(false).toString() // "false"
|
|
24
|
-
*/
|
|
25
|
-
toString() {
|
|
26
|
-
return String(this.value);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Retorna o valor como número (1 para true, 0 para false).
|
|
30
|
-
* @returns 1 se true, 0 se false
|
|
31
|
-
* @example
|
|
32
|
-
* new MyBooleanEdge(true).toNumber() // 1
|
|
33
|
-
* new MyBooleanEdge(false).toNumber() // 0
|
|
34
|
-
*/
|
|
35
|
-
toNumber() {
|
|
36
|
-
return this.value ? 1 : 0;
|
|
37
|
-
}
|
|
38
|
-
// ==================== Comparações ====================
|
|
39
|
-
/**
|
|
40
|
-
* Verifica se este valor é igual a outro.
|
|
41
|
-
* @param value - Booleano ou BooleanEdgeSketch para comparação
|
|
42
|
-
* @returns true se os valores são iguais, false caso contrário
|
|
43
|
-
* @example
|
|
44
|
-
* new MyBooleanEdge(true).isEqual(true) // true
|
|
45
|
-
* new MyBooleanEdge(true).isEqual(false) // false
|
|
46
|
-
*/
|
|
47
|
-
isEqual(value) {
|
|
48
|
-
const comparand = value instanceof BooleanEdgeSketch ? value.toBoolean() : value;
|
|
49
|
-
return this.value === comparand;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Verifica se este valor é diferente de outro.
|
|
53
|
-
* @param value - Booleano ou BooleanEdgeSketch para comparação
|
|
54
|
-
* @returns true se os valores são diferentes, false caso contrário
|
|
55
|
-
* @example
|
|
56
|
-
* new MyBooleanEdge(true).isDifferent(false) // true
|
|
57
|
-
* new MyBooleanEdge(true).isDifferent(true) // false
|
|
58
|
-
*/
|
|
59
|
-
isDifferent(value) {
|
|
60
|
-
const comparand = value instanceof BooleanEdgeSketch ? value.toBoolean() : value;
|
|
61
|
-
return this.value !== comparand;
|
|
62
|
-
}
|
|
63
|
-
// ==================== Verificações ====================
|
|
64
|
-
/**
|
|
65
|
-
* Verifica se o valor é true.
|
|
66
|
-
* @returns true se o valor interno é true, false caso contrário
|
|
67
|
-
* @example
|
|
68
|
-
* new MyBooleanEdge(true).isTrue() // true
|
|
69
|
-
* new MyBooleanEdge(false).isTrue() // false
|
|
70
|
-
*/
|
|
71
|
-
isTrue() {
|
|
72
|
-
return this.value === true;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Verifica se o valor é false.
|
|
76
|
-
* @returns true se o valor interno é false, false caso contrário
|
|
77
|
-
* @example
|
|
78
|
-
* new MyBooleanEdge(false).isFalse() // true
|
|
79
|
-
* new MyBooleanEdge(true).isFalse() // false
|
|
80
|
-
*/
|
|
81
|
-
isFalse() {
|
|
82
|
-
return this.value === false;
|
|
83
|
-
}
|
|
84
|
-
// ==================== Operações Lógicas ====================
|
|
85
|
-
/**
|
|
86
|
-
* Retorna o valor negado (NOT lógico).
|
|
87
|
-
* @returns Negação do valor interno
|
|
88
|
-
* @example
|
|
89
|
-
* new MyBooleanEdge(true).negate() // false
|
|
90
|
-
* new MyBooleanEdge(false).negate() // true
|
|
91
|
-
*/
|
|
92
|
-
negate() {
|
|
93
|
-
return !this.value;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Realiza AND lógico entre este valor e outro.
|
|
97
|
-
* @param value - Booleano ou BooleanEdgeSketch para operação
|
|
98
|
-
* @returns Resultado do AND lógico
|
|
99
|
-
* @example
|
|
100
|
-
* new MyBooleanEdge(true).and(true) // true
|
|
101
|
-
* new MyBooleanEdge(true).and(false) // false
|
|
102
|
-
* new MyBooleanEdge(false).and(true) // false
|
|
103
|
-
*/
|
|
104
|
-
and(value) {
|
|
105
|
-
const operand = value instanceof BooleanEdgeSketch ? value.toBoolean() : value;
|
|
106
|
-
return this.value && operand;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Realiza OR lógico entre este valor e outro.
|
|
110
|
-
* @param value - Booleano ou BooleanEdgeSketch para operação
|
|
111
|
-
* @returns Resultado do OR lógico
|
|
112
|
-
* @example
|
|
113
|
-
* new MyBooleanEdge(true).or(false) // true
|
|
114
|
-
* new MyBooleanEdge(false).or(false) // false
|
|
115
|
-
* new MyBooleanEdge(false).or(true) // true
|
|
116
|
-
*/
|
|
117
|
-
or(value) {
|
|
118
|
-
const operand = value instanceof BooleanEdgeSketch ? value.toBoolean() : value;
|
|
119
|
-
return this.value || operand;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Realiza XOR lógico (OU exclusivo) entre este valor e outro.
|
|
123
|
-
* @param value - Booleano ou BooleanEdgeSketch para operação
|
|
124
|
-
* @returns true se os valores são diferentes, false se iguais
|
|
125
|
-
* @example
|
|
126
|
-
* new MyBooleanEdge(true).xor(false) // true
|
|
127
|
-
* new MyBooleanEdge(true).xor(true) // false
|
|
128
|
-
* new MyBooleanEdge(false).xor(false) // false
|
|
129
|
-
*/
|
|
130
|
-
xor(value) {
|
|
131
|
-
const operand = value instanceof BooleanEdgeSketch ? value.toBoolean() : value;
|
|
132
|
-
return this.value !== operand;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Retorna um valor baseado no estado booleano (ternário tipado).
|
|
136
|
-
* @param onTrue - Valor retornado se true
|
|
137
|
-
* @param onFalse - Valor retornado se false
|
|
138
|
-
* @returns onTrue se value é true, onFalse caso contrário
|
|
139
|
-
* @example
|
|
140
|
-
* new MyBooleanEdge(true).fold("yes", "no") // "yes"
|
|
141
|
-
* new MyBooleanEdge(false).fold("yes", "no") // "no"
|
|
142
|
-
*/
|
|
143
|
-
fold(onTrue, onFalse) {
|
|
144
|
-
return this.value ? onTrue : onFalse;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
exports.BooleanEdgeSketch = BooleanEdgeSketch;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DatetimeEdgeSketch = void 0;
|
|
4
|
-
const datetime_edge_1 = require("#/objects/datetime/edges/datetime.edge");
|
|
5
|
-
class DatetimeEdgeSketch extends datetime_edge_1.DatetimeEdge {
|
|
6
|
-
}
|
|
7
|
-
exports.DatetimeEdgeSketch = DatetimeEdgeSketch;
|
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NumberEdgeSketch = void 0;
|
|
4
|
-
const guardian_1 = require("#/@tool-box/utils/type-guard/guardian");
|
|
5
|
-
class NumberEdgeSketch {
|
|
6
|
-
constructor(value) {
|
|
7
|
-
this.value = value;
|
|
8
|
-
this.validate(value);
|
|
9
|
-
}
|
|
10
|
-
// ==================== Getters ====================
|
|
11
|
-
/**
|
|
12
|
-
* Retorna o valor numérico interno.
|
|
13
|
-
* @returns Número interno do edge
|
|
14
|
-
* @example
|
|
15
|
-
* new MyNumberEdge(42).toNumber() // 42
|
|
16
|
-
*/
|
|
17
|
-
toNumber() {
|
|
18
|
-
return this.value;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Retorna o valor como string.
|
|
22
|
-
* @returns String representando o número
|
|
23
|
-
* @example
|
|
24
|
-
* new MyNumberEdge(42).toString() // "42"
|
|
25
|
-
*/
|
|
26
|
-
toString() {
|
|
27
|
-
return String(this.value);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Retorna o valor absoluto do número.
|
|
31
|
-
* @returns Valor absoluto (sempre positivo)
|
|
32
|
-
* @example
|
|
33
|
-
* new MyNumberEdge(-5).toAbsolute() // 5
|
|
34
|
-
* new MyNumberEdge(5).toAbsolute() // 5
|
|
35
|
-
*/
|
|
36
|
-
toAbsolute() {
|
|
37
|
-
return Math.abs(this.value);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Retorna o número fixado com casas decimais.
|
|
41
|
-
* @param decimalPlaces - Número de casas decimais (padrão: 2)
|
|
42
|
-
* @returns String com o número formatado
|
|
43
|
-
* @example
|
|
44
|
-
* new MyNumberEdge(3.14159).toFixed(2) // "3.14"
|
|
45
|
-
* new MyNumberEdge(3).toFixed(2) // "3.00"
|
|
46
|
-
*/
|
|
47
|
-
toFixed(decimalPlaces = 2) {
|
|
48
|
-
return this.value.toFixed(decimalPlaces);
|
|
49
|
-
}
|
|
50
|
-
// ==================== Comparações ====================
|
|
51
|
-
/**
|
|
52
|
-
* Verifica se este valor é igual a outro.
|
|
53
|
-
* @param value - Número ou NumberEdgeSketch para comparação
|
|
54
|
-
* @returns true se os valores são iguais, false caso contrário
|
|
55
|
-
* @example
|
|
56
|
-
* new MyNumberEdge(5).isEqual(5) // true
|
|
57
|
-
* new MyNumberEdge(5).isEqual(6) // false
|
|
58
|
-
*/
|
|
59
|
-
isEqual(value) {
|
|
60
|
-
const comparand = value instanceof NumberEdgeSketch ? value.toNumber() : value;
|
|
61
|
-
return this.value === comparand;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Verifica se este valor é diferente de outro.
|
|
65
|
-
* @param value - Número ou NumberEdgeSketch para comparação
|
|
66
|
-
* @returns true se os valores são diferentes, false caso contrário
|
|
67
|
-
* @example
|
|
68
|
-
* new MyNumberEdge(5).isDifferent(6) // true
|
|
69
|
-
* new MyNumberEdge(5).isDifferent(5) // false
|
|
70
|
-
*/
|
|
71
|
-
isDifferent(value) {
|
|
72
|
-
const comparand = value instanceof NumberEdgeSketch ? value.toNumber() : value;
|
|
73
|
-
return this.value !== comparand;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Verifica se este valor é maior que outro.
|
|
77
|
-
* @param value - Número ou NumberEdgeSketch para comparação
|
|
78
|
-
* @returns true se this > value, false caso contrário
|
|
79
|
-
* @example
|
|
80
|
-
* new MyNumberEdge(10).isBiggerThan(5) // true
|
|
81
|
-
* new MyNumberEdge(3).isBiggerThan(5) // false
|
|
82
|
-
*/
|
|
83
|
-
isBiggerThan(value) {
|
|
84
|
-
const comparand = value instanceof NumberEdgeSketch ? value.toNumber() : value;
|
|
85
|
-
return this.value > comparand; // 🐛 fix: estava value.toNumber() > this.value (invertido)
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Verifica se este valor é menor que outro.
|
|
89
|
-
* @param value - Número ou NumberEdgeSketch para comparação
|
|
90
|
-
* @returns true se this < value, false caso contrário
|
|
91
|
-
* @example
|
|
92
|
-
* new MyNumberEdge(3).isSmallerThan(5) // true
|
|
93
|
-
* new MyNumberEdge(10).isSmallerThan(5) // false
|
|
94
|
-
*/
|
|
95
|
-
isSmallerThan(value) {
|
|
96
|
-
const comparand = value instanceof NumberEdgeSketch ? value.toNumber() : value;
|
|
97
|
-
return this.value < comparand; // 🐛 fix: estava value.toNumber() < this.value (invertido)
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Verifica se este valor é maior ou igual a outro.
|
|
101
|
-
* @param value - Número ou NumberEdgeSketch para comparação
|
|
102
|
-
* @returns true se this >= value, false caso contrário
|
|
103
|
-
* @example
|
|
104
|
-
* new MyNumberEdge(5).isEqualOrBiggerThan(5) // true
|
|
105
|
-
* new MyNumberEdge(6).isEqualOrBiggerThan(5) // true
|
|
106
|
-
* new MyNumberEdge(4).isEqualOrBiggerThan(5) // false
|
|
107
|
-
*/
|
|
108
|
-
isEqualOrBiggerThan(value) {
|
|
109
|
-
const comparand = value instanceof NumberEdgeSketch ? value.toNumber() : value;
|
|
110
|
-
return this.value >= comparand; // 🐛 fix: estava value.toNumber() >= this.value (invertido)
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Verifica se este valor é menor ou igual a outro.
|
|
114
|
-
* @param value - Número ou NumberEdgeSketch para comparação
|
|
115
|
-
* @returns true se this <= value, false caso contrário
|
|
116
|
-
* @example
|
|
117
|
-
* new MyNumberEdge(5).isEqualOrSmallerThan(5) // true
|
|
118
|
-
* new MyNumberEdge(4).isEqualOrSmallerThan(5) // true
|
|
119
|
-
* new MyNumberEdge(6).isEqualOrSmallerThan(5) // false
|
|
120
|
-
*/
|
|
121
|
-
isEqualOrSmallerThan(value) {
|
|
122
|
-
const comparand = value instanceof NumberEdgeSketch ? value.toNumber() : value;
|
|
123
|
-
return this.value <= comparand; // 🐛 fix: estava value.toNumber() <= this.value (invertido)
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Verifica se este valor está entre dois limites (inclusivo).
|
|
127
|
-
* @param min - Limite mínimo
|
|
128
|
-
* @param max - Limite máximo
|
|
129
|
-
* @returns true se min <= this <= max, false caso contrário
|
|
130
|
-
* @example
|
|
131
|
-
* new MyNumberEdge(5).isBetween(1, 10) // true
|
|
132
|
-
* new MyNumberEdge(15).isBetween(1, 10) // false
|
|
133
|
-
*/
|
|
134
|
-
isBetween(min, max) {
|
|
135
|
-
const minimus = min instanceof NumberEdgeSketch ? min.toNumber() : min;
|
|
136
|
-
const maximus = max instanceof NumberEdgeSketch ? max.toNumber() : max;
|
|
137
|
-
return guardian_1._.isBetween(this.value, minimus, maximus);
|
|
138
|
-
}
|
|
139
|
-
// ==================== Verificações ====================
|
|
140
|
-
/**
|
|
141
|
-
* Verifica se o número é positivo (maior que zero).
|
|
142
|
-
* @returns true se o número é positivo, false caso contrário
|
|
143
|
-
* @example
|
|
144
|
-
* new MyNumberEdge(5).isPositive() // true
|
|
145
|
-
* new MyNumberEdge(-5).isPositive() // false
|
|
146
|
-
* new MyNumberEdge(0).isPositive() // false
|
|
147
|
-
*/
|
|
148
|
-
isPositive() {
|
|
149
|
-
return this.value > 0;
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Verifica se o número é negativo (menor que zero).
|
|
153
|
-
* @returns true se o número é negativo, false caso contrário
|
|
154
|
-
* @example
|
|
155
|
-
* new MyNumberEdge(-5).isNegative() // true
|
|
156
|
-
* new MyNumberEdge(5).isNegative() // false
|
|
157
|
-
* new MyNumberEdge(0).isNegative() // false
|
|
158
|
-
*/
|
|
159
|
-
isNegative() {
|
|
160
|
-
return this.value < 0;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Verifica se o número é zero.
|
|
164
|
-
* @returns true se o número é zero, false caso contrário
|
|
165
|
-
* @example
|
|
166
|
-
* new MyNumberEdge(0).isZero() // true
|
|
167
|
-
* new MyNumberEdge(1).isZero() // false
|
|
168
|
-
*/
|
|
169
|
-
isZero() {
|
|
170
|
-
return this.value === 0;
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Verifica se o número é inteiro (sem casas decimais).
|
|
174
|
-
* @returns true se o número é inteiro, false caso contrário
|
|
175
|
-
* @example
|
|
176
|
-
* new MyNumberEdge(5).isInteger() // true
|
|
177
|
-
* new MyNumberEdge(5.5).isInteger() // false
|
|
178
|
-
*/
|
|
179
|
-
isInteger() {
|
|
180
|
-
return Number.isInteger(this.value);
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Verifica se o número é float (possui casas decimais).
|
|
184
|
-
* @returns true se o número é float, false caso contrário
|
|
185
|
-
* @example
|
|
186
|
-
* new MyNumberEdge(5.5).isFloat() // true
|
|
187
|
-
* new MyNumberEdge(5).isFloat() // false
|
|
188
|
-
*/
|
|
189
|
-
isFloat() {
|
|
190
|
-
return !Number.isInteger(this.value);
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Verifica se o número é par.
|
|
194
|
-
* @returns true se o número é par, false caso contrário
|
|
195
|
-
* @example
|
|
196
|
-
* new MyNumberEdge(4).isEven() // true
|
|
197
|
-
* new MyNumberEdge(5).isEven() // false
|
|
198
|
-
*/
|
|
199
|
-
isEven() {
|
|
200
|
-
return this.value % 2 === 0;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Verifica se o número é ímpar.
|
|
204
|
-
* @returns true se o número é ímpar, false caso contrário
|
|
205
|
-
* @example
|
|
206
|
-
* new MyNumberEdge(5).isOdd() // true
|
|
207
|
-
* new MyNumberEdge(4).isOdd() // false
|
|
208
|
-
*/
|
|
209
|
-
isOdd() {
|
|
210
|
-
return this.value % 2 !== 0;
|
|
211
|
-
}
|
|
212
|
-
// ==================== Operações Aritméticas ====================
|
|
213
|
-
/**
|
|
214
|
-
* Soma este valor com outro e retorna o resultado.
|
|
215
|
-
* @param value - Número ou NumberEdgeSketch a somar
|
|
216
|
-
* @returns Resultado da soma
|
|
217
|
-
* @example
|
|
218
|
-
* new MyNumberEdge(5).add(3) // 8
|
|
219
|
-
*/
|
|
220
|
-
add(value) {
|
|
221
|
-
const operand = value instanceof NumberEdgeSketch ? value.toNumber() : value;
|
|
222
|
-
return this.value + operand;
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Subtrai outro valor deste e retorna o resultado.
|
|
226
|
-
* @param value - Número ou NumberEdgeSketch a subtrair
|
|
227
|
-
* @returns Resultado da subtração
|
|
228
|
-
* @example
|
|
229
|
-
* new MyNumberEdge(10).subtract(3) // 7
|
|
230
|
-
*/
|
|
231
|
-
subtract(value) {
|
|
232
|
-
const operand = value instanceof NumberEdgeSketch ? value.toNumber() : value;
|
|
233
|
-
return this.value - operand;
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Multiplica este valor por outro e retorna o resultado.
|
|
237
|
-
* @param value - Número ou NumberEdgeSketch a multiplicar
|
|
238
|
-
* @returns Resultado da multiplicação
|
|
239
|
-
* @example
|
|
240
|
-
* new MyNumberEdge(5).multiply(3) // 15
|
|
241
|
-
*/
|
|
242
|
-
multiply(value) {
|
|
243
|
-
const operand = value instanceof NumberEdgeSketch ? value.toNumber() : value;
|
|
244
|
-
return this.value * operand;
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Divide este valor por outro e retorna o resultado.
|
|
248
|
-
* @param value - Número ou NumberEdgeSketch divisor
|
|
249
|
-
* @returns Resultado da divisão
|
|
250
|
-
* @throws {Error} Se o divisor for zero
|
|
251
|
-
* @example
|
|
252
|
-
* new MyNumberEdge(10).divide(2) // 5
|
|
253
|
-
*/
|
|
254
|
-
divide(value) {
|
|
255
|
-
const operand = value instanceof NumberEdgeSketch ? value.toNumber() : value;
|
|
256
|
-
if (operand === 0) {
|
|
257
|
-
throw new Error(`${this.constructor.name}: division by zero is not allowed.`);
|
|
258
|
-
}
|
|
259
|
-
return this.value / operand;
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Retorna o resto da divisão deste valor por outro.
|
|
263
|
-
* @param value - Número ou NumberEdgeSketch divisor
|
|
264
|
-
* @returns Resto da divisão
|
|
265
|
-
* @throws {Error} Se o divisor for zero
|
|
266
|
-
* @example
|
|
267
|
-
* new MyNumberEdge(10).modulo(3) // 1
|
|
268
|
-
*/
|
|
269
|
-
modulo(value) {
|
|
270
|
-
const operand = value instanceof NumberEdgeSketch ? value.toNumber() : value;
|
|
271
|
-
if (operand === 0) {
|
|
272
|
-
throw new Error(`${this.constructor.name}: modulo by zero is not allowed.`);
|
|
273
|
-
}
|
|
274
|
-
return this.value % operand;
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Eleva este valor à potência de outro.
|
|
278
|
-
* @param exponent - Expoente da potenciação
|
|
279
|
-
* @returns Resultado da potenciação
|
|
280
|
-
* @throws {TypeError} Se o expoente não for finito
|
|
281
|
-
* @example
|
|
282
|
-
* new MyNumberEdge(2).power(8) // 256
|
|
283
|
-
* new MyNumberEdge(5).power(2) // 25
|
|
284
|
-
*/
|
|
285
|
-
power(exponent) {
|
|
286
|
-
if (!Number.isFinite(exponent)) {
|
|
287
|
-
throw new TypeError(`${this.constructor.name}: exponent should be a finite number.`);
|
|
288
|
-
}
|
|
289
|
-
return this.value ** exponent;
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Retorna a raiz quadrada do número.
|
|
293
|
-
* @returns Raiz quadrada do valor
|
|
294
|
-
* @throws {Error} Se o número for negativo
|
|
295
|
-
* @example
|
|
296
|
-
* new MyNumberEdge(9).sqrt() // 3
|
|
297
|
-
* new MyNumberEdge(16).sqrt() // 4
|
|
298
|
-
*/
|
|
299
|
-
sqrt() {
|
|
300
|
-
if (this.value < 0) {
|
|
301
|
-
throw new Error(`${this.constructor.name}: cannot calculate sqrt of a negative number.`);
|
|
302
|
-
}
|
|
303
|
-
return Math.sqrt(this.value);
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* Arredonda o número para o inteiro mais próximo.
|
|
307
|
-
* @returns Número arredondado
|
|
308
|
-
* @example
|
|
309
|
-
* new MyNumberEdge(4.5).round() // 5
|
|
310
|
-
* new MyNumberEdge(4.4).round() // 4
|
|
311
|
-
*/
|
|
312
|
-
round() {
|
|
313
|
-
return Math.round(this.value);
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Arredonda o número para baixo (floor).
|
|
317
|
-
* @returns Maior inteiro menor ou igual ao número
|
|
318
|
-
* @example
|
|
319
|
-
* new MyNumberEdge(4.9).floor() // 4
|
|
320
|
-
* new MyNumberEdge(-4.1).floor() // -5
|
|
321
|
-
*/
|
|
322
|
-
floor() {
|
|
323
|
-
return Math.floor(this.value);
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Arredonda o número para cima (ceil).
|
|
327
|
-
* @returns Menor inteiro maior ou igual ao número
|
|
328
|
-
* @example
|
|
329
|
-
* new MyNumberEdge(4.1).ceil() // 5
|
|
330
|
-
* new MyNumberEdge(-4.9).ceil() // -4
|
|
331
|
-
*/
|
|
332
|
-
ceil() {
|
|
333
|
-
return Math.ceil(this.value);
|
|
334
|
-
}
|
|
335
|
-
// ==================== Privados ====================
|
|
336
|
-
/**
|
|
337
|
-
* Valida se o valor fornecido no construtor é um número válido.
|
|
338
|
-
* @throws {TypeError} Se o valor for NaN
|
|
339
|
-
*/
|
|
340
|
-
validate(value) {
|
|
341
|
-
if (Number.isNaN(value)) {
|
|
342
|
-
throw new TypeError(`${this.constructor.name} should be valid.`);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
exports.NumberEdgeSketch = NumberEdgeSketch;
|