@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,626 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AmountEdge = void 0;
|
|
4
|
-
const convert_units_1 = require("#/@tool-box/utils/convert-units/convert-units");
|
|
5
|
-
const guardian_1 = require("#/@tool-box/utils/type-guard/guardian");
|
|
6
|
-
const amount_value_edge_1 = require("#/objects/amount/amount-value.edge");
|
|
7
|
-
const energy_unit_point_1 = require("#/objects/amount/points/energy-unit.point");
|
|
8
|
-
const length_unit_point_1 = require("#/objects/amount/points/length-unit.point");
|
|
9
|
-
const mass_unit_point_1 = require("#/objects/amount/points/mass-unit.point");
|
|
10
|
-
const volume_unit_point_1 = require("#/objects/amount/points/volume-unit.point");
|
|
11
|
-
class AmountEdge {
|
|
12
|
-
constructor(_value, _unit) {
|
|
13
|
-
this._value = _value;
|
|
14
|
-
this._unit = _unit;
|
|
15
|
-
}
|
|
16
|
-
get value() {
|
|
17
|
-
return this._value;
|
|
18
|
-
}
|
|
19
|
-
get unit() {
|
|
20
|
-
return this._unit;
|
|
21
|
-
}
|
|
22
|
-
// ====================
|
|
23
|
-
// Rounding and Precision
|
|
24
|
-
// ====================
|
|
25
|
-
/**
|
|
26
|
-
* Rounds the value to the nearest integer.
|
|
27
|
-
* @returns `this` to allow method chaining.
|
|
28
|
-
* @example
|
|
29
|
-
* const amount = new AmountEdge(5.7, MassUnitPoint.gram);
|
|
30
|
-
* amount.round(); // value is now 6
|
|
31
|
-
*/
|
|
32
|
-
round() {
|
|
33
|
-
this._value = Math.round(this._value);
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Rounds the value up to the next highest integer.
|
|
38
|
-
* @returns `this` to allow method chaining.
|
|
39
|
-
* @example
|
|
40
|
-
* const amount = new AmountEdge(5.2, MassUnitPoint.gram);
|
|
41
|
-
* amount.ceil(); // value is now 6
|
|
42
|
-
*/
|
|
43
|
-
ceil() {
|
|
44
|
-
this._value = Math.ceil(this._value);
|
|
45
|
-
return this;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Rounds the value down to the next lowest integer.
|
|
49
|
-
* @returns `this` to allow method chaining.
|
|
50
|
-
* @example
|
|
51
|
-
* const amount = new AmountEdge(5.9, MassUnitPoint.gram);
|
|
52
|
-
* amount.floor(); // value is now 5
|
|
53
|
-
*/
|
|
54
|
-
floor() {
|
|
55
|
-
this._value = Math.floor(this._value);
|
|
56
|
-
return this;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Rounds the value to a specified number of decimal places.
|
|
60
|
-
* @param precision - The number of decimal places to keep.
|
|
61
|
-
* @returns `this` to allow method chaining.
|
|
62
|
-
* @example
|
|
63
|
-
* const amount = new AmountEdge(5.6789, MassUnitPoint.gram);
|
|
64
|
-
* amount.toFixed(2); // value is now 5.68
|
|
65
|
-
*/
|
|
66
|
-
toFixed(precision) {
|
|
67
|
-
this._value = Number(this._value.toFixed(precision));
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Returns the absolute value (without sign).
|
|
72
|
-
* @returns `this` to allow method chaining.
|
|
73
|
-
* @example
|
|
74
|
-
* const amount = new AmountEdge(-5.5, MassUnitPoint.gram);
|
|
75
|
-
* amount.abs(); // value is now 5.5
|
|
76
|
-
*/
|
|
77
|
-
abs() {
|
|
78
|
-
this._value = Math.abs(this._value);
|
|
79
|
-
return this;
|
|
80
|
-
}
|
|
81
|
-
// ====================
|
|
82
|
-
// Unit Compaction
|
|
83
|
-
// ====================
|
|
84
|
-
/**
|
|
85
|
-
* Compacts the amount into a more appropriate unit based on its value.
|
|
86
|
-
* For example, 1000 grams is converted to 1 kilogram.
|
|
87
|
-
*
|
|
88
|
-
* @returns A new instance with the compacted unit.
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* const amount = new AmountEdge(1500, MassUnitPoint.gram);
|
|
92
|
-
* const compact = amount.compact(); // 1.5 kg
|
|
93
|
-
*/
|
|
94
|
-
compact() {
|
|
95
|
-
const amountValue = new amount_value_edge_1.AmountValueEdge(this._value);
|
|
96
|
-
// Mass
|
|
97
|
-
if (amountValue.isEqualOrBiggerThan(1000) &&
|
|
98
|
-
guardian_1._.isEqual(this._unit, mass_unit_point_1.MassUnitPoint.gram)) {
|
|
99
|
-
return new AmountEdge(convert_units_1.ConvertUnit.toKilogram(this), mass_unit_point_1.MassUnitPoint.kilogram);
|
|
100
|
-
}
|
|
101
|
-
if (amountValue.isEqualOrBiggerThan(1000) &&
|
|
102
|
-
guardian_1._.isEqual(this._unit, mass_unit_point_1.MassUnitPoint.milligram)) {
|
|
103
|
-
return new AmountEdge(convert_units_1.ConvertUnit.toGram(this), mass_unit_point_1.MassUnitPoint.gram);
|
|
104
|
-
}
|
|
105
|
-
if (amountValue.isEqualOrBiggerThan(1000) &&
|
|
106
|
-
guardian_1._.isEqual(this._unit, mass_unit_point_1.MassUnitPoint.micrograma)) {
|
|
107
|
-
return new AmountEdge(convert_units_1.ConvertUnit.toMilligram(this), mass_unit_point_1.MassUnitPoint.milligram);
|
|
108
|
-
}
|
|
109
|
-
// Volume
|
|
110
|
-
if (amountValue.isEqualOrBiggerThan(1000) &&
|
|
111
|
-
guardian_1._.isEqual(this._unit, volume_unit_point_1.VolumeUnitPoint.milliliter)) {
|
|
112
|
-
return new AmountEdge(convert_units_1.ConvertUnit.toLiter(this), volume_unit_point_1.VolumeUnitPoint.liter);
|
|
113
|
-
}
|
|
114
|
-
// Length
|
|
115
|
-
if (amountValue.isEqualOrBiggerThan(1000) &&
|
|
116
|
-
guardian_1._.isEqual(this._unit, length_unit_point_1.LengthUnitPoint.meter)) {
|
|
117
|
-
return new AmountEdge(convert_units_1.ConvertUnit.toKilometer(this), length_unit_point_1.LengthUnitPoint.kilometer);
|
|
118
|
-
}
|
|
119
|
-
if (amountValue.isEqualOrBiggerThan(100) &&
|
|
120
|
-
guardian_1._.isEqual(this._unit, length_unit_point_1.LengthUnitPoint.centimeter)) {
|
|
121
|
-
return new AmountEdge(convert_units_1.ConvertUnit.toMeter(this), length_unit_point_1.LengthUnitPoint.meter);
|
|
122
|
-
}
|
|
123
|
-
if (amountValue.isEqualOrBiggerThan(1000) &&
|
|
124
|
-
guardian_1._.isEqual(this._unit, length_unit_point_1.LengthUnitPoint.millimeter)) {
|
|
125
|
-
return new AmountEdge(convert_units_1.ConvertUnit.toMeter(this), length_unit_point_1.LengthUnitPoint.meter);
|
|
126
|
-
}
|
|
127
|
-
// Energy
|
|
128
|
-
if (amountValue.isEqualOrBiggerThan(1000) &&
|
|
129
|
-
guardian_1._.isEqual(this._unit, energy_unit_point_1.EnergyUnitPoint.calorie)) {
|
|
130
|
-
return new AmountEdge(convert_units_1.ConvertUnit.toKilocalorie(this), energy_unit_point_1.EnergyUnitPoint.kilocalorie);
|
|
131
|
-
}
|
|
132
|
-
return this;
|
|
133
|
-
}
|
|
134
|
-
// ====================
|
|
135
|
-
// Arithmetic Operations
|
|
136
|
-
// ====================
|
|
137
|
-
/**
|
|
138
|
-
* Adds another amount to the current value.
|
|
139
|
-
* @param amount - The amount to be added.
|
|
140
|
-
* @returns `this` to allow method chaining.
|
|
141
|
-
* @example
|
|
142
|
-
* const amount1 = new AmountEdge(5, MassUnitPoint.gram);
|
|
143
|
-
* const amount2 = new AmountEdge(3, MassUnitPoint.gram);
|
|
144
|
-
* amount1.sum(amount2); // value is now 8
|
|
145
|
-
*/
|
|
146
|
-
sum(amount) {
|
|
147
|
-
this._value += amount.value;
|
|
148
|
-
return this;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Subtracts another amount from the current value.
|
|
152
|
-
* @param amount - The amount to be subtracted.
|
|
153
|
-
* @returns `this` to allow method chaining.
|
|
154
|
-
* @example
|
|
155
|
-
* const amount1 = new AmountEdge(8, MassUnitPoint.gram);
|
|
156
|
-
* const amount2 = new AmountEdge(3, MassUnitPoint.gram);
|
|
157
|
-
* amount1.subtract(amount2); // value is now 5
|
|
158
|
-
*/
|
|
159
|
-
subtract(amount) {
|
|
160
|
-
this._value -= amount.value;
|
|
161
|
-
return this;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Divides the value by a number or another amount.
|
|
165
|
-
* @param amount - Divisor (number or AmountEdge)
|
|
166
|
-
* @returns `this` to allow method chaining
|
|
167
|
-
* @example
|
|
168
|
-
* const amount = new AmountEdge(10, MassUnitPoint.gram);
|
|
169
|
-
* amount.divideBy(2); // value is now 5
|
|
170
|
-
* amount.divideBy(new AmountEdge(2, MassUnitPoint.gram)); // value is now 2.5
|
|
171
|
-
*/
|
|
172
|
-
divideBy(amount) {
|
|
173
|
-
if (typeof amount === "number") {
|
|
174
|
-
this._value /= amount;
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
this._value /= amount.value;
|
|
178
|
-
}
|
|
179
|
-
return this;
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Multiplies the value by a number or another amount.
|
|
183
|
-
* @param amount - Multiplier (number or AmountEdge)
|
|
184
|
-
* @returns `this` to allow method chaining
|
|
185
|
-
* @example
|
|
186
|
-
* const amount = new AmountEdge(5, MassUnitPoint.gram);
|
|
187
|
-
* amount.multiplyBy(2); // value is now 10
|
|
188
|
-
* amount.multiplyBy(new AmountEdge(3, MassUnitPoint.gram)); // value is now 30
|
|
189
|
-
*/
|
|
190
|
-
multiplyBy(amount) {
|
|
191
|
-
if (typeof amount === "number") {
|
|
192
|
-
this._value *= amount;
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
this._value *= amount.value;
|
|
196
|
-
}
|
|
197
|
-
return this;
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Calculates the remainder (modulus) of the current value.
|
|
201
|
-
* @param amount - The divisor, either a number or an AmountEdge instance.
|
|
202
|
-
* @returns `this` to allow method chaining.
|
|
203
|
-
* @example
|
|
204
|
-
* const amount = new AmountEdge(10, MassUnitPoint.gram);
|
|
205
|
-
* amount.modBy(3); // value is now 1
|
|
206
|
-
*/
|
|
207
|
-
modBy(amount) {
|
|
208
|
-
if (typeof amount === "number") {
|
|
209
|
-
this._value %= amount;
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
this._value %= amount.value;
|
|
213
|
-
}
|
|
214
|
-
return this;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Calculates the absolute difference between this amount and another.
|
|
218
|
-
* @param amount - The amount to compare against
|
|
219
|
-
* @returns A new instance with the absolute difference
|
|
220
|
-
* @example
|
|
221
|
-
* const amount1 = new AmountEdge(10, MassUnitPoint.gram);
|
|
222
|
-
* const amount2 = new AmountEdge(3, MassUnitPoint.gram);
|
|
223
|
-
* const diff = amount1.difference(amount2); // 7
|
|
224
|
-
*/
|
|
225
|
-
difference(amount) {
|
|
226
|
-
const diff = Math.abs(this._value - amount.value);
|
|
227
|
-
return new AmountEdge(diff, this._unit);
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Applies a percentage to the current value.
|
|
231
|
-
* @param percentage - The percentage to apply (0-100)
|
|
232
|
-
* @returns `this` to allow method chaining
|
|
233
|
-
* @example
|
|
234
|
-
* const amount = new AmountEdge(100, MassUnitPoint.gram);
|
|
235
|
-
* amount.applyPercentage(20); // value is now 120 (100 + 20%)
|
|
236
|
-
*/
|
|
237
|
-
applyPercentage(percentage) {
|
|
238
|
-
const percentageValue = (this._value * percentage) / 100;
|
|
239
|
-
this._value += percentageValue;
|
|
240
|
-
return this;
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Calculates the percentage that this amount represents of a total.
|
|
244
|
-
* @param total - The total amount
|
|
245
|
-
* @returns The percentage as a number (0-100)
|
|
246
|
-
* @example
|
|
247
|
-
* const amount = new AmountEdge(25, MassUnitPoint.gram);
|
|
248
|
-
* const total = new AmountEdge(100, MassUnitPoint.gram);
|
|
249
|
-
* const percentage = amount.percentageOf(total); // 25
|
|
250
|
-
* @returns The percentage as a number (0-100)
|
|
251
|
-
* @example
|
|
252
|
-
* const amount = new AmountEdge(25, MassUnitPoint.gram);
|
|
253
|
-
* const total = new AmountEdge(100, MassUnitPoint.gram);
|
|
254
|
-
* const percentage = amount.percentageOf(total); // 25
|
|
255
|
-
*/
|
|
256
|
-
percentageOf(total) {
|
|
257
|
-
if (total.value === 0)
|
|
258
|
-
return 0;
|
|
259
|
-
return (this._value / total.value) * 100;
|
|
260
|
-
}
|
|
261
|
-
// ====================
|
|
262
|
-
// Comparisons
|
|
263
|
-
// ====================
|
|
264
|
-
/**
|
|
265
|
-
* Checks whether this amount is equal to another amount.
|
|
266
|
-
* @param amount - The amount to compare against.
|
|
267
|
-
* @returns `true` if both amounts have the same value and unit; otherwise, `false`.
|
|
268
|
-
* @example
|
|
269
|
-
* const amount1 = new AmountEdge(5, MassUnitPoint.gram);
|
|
270
|
-
* const amount2 = new AmountEdge(5, MassUnitPoint.gram);
|
|
271
|
-
* amount1.isEqual(amount2); // true
|
|
272
|
-
*/
|
|
273
|
-
isEqual(amount) {
|
|
274
|
-
return (guardian_1._.isEqual(this._value, amount.value) && guardian_1._.isEqual(this._unit, amount.unit));
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Checks whether this amount is different from another amount.
|
|
278
|
-
* @param amount - The amount to compare against.
|
|
279
|
-
* @returns `true` if the amounts are different; otherwise, `false`.
|
|
280
|
-
* @example
|
|
281
|
-
* const amount1 = new AmountEdge(5, MassUnitPoint.gram);
|
|
282
|
-
* const amount2 = new AmountEdge(3, MassUnitPoint.gram);
|
|
283
|
-
* amount1.isDifferent(amount2); // true
|
|
284
|
-
*/
|
|
285
|
-
isDifferent(amount) {
|
|
286
|
-
return !this.isEqual(amount);
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Checks whether this amount is greater than another amount.
|
|
290
|
-
* @param amount - The amount to compare against.
|
|
291
|
-
* @returns `true` if this amount's value is greater than `amount`'s value; otherwise, `false`.
|
|
292
|
-
* @example
|
|
293
|
-
* const amount1 = new AmountEdge(10, MassUnitPoint.gram);
|
|
294
|
-
* const amount2 = new AmountEdge(5, MassUnitPoint.gram);
|
|
295
|
-
* amount1.isGreaterThan(amount2); // true
|
|
296
|
-
*/
|
|
297
|
-
isGreaterThan(amount) {
|
|
298
|
-
return this._value > amount.value;
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Checks whether this amount is less than another amount.
|
|
302
|
-
* @param amount - The amount to compare against.
|
|
303
|
-
* @returns `true` if this amount's value is less than `amount`'s value; otherwise, `false`.
|
|
304
|
-
* @example
|
|
305
|
-
* const amount1 = new AmountEdge(3, MassUnitPoint.gram);
|
|
306
|
-
* const amount2 = new AmountEdge(5, MassUnitPoint.gram);
|
|
307
|
-
* amount1.isLessThan(amount2); // true
|
|
308
|
-
*/
|
|
309
|
-
isLessThan(amount) {
|
|
310
|
-
return this._value < amount.value;
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* Checks whether this amount is greater than or equal to another amount.
|
|
314
|
-
* @param amount - The amount to compare against.
|
|
315
|
-
* @returns `true` if this amount's value is greater than or equal to `amount`'s value; otherwise, `false`.
|
|
316
|
-
* @example
|
|
317
|
-
* const amount1 = new AmountEdge(5, MassUnitPoint.gram);
|
|
318
|
-
* const amount2 = new AmountEdge(5, MassUnitPoint.gram);
|
|
319
|
-
* amount1.isGreaterThanOrEqual(amount2); // true
|
|
320
|
-
*/
|
|
321
|
-
isGreaterThanOrEqual(amount) {
|
|
322
|
-
return this._value >= amount.value;
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* Checks whether this amount is less than or equal to another amount.
|
|
326
|
-
* @param amount - The amount to compare against.
|
|
327
|
-
* @returns `true` if this amount's value is less than or equal to `amount`'s value; otherwise, `false`.
|
|
328
|
-
* @example
|
|
329
|
-
* const amount1 = new AmountEdge(5, MassUnitPoint.gram);
|
|
330
|
-
* const amount2 = new AmountEdge(5, MassUnitPoint.gram);
|
|
331
|
-
* amount1.isLessThanOrEqual(amount2); // true
|
|
332
|
-
*/
|
|
333
|
-
isLessThanOrEqual(amount) {
|
|
334
|
-
return this._value <= amount.value;
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Checks whether this amount is between two bounds (inclusive).
|
|
338
|
-
* @param min - The minimum amount.
|
|
339
|
-
* @param max - The maximum amount.
|
|
340
|
-
* @returns `true` if the value is between min and max; otherwise, `false`.
|
|
341
|
-
* @example
|
|
342
|
-
* const amount = new AmountEdge(5, MassUnitPoint.gram);
|
|
343
|
-
* const min = new AmountEdge(1, MassUnitPoint.gram);
|
|
344
|
-
* const max = new AmountEdge(10, MassUnitPoint.gram);
|
|
345
|
-
* amount.isBetween(min, max); // true
|
|
346
|
-
*/
|
|
347
|
-
isBetween(min, max) {
|
|
348
|
-
return this.isGreaterThanOrEqual(min) && this.isLessThanOrEqual(max);
|
|
349
|
-
}
|
|
350
|
-
// ====================
|
|
351
|
-
// Validations
|
|
352
|
-
// ====================
|
|
353
|
-
/**
|
|
354
|
-
* Checks whether the value is zero.
|
|
355
|
-
* @returns `true` if this.value === 0, `false` otherwise
|
|
356
|
-
* @example
|
|
357
|
-
* const amount = new AmountEdge(0, MassUnitPoint.gram);
|
|
358
|
-
* amount.isZero(); // true
|
|
359
|
-
*/
|
|
360
|
-
isZero() {
|
|
361
|
-
return this._value === 0;
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* Checks whether the value is positive (greater than zero).
|
|
365
|
-
* @returns `true` if this.value > 0, `false` otherwise
|
|
366
|
-
* @example
|
|
367
|
-
* const amount = new AmountEdge(5, MassUnitPoint.gram);
|
|
368
|
-
* amount.isPositive(); // true
|
|
369
|
-
*/
|
|
370
|
-
isPositive() {
|
|
371
|
-
return this._value > 0;
|
|
372
|
-
}
|
|
373
|
-
/**
|
|
374
|
-
* Checks whether the value is negative (less than zero).
|
|
375
|
-
* @returns `true` if this.value < 0, `false` otherwise
|
|
376
|
-
* @example
|
|
377
|
-
* const amount = new AmountEdge(-5, MassUnitPoint.gram);
|
|
378
|
-
* amount.isNegative(); // true
|
|
379
|
-
*/
|
|
380
|
-
isNegative() {
|
|
381
|
-
return this._value < 0;
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
* Checks whether the amount has a specific unit.
|
|
385
|
-
* @param unit - The unit to compare against.
|
|
386
|
-
* @returns `true` if the unit matches; otherwise, `false`.
|
|
387
|
-
* @example
|
|
388
|
-
* const amount = new AmountEdge(5, MassUnitPoint.gram);
|
|
389
|
-
* amount.hasUnit(MassUnitPoint.gram); // true
|
|
390
|
-
* amount.hasUnit(MassUnitPoint.kilogram); // false
|
|
391
|
-
*/
|
|
392
|
-
hasUnit(unit) {
|
|
393
|
-
return guardian_1._.isEqual(this._unit, unit);
|
|
394
|
-
}
|
|
395
|
-
// ====================
|
|
396
|
-
// Cloning and Immutability
|
|
397
|
-
// ====================
|
|
398
|
-
/**
|
|
399
|
-
* Creates an independent copy of this amount.
|
|
400
|
-
* Useful for avoiding unintended mutations.
|
|
401
|
-
*
|
|
402
|
-
* @returns A new instance with the same value and unit.
|
|
403
|
-
*
|
|
404
|
-
* @example
|
|
405
|
-
* const amount1 = new AmountEdge(5, MassUnitPoint.gram);
|
|
406
|
-
* const amount2 = amount1.clone();
|
|
407
|
-
* amount2.multiplyBy(2); // amount1 remains 5, amount2 is 10
|
|
408
|
-
*/
|
|
409
|
-
clone() {
|
|
410
|
-
return new AmountEdge(this._value, this._unit);
|
|
411
|
-
}
|
|
412
|
-
/**
|
|
413
|
-
* Returns a new instance with the value changed.
|
|
414
|
-
* Maintains the immutability of the original instance.
|
|
415
|
-
* @param value - New value
|
|
416
|
-
* @returns New instance with the changed value
|
|
417
|
-
* @example
|
|
418
|
-
* const amount = new AmountEdge(5, MassUnitPoint.gram);
|
|
419
|
-
* const newAmount = amount.withValue(10); // amount continua 5, newAmount é 10
|
|
420
|
-
*/
|
|
421
|
-
withValue(value) {
|
|
422
|
-
return new AmountEdge(value, this._unit);
|
|
423
|
-
}
|
|
424
|
-
/**
|
|
425
|
-
* Returns a new instance with the unit changed.
|
|
426
|
-
* Maintains the immutability of the original instance.
|
|
427
|
-
* @param unit - New unit
|
|
428
|
-
* @returns New instance with the changed unit
|
|
429
|
-
* @example
|
|
430
|
-
* const amount = new AmountEdge(5, MassUnitPoint.gram);
|
|
431
|
-
* const newAmount = amount.withUnit(MassUnitPoint.kilogram);
|
|
432
|
-
*/
|
|
433
|
-
withUnit(unit) {
|
|
434
|
-
return new AmountEdge(this._value, unit);
|
|
435
|
-
}
|
|
436
|
-
// ====================
|
|
437
|
-
// Formatting
|
|
438
|
-
// ====================
|
|
439
|
-
/**
|
|
440
|
-
* Returns a string representation of the amount.
|
|
441
|
-
* @returns A string in the format "value unit".
|
|
442
|
-
* @example
|
|
443
|
-
* const amount = new AmountEdge(5, MassUnitPoint.gram);
|
|
444
|
-
* amount.toString(); // "5 g"
|
|
445
|
-
*/
|
|
446
|
-
toString() {
|
|
447
|
-
return `${this._value.toString()} ${this._unit}`;
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* Formats the amount as a string with a thousands separator and decimal precision.
|
|
451
|
-
* @param locale - Locale for formatting (e.g., 'en-US', 'pt-BR')
|
|
452
|
-
* @param precision - NNumber of decimal places
|
|
453
|
-
* @returns Formatted string
|
|
454
|
-
* @example
|
|
455
|
-
* const amount = new AmountEdge(1234.5678, MassUnitPoint.gram);
|
|
456
|
-
* amount.toFormattedString('pt-BR', 2); // "1.234,57 g"
|
|
457
|
-
*/
|
|
458
|
-
toFormattedString(locale = "pt-BR", precision = 2) {
|
|
459
|
-
const formatted = this._value.toLocaleString(locale, {
|
|
460
|
-
minimumFractionDigits: precision,
|
|
461
|
-
maximumFractionDigits: precision,
|
|
462
|
-
});
|
|
463
|
-
return `${formatted} ${this._unit}`;
|
|
464
|
-
}
|
|
465
|
-
/**
|
|
466
|
-
* Returns only the value as a string with specific precision.
|
|
467
|
-
* @param precision - NNumber of decimal places
|
|
468
|
-
* @returns Formatted value string
|
|
469
|
-
* @example
|
|
470
|
-
* const amount = new AmountEdge(5.6789, MassUnitPoint.gram);
|
|
471
|
-
* amount.toValueString(2); // "5.68"
|
|
472
|
-
*/
|
|
473
|
-
toValueString(precision = 2) {
|
|
474
|
-
return this._value.toFixed(precision);
|
|
475
|
-
}
|
|
476
|
-
// ====================
|
|
477
|
-
// Conversion
|
|
478
|
-
// ====================
|
|
479
|
-
/**
|
|
480
|
-
* Converts the amount to a Polygon object.
|
|
481
|
-
* @param precision - The number of decimal places to retain.
|
|
482
|
-
* @returns A Polygon object containing the value and unit.
|
|
483
|
-
* @example
|
|
484
|
-
* const amount = new AmountEdge(5.6789, MassUnitPoint.gram);
|
|
485
|
-
* amount.toPolygon(2); // { value: 5.68, unit: MassUnitPoint.gram }
|
|
486
|
-
*/
|
|
487
|
-
toPolygon(precision = 2) {
|
|
488
|
-
return {
|
|
489
|
-
value: this._unit === mass_unit_point_1.MassUnitPoint.gram
|
|
490
|
-
? Number(this._value.toFixed(0))
|
|
491
|
-
: Number(this._value.toFixed(precision)),
|
|
492
|
-
unit: this._unit,
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
/**
|
|
496
|
-
* Converts the amount to a JSON object.
|
|
497
|
-
* @returns JSON object with value and unit
|
|
498
|
-
* @example
|
|
499
|
-
* const amount = new AmountEdge(5, MassUnitPoint.gram);
|
|
500
|
-
* amount.toJSON(); // { value: 5, unit: "g" }
|
|
501
|
-
*/
|
|
502
|
-
toJSON() {
|
|
503
|
-
return {
|
|
504
|
-
value: this._value,
|
|
505
|
-
unit: this._unit,
|
|
506
|
-
};
|
|
507
|
-
}
|
|
508
|
-
// ====================
|
|
509
|
-
// Static Methods
|
|
510
|
-
// ====================
|
|
511
|
-
/**
|
|
512
|
-
* Creates a new amount with a value of zero.
|
|
513
|
-
* @template T - The unit type.
|
|
514
|
-
* @param unit - The unit of the amount.
|
|
515
|
-
* @returns A new instance with a value of zero.
|
|
516
|
-
* @example
|
|
517
|
-
* const zero = AmountEdge.zero(MassUnitPoint.gram); // 0 g
|
|
518
|
-
*/
|
|
519
|
-
static zero(unit) {
|
|
520
|
-
return new AmountEdge(0, unit);
|
|
521
|
-
}
|
|
522
|
-
/**
|
|
523
|
-
* Sums a list of amounts.
|
|
524
|
-
* @template T - The unit type.
|
|
525
|
-
* @param amounts - An array of amounts to sum.
|
|
526
|
-
* @returns A new instance containing the total sum.
|
|
527
|
-
* @example
|
|
528
|
-
* const amounts = [
|
|
529
|
-
* new AmountEdge(5, MassUnitPoint.gram),
|
|
530
|
-
* new AmountEdge(3, MassUnitPoint.gram),
|
|
531
|
-
* new AmountEdge(2, MassUnitPoint.gram),
|
|
532
|
-
* ];
|
|
533
|
-
* const total = AmountEdge.sumAll(amounts); // 10 g
|
|
534
|
-
*/
|
|
535
|
-
static sumAll(amounts) {
|
|
536
|
-
if (amounts.length === 0) {
|
|
537
|
-
throw new Error("Cannot sum an empty array of amounts");
|
|
538
|
-
}
|
|
539
|
-
const total = amounts[0].clone();
|
|
540
|
-
for (let i = 1; i < amounts.length; i++) {
|
|
541
|
-
total.sum(amounts[i]);
|
|
542
|
-
}
|
|
543
|
-
return total;
|
|
544
|
-
}
|
|
545
|
-
/**
|
|
546
|
-
* Returns the maximum amount from a list.
|
|
547
|
-
* @template T - The unit type.
|
|
548
|
-
* @param amounts - n array of amounts.
|
|
549
|
-
* @returns A new instance with the maximum value.
|
|
550
|
-
* @example
|
|
551
|
-
* const amounts = [
|
|
552
|
-
* new AmountEdge(5, MassUnitPoint.gram),
|
|
553
|
-
* new AmountEdge(10, MassUnitPoint.gram),
|
|
554
|
-
* new AmountEdge(3, MassUnitPoint.gram),
|
|
555
|
-
* ];
|
|
556
|
-
* const max = AmountEdge.max(amounts); // 10 g
|
|
557
|
-
*/
|
|
558
|
-
static max(amounts) {
|
|
559
|
-
if (amounts.length === 0) {
|
|
560
|
-
throw new Error("Cannot find max of an empty array of amounts");
|
|
561
|
-
}
|
|
562
|
-
let maxAmount = amounts[0].clone();
|
|
563
|
-
for (let i = 1; i < amounts.length; i++) {
|
|
564
|
-
if (amounts[i].isGreaterThan(maxAmount)) {
|
|
565
|
-
maxAmount = amounts[i].clone();
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
return maxAmount;
|
|
569
|
-
}
|
|
570
|
-
/**
|
|
571
|
-
* Returns the minimum amount from a list.
|
|
572
|
-
* @template T - The unit type.
|
|
573
|
-
* @param amounts - An array of amounts.
|
|
574
|
-
* @returns A new instance containing the smallest value.
|
|
575
|
-
* @example
|
|
576
|
-
* const amounts = [
|
|
577
|
-
* new AmountEdge(5, MassUnitPoint.gram),
|
|
578
|
-
* new AmountEdge(10, MassUnitPoint.gram),
|
|
579
|
-
* new AmountEdge(3, MassUnitPoint.gram),
|
|
580
|
-
* ];
|
|
581
|
-
* const min = AmountEdge.min(amounts); // 3 g
|
|
582
|
-
*/
|
|
583
|
-
static min(amounts) {
|
|
584
|
-
if (amounts.length === 0) {
|
|
585
|
-
throw new Error("Cannot find min of an empty array of amounts");
|
|
586
|
-
}
|
|
587
|
-
let minAmount = amounts[0].clone();
|
|
588
|
-
for (let i = 1; i < amounts.length; i++) {
|
|
589
|
-
if (amounts[i].isLessThan(minAmount)) {
|
|
590
|
-
minAmount = amounts[i].clone();
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
return minAmount;
|
|
594
|
-
}
|
|
595
|
-
/**
|
|
596
|
-
* Calculates the average of a list of amounts.
|
|
597
|
-
* @template T - The unit type.
|
|
598
|
-
* @param amounts - n array of amounts.
|
|
599
|
-
* @returns A new instance with the average value.
|
|
600
|
-
* @example
|
|
601
|
-
* const amounts = [
|
|
602
|
-
* new AmountEdge(10, MassUnitPoint.gram),
|
|
603
|
-
* new AmountEdge(20, MassUnitPoint.gram),
|
|
604
|
-
* new AmountEdge(30, MassUnitPoint.gram),
|
|
605
|
-
* ];
|
|
606
|
-
* const average = AmountEdge.average(amounts); // 20 g
|
|
607
|
-
*/
|
|
608
|
-
static average(amounts) {
|
|
609
|
-
const total = AmountEdge.sumAll(amounts);
|
|
610
|
-
total.divideBy(amounts.length);
|
|
611
|
-
return total;
|
|
612
|
-
}
|
|
613
|
-
/**
|
|
614
|
-
* Creates an amount from a Polygon object.
|
|
615
|
-
* @template T - The unit type.
|
|
616
|
-
* @param polygon - A Polygon object containing `value` and `unit`.
|
|
617
|
-
* @returns A new AmountEdge instance.
|
|
618
|
-
* @example
|
|
619
|
-
* const polygon = { value: 5, unit: MassUnitPoint.gram };
|
|
620
|
-
* const amount = AmountEdge.fromPolygon(polygon); // 5 g
|
|
621
|
-
*/
|
|
622
|
-
static fromPolygon(polygon) {
|
|
623
|
-
return new AmountEdge(polygon.value, polygon.unit);
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
exports.AmountEdge = AmountEdge;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.AmountUv = void 0;
|
|
13
|
-
const class_validator_1 = require("class-validator");
|
|
14
|
-
const amount_edge_1 = require("#/objects/amount/amount.edge");
|
|
15
|
-
const uv_abstract_1 = require("#/objects-interface/uv.abstract");
|
|
16
|
-
class AmountUv extends uv_abstract_1.UvAbstract {
|
|
17
|
-
toEntity() {
|
|
18
|
-
return new amount_edge_1.AmountEdge(this.value, this.unit);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.AmountUv = AmountUv;
|
|
22
|
-
__decorate([
|
|
23
|
-
(0, class_validator_1.IsNumber)(),
|
|
24
|
-
__metadata("design:type", Number)
|
|
25
|
-
], AmountUv.prototype, "value", void 0);
|
|
26
|
-
__decorate([
|
|
27
|
-
(0, class_validator_1.IsString)(),
|
|
28
|
-
__metadata("design:type", Object)
|
|
29
|
-
], AmountUv.prototype, "unit", void 0);
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DurationUnitPoint = void 0;
|
|
4
|
-
var DurationUnitPoint;
|
|
5
|
-
(function (DurationUnitPoint) {
|
|
6
|
-
DurationUnitPoint["years"] = "yr";
|
|
7
|
-
DurationUnitPoint["months"] = "mo";
|
|
8
|
-
DurationUnitPoint["weeks"] = "wk";
|
|
9
|
-
DurationUnitPoint["days"] = "d";
|
|
10
|
-
DurationUnitPoint["hours"] = "h";
|
|
11
|
-
DurationUnitPoint["minutes"] = "min";
|
|
12
|
-
DurationUnitPoint["seconds"] = "s";
|
|
13
|
-
DurationUnitPoint["milliseconds"] = "milliseconds";
|
|
14
|
-
DurationUnitPoint["quarters"] = "quarters";
|
|
15
|
-
})(DurationUnitPoint || (exports.DurationUnitPoint = DurationUnitPoint = {}));
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EnergyUnitPoint = void 0;
|
|
4
|
-
var EnergyUnitPoint;
|
|
5
|
-
(function (EnergyUnitPoint) {
|
|
6
|
-
EnergyUnitPoint["joule"] = "J";
|
|
7
|
-
EnergyUnitPoint["calorie"] = "cal";
|
|
8
|
-
EnergyUnitPoint["kilocalorie"] = "kcal";
|
|
9
|
-
EnergyUnitPoint["kilocaloriePerDay"] = "kcal/d";
|
|
10
|
-
})(EnergyUnitPoint || (exports.EnergyUnitPoint = EnergyUnitPoint = {}));
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LengthUnitPoint = void 0;
|
|
4
|
-
var LengthUnitPoint;
|
|
5
|
-
(function (LengthUnitPoint) {
|
|
6
|
-
LengthUnitPoint["meter"] = "m";
|
|
7
|
-
LengthUnitPoint["kilometer"] = "km";
|
|
8
|
-
LengthUnitPoint["centimeter"] = "cm";
|
|
9
|
-
LengthUnitPoint["millimeter"] = "mm";
|
|
10
|
-
})(LengthUnitPoint || (exports.LengthUnitPoint = LengthUnitPoint = {}));
|