@wisemen/quantity 0.10.0 → 0.11.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/dist/quantities/current/current.column.d.ts +1 -1
- package/dist/quantities/current/current.column.js.map +1 -1
- package/dist/quantities/current/current.d.ts +4 -2
- package/dist/quantities/current/current.js +8 -2
- package/dist/quantities/current/current.js.map +1 -1
- package/dist/quantities/current/is-current.validator.d.ts +1 -2
- package/dist/quantities/current/is-current.validator.js.map +1 -1
- package/dist/quantities/distance/distance.column.d.ts +1 -1
- package/dist/quantities/distance/distance.column.js.map +1 -1
- package/dist/quantities/distance/distance.d.ts +12 -2
- package/dist/quantities/distance/distance.js +17 -2
- package/dist/quantities/distance/distance.js.map +1 -1
- package/dist/quantities/distance/is-distance.validator.d.ts +1 -2
- package/dist/quantities/distance/is-distance.validator.js.map +1 -1
- package/dist/quantities/distance/tests/distance.unit.test.js +11 -0
- package/dist/quantities/distance/tests/distance.unit.test.js.map +1 -1
- package/dist/quantities/duration/duration.column.d.ts +1 -1
- package/dist/quantities/duration/duration.column.js.map +1 -1
- package/dist/quantities/duration/duration.d.ts +10 -2
- package/dist/quantities/duration/duration.js +17 -2
- package/dist/quantities/duration/duration.js.map +1 -1
- package/dist/quantities/duration/is-duration.validator.d.ts +1 -2
- package/dist/quantities/duration/is-duration.validator.js.map +1 -1
- package/dist/quantities/duration/tests/duration.unit.test.js +13 -0
- package/dist/quantities/duration/tests/duration.unit.test.js.map +1 -1
- package/dist/quantities/energy/energy.column.d.ts +1 -1
- package/dist/quantities/energy/energy.column.js.map +1 -1
- package/dist/quantities/energy/energy.d.ts +12 -2
- package/dist/quantities/energy/energy.js +17 -2
- package/dist/quantities/energy/energy.js.map +1 -1
- package/dist/quantities/energy/is-energy.validator.d.ts +1 -2
- package/dist/quantities/energy/is-energy.validator.js.map +1 -1
- package/dist/quantities/energy/tests/energy.unit.test.js +13 -0
- package/dist/quantities/energy/tests/energy.unit.test.js.map +1 -1
- package/dist/quantities/mass/is-mass.validator.d.ts +1 -2
- package/dist/quantities/mass/is-mass.validator.js.map +1 -1
- package/dist/quantities/mass/mass.column.d.ts +1 -1
- package/dist/quantities/mass/mass.column.js.map +1 -1
- package/dist/quantities/mass/mass.d.ts +4 -2
- package/dist/quantities/mass/mass.js +8 -2
- package/dist/quantities/mass/mass.js.map +1 -1
- package/dist/quantities/power/is-power.validator.d.ts +1 -2
- package/dist/quantities/power/is-power.validator.js.map +1 -1
- package/dist/quantities/power/power.column.d.ts +1 -1
- package/dist/quantities/power/power.column.js.map +1 -1
- package/dist/quantities/power/power.d.ts +10 -2
- package/dist/quantities/power/power.js +17 -2
- package/dist/quantities/power/power.js.map +1 -1
- package/dist/quantities/power/tests/power.unit.test.js +13 -0
- package/dist/quantities/power/tests/power.unit.test.js.map +1 -1
- package/dist/quantities/speed/is-speed.validator.d.ts +1 -2
- package/dist/quantities/speed/is-speed.validator.js.map +1 -1
- package/dist/quantities/speed/speed.column.d.ts +1 -1
- package/dist/quantities/speed/speed.column.js.map +1 -1
- package/dist/quantities/speed/speed.d.ts +10 -2
- package/dist/quantities/speed/speed.js +17 -2
- package/dist/quantities/speed/speed.js.map +1 -1
- package/dist/quantities/speed/tests/speed.unit.test.js +12 -1
- package/dist/quantities/speed/tests/speed.unit.test.js.map +1 -1
- package/dist/quantities/temperature/is-temperature.validator.d.ts +1 -2
- package/dist/quantities/temperature/is-temperature.validator.js.map +1 -1
- package/dist/quantities/temperature/temperature.d.ts +13 -2
- package/dist/quantities/temperature/temperature.js +45 -2
- package/dist/quantities/temperature/temperature.js.map +1 -1
- package/dist/quantities/temperature/tests/temperature.unit.test.js +18 -1
- package/dist/quantities/temperature/tests/temperature.unit.test.js.map +1 -1
- package/dist/quantities/voltage/is-voltage.validator.d.ts +1 -2
- package/dist/quantities/voltage/is-voltage.validator.js.map +1 -1
- package/dist/quantities/voltage/voltage.column.d.ts +1 -1
- package/dist/quantities/voltage/voltage.column.js.map +1 -1
- package/dist/quantities/voltage/voltage.d.ts +4 -2
- package/dist/quantities/voltage/voltage.js +8 -2
- package/dist/quantities/voltage/voltage.js.map +1 -1
- package/dist/quantity.column.d.ts +3 -3
- package/dist/quantity.column.js.map +1 -1
- package/dist/quantity.d.ts +38 -15
- package/dist/quantity.dto.d.ts +1 -1
- package/dist/quantity.js +60 -36
- package/dist/quantity.js.map +1 -1
- package/dist/validators/is-quantity.decorator.d.ts +3 -3
- package/dist/validators/is-quantity.decorator.js.map +1 -1
- package/dist/validators/max-quantity.validator.d.ts +2 -2
- package/dist/validators/min-quantity.validator.d.ts +2 -2
- package/package.json +3 -3
package/dist/quantity.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import assert from 'assert';
|
|
2
2
|
import { Rate } from './rate/rate.js';
|
|
3
|
-
export class
|
|
3
|
+
export class BaseQuantity {
|
|
4
4
|
value;
|
|
5
5
|
unit;
|
|
6
6
|
constructor(quantityOrValue, unit) {
|
|
7
|
-
if (quantityOrValue
|
|
7
|
+
if (this.isQuantity(quantityOrValue)) {
|
|
8
8
|
this.value = quantityOrValue.value;
|
|
9
9
|
this.unit = quantityOrValue.unit;
|
|
10
10
|
}
|
|
@@ -23,11 +23,26 @@ export class Quantity {
|
|
|
23
23
|
this.unit = unit;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
isQuantity(quantityOrValue) {
|
|
27
|
+
return quantityOrValue instanceof this.getQuantity();
|
|
28
|
+
}
|
|
29
|
+
isDelta(quantityOrValue) {
|
|
30
|
+
return quantityOrValue instanceof this.getDelta();
|
|
31
|
+
}
|
|
32
|
+
constructQuantity(quantityOrValue, unit) {
|
|
33
|
+
const Constructor = this.getQuantity();
|
|
34
|
+
if (this.isQuantity(quantityOrValue)) {
|
|
35
|
+
return quantityOrValue;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
assert(unit !== undefined, 'Unit must be provided when constructing from a numeric value');
|
|
39
|
+
return new Constructor(quantityOrValue, unit);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
constructDelta(quantityOrValue, unit) {
|
|
43
|
+
const Constructor = this.getDelta();
|
|
44
|
+
if (this.isDelta(quantityOrValue)) {
|
|
45
|
+
return quantityOrValue;
|
|
31
46
|
}
|
|
32
47
|
else {
|
|
33
48
|
assert(unit !== undefined, 'Unit must be provided when constructing from a numeric value');
|
|
@@ -37,69 +52,62 @@ export class Quantity {
|
|
|
37
52
|
/** Converts the quantity to the specified unit */
|
|
38
53
|
to(unit) {
|
|
39
54
|
const value = this.convertBaseUnitValueTo(this.valueOf(), unit);
|
|
40
|
-
return this.
|
|
55
|
+
return this.constructQuantity(value, unit);
|
|
41
56
|
}
|
|
42
57
|
/** Returns the numeric value of the quantity in the specified unit */
|
|
43
58
|
asNumber(unit = this.unit) {
|
|
44
59
|
return this.to(unit).value;
|
|
45
60
|
}
|
|
46
61
|
isEqualTo(quantityOrValue, unit) {
|
|
47
|
-
const other = this.
|
|
62
|
+
const other = this.constructQuantity(quantityOrValue, unit);
|
|
48
63
|
return this.valueOf() === other.valueOf();
|
|
49
64
|
}
|
|
50
65
|
isLessThan(quantityOrValue, unit) {
|
|
51
|
-
const other = this.
|
|
66
|
+
const other = this.constructQuantity(quantityOrValue, unit);
|
|
52
67
|
return this.valueOf() < other.valueOf();
|
|
53
68
|
}
|
|
54
69
|
isLessThanOrEqualTo(quantityOrValue, unit) {
|
|
55
|
-
const other = this.
|
|
70
|
+
const other = this.constructQuantity(quantityOrValue, unit);
|
|
56
71
|
return this.valueOf() <= other.valueOf();
|
|
57
72
|
}
|
|
58
73
|
isMoreThan(quantityOrValue, unit) {
|
|
59
|
-
const other = this.
|
|
74
|
+
const other = this.constructQuantity(quantityOrValue, unit);
|
|
60
75
|
return this.valueOf() > other.valueOf();
|
|
61
76
|
}
|
|
62
77
|
isMoreThanOrEqualTo(quantityOrValue, unit) {
|
|
63
|
-
const other = this.
|
|
78
|
+
const other = this.constructQuantity(quantityOrValue, unit);
|
|
64
79
|
return this.valueOf() >= other.valueOf();
|
|
65
80
|
}
|
|
66
81
|
add(quantityOrValue, unit) {
|
|
67
|
-
const other = this.
|
|
68
|
-
return this.
|
|
82
|
+
const other = this.constructDelta(quantityOrValue, unit);
|
|
83
|
+
return this.constructQuantity(this.valueOf() + other.valueOf(), this.getBaseUnit()).to(this.unit);
|
|
69
84
|
}
|
|
70
85
|
subtract(quantityOrValue, unit) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const factor = factorOrRate instanceof Rate ? factorOrRate.asDecimal() : factorOrRate;
|
|
76
|
-
return this.construct(this.valueOf() * factor, this.getBaseUnit()).to(this.unit);
|
|
77
|
-
}
|
|
78
|
-
divide(divisor, unit) {
|
|
79
|
-
if (divisor instanceof Quantity || (typeof divisor === 'number' && unit !== undefined)) {
|
|
80
|
-
const other = this.construct(divisor, unit);
|
|
81
|
-
return this.valueOf() / other.valueOf();
|
|
86
|
+
let other;
|
|
87
|
+
if (this.isDelta(quantityOrValue)) {
|
|
88
|
+
other = this.constructDelta(quantityOrValue, unit);
|
|
89
|
+
return this.constructQuantity(this.valueOf() - other.valueOf(), this.getBaseUnit()).to(this.unit);
|
|
82
90
|
}
|
|
83
91
|
else {
|
|
84
|
-
|
|
85
|
-
return this.
|
|
92
|
+
other = this.constructQuantity(quantityOrValue, unit);
|
|
93
|
+
return this.constructDelta(this.valueOf() - other.valueOf(), this.getBaseUnit()).to(this.unit);
|
|
86
94
|
}
|
|
87
95
|
}
|
|
88
96
|
modulo(quantityOrValue, unit) {
|
|
89
|
-
const other = this.
|
|
90
|
-
return this.
|
|
97
|
+
const other = this.constructQuantity(quantityOrValue, unit);
|
|
98
|
+
return this.constructQuantity(this.valueOf() % other.valueOf(), this.getBaseUnit()).to(this.unit);
|
|
91
99
|
}
|
|
92
100
|
/** Ceils the value to the nearest integer for the current unit */
|
|
93
101
|
ceil() {
|
|
94
|
-
return this.
|
|
102
|
+
return this.constructQuantity(Math.ceil(this.value), this.unit);
|
|
95
103
|
}
|
|
96
104
|
/** Rounds the value half up to the nearest integer for the current unit */
|
|
97
105
|
round() {
|
|
98
|
-
return this.
|
|
106
|
+
return this.constructQuantity(Math.round(this.value), this.unit);
|
|
99
107
|
}
|
|
100
108
|
/** Floors the value to the nearest integer for the current unit */
|
|
101
109
|
floor() {
|
|
102
|
-
return this.
|
|
110
|
+
return this.constructQuantity(Math.floor(this.value), this.unit);
|
|
103
111
|
}
|
|
104
112
|
/** Checks whether the value is an integer for the current unit */
|
|
105
113
|
isRounded() {
|
|
@@ -129,14 +137,14 @@ export class Quantity {
|
|
|
129
137
|
}
|
|
130
138
|
/** Returns the maximum quantity from the provided quantities */
|
|
131
139
|
static max(...quantities) {
|
|
132
|
-
return quantities.reduce((max, quantity) => quantity.
|
|
140
|
+
return quantities.reduce((max, quantity) => quantity.isMoreThan(max) ? quantity : max);
|
|
133
141
|
}
|
|
134
142
|
/** Returns the minimum quantity from the provided quantities */
|
|
135
143
|
static min(...quantities) {
|
|
136
|
-
return quantities.reduce((min, quantity) => quantity.
|
|
144
|
+
return quantities.reduce((min, quantity) => quantity.isLessThan(min) ? quantity : min);
|
|
137
145
|
}
|
|
138
146
|
parseString(s, units) {
|
|
139
|
-
const unitsPattern = units.map(unit =>
|
|
147
|
+
const unitsPattern = units.map(unit => BaseQuantity.escapeRegex(unit)).join('|');
|
|
140
148
|
const pattern = new RegExp(`^(?<amount>[+-]?(?:\\d+\\.?\\d*|\\.\\d+)(?:e[+-]?\\d+)?)(?<unit>${unitsPattern})$`, 'u');
|
|
141
149
|
const match = pattern.exec(s);
|
|
142
150
|
const amount = match?.groups?.amount;
|
|
@@ -150,4 +158,20 @@ export class Quantity {
|
|
|
150
158
|
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
151
159
|
}
|
|
152
160
|
}
|
|
161
|
+
export class ScalableQuantity extends BaseQuantity {
|
|
162
|
+
multiply(multiplier) {
|
|
163
|
+
const factor = multiplier instanceof Rate ? multiplier.asDecimal() : multiplier;
|
|
164
|
+
return this.constructQuantity(this.valueOf() * factor, this.getBaseUnit()).to(this.unit);
|
|
165
|
+
}
|
|
166
|
+
divide(divisor, unit) {
|
|
167
|
+
if (divisor instanceof BaseQuantity || (typeof divisor === 'number' && unit !== undefined)) {
|
|
168
|
+
const other = this.constructQuantity(divisor, unit);
|
|
169
|
+
return this.valueOf() / other.valueOf();
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
const factor = divisor instanceof Rate ? divisor.asDecimal() : divisor;
|
|
173
|
+
return this.constructQuantity(this.valueOf() / factor, this.getBaseUnit()).to(this.unit);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
153
177
|
//# sourceMappingURL=quantity.js.map
|
package/dist/quantity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quantity.js","sourceRoot":"","sources":["../lib/quantity.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"quantity.js","sourceRoot":"","sources":["../lib/quantity.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAwBrC,MAAM,OAAgB,YAAY;IAYvB,KAAK,CAAQ;IACb,IAAI,CAAG;IAMhB,YAAa,eAAoC,EAAE,IAAQ;QACzD,IAAI,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;YACrC,IAAI,CAAC,KAAK,GAAG,eAAe,CAAC,KAAK,CAAA;YAClC,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC,IAAI,CAAA;QAClC,CAAC;aAAM,IAAI,eAAe,KAAK,CAAC,EAAE,CA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EAAE,CAAA;QACzC,CAAC;aAAM,CAAC;YACN,MAAM,MAAM,GAAG,OAAO,YAAY,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,OAAO,CAAA;YACtE,OAAO,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC1F,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ClassConstructor } from 'class-transformer';
|
|
2
2
|
import { ValidationOptions } from 'class-validator';
|
|
3
|
-
import { Quantity } from '../quantity.js';
|
|
3
|
+
import { Comparable, Quantity } from '../quantity.js';
|
|
4
4
|
import { QuantityDto } from '../quantity.dto.js';
|
|
5
|
-
export interface IsQuantityOptions<
|
|
5
|
+
export interface IsQuantityOptions<Q extends Quantity & Comparable> extends ValidationOptions {
|
|
6
6
|
min?: Q;
|
|
7
7
|
max?: Q;
|
|
8
8
|
}
|
|
9
|
-
export declare function IsQuantity<
|
|
9
|
+
export declare function IsQuantity<Q extends Quantity & Comparable>(quantityClass: ClassConstructor<QuantityDto<Q>>, options?: IsQuantityOptions<Q>): PropertyDecorator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-quantity.decorator.js","sourceRoot":"","sources":["../../lib/validators/is-quantity.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAqB,MAAM,iBAAiB,CAAA;AAGzF,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAQlE,MAAM,UAAU,UAAU,CACxB,aAA+C,EAC/C,
|
|
1
|
+
{"version":3,"file":"is-quantity.decorator.js","sourceRoot":"","sources":["../../lib/validators/is-quantity.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAqB,MAAM,iBAAiB,CAAA;AAGzF,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAQlE,MAAM,UAAU,UAAU,CACxB,aAA+C,EAC/C,OAA8B;IAE9B,MAAM,UAAU,GAAG;QACjB,IAAI,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC;QACzB,cAAc,CAAC,OAAO,CAAC;QACvB,QAAQ,CAAC,OAAO,CAAC;KAClB,CAAA;IAED,IAAI,OAAO,EAAE,GAAG,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,SAAS,GAAG,IAAI,oBAAoB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QAEvD,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,sBAAsB,EAAE,SAAS,EAAE,CAAC,CAAC,CAAA;IAC1E,CAAC;IAED,IAAI,OAAO,EAAE,GAAG,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,SAAS,GAAG,IAAI,oBAAoB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QAEvD,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,sBAAsB,EAAE,SAAS,EAAE,CAAC,CAAC,CAAA;IAC1E,CAAC;IAED,OAAO,eAAe,CAAC,GAAG,UAAU,CAAC,CAAA;AACvC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ValidatorConstraintInterface, ValidationArguments } from 'class-validator';
|
|
2
|
-
import { Quantity } from '../quantity.js';
|
|
3
|
-
export declare class MaxQuantityValidator<
|
|
2
|
+
import { Comparable, Quantity } from '../quantity.js';
|
|
3
|
+
export declare class MaxQuantityValidator<Q extends Quantity & Comparable> implements ValidatorConstraintInterface {
|
|
4
4
|
private max;
|
|
5
5
|
constructor(max: Q);
|
|
6
6
|
validate(q: unknown, _args: ValidationArguments): boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ValidatorConstraintInterface, ValidationArguments } from 'class-validator';
|
|
2
|
-
import { Quantity } from '../quantity.js';
|
|
3
|
-
export declare class MinQuantityValidator<
|
|
2
|
+
import { Comparable, Quantity } from '../quantity.js';
|
|
3
|
+
export declare class MinQuantityValidator<Q extends Quantity & Comparable> implements ValidatorConstraintInterface {
|
|
4
4
|
private min;
|
|
5
5
|
constructor(min: Q);
|
|
6
6
|
validate(q: unknown, _args: ValidationArguments): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wisemen/quantity",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"@nestjs/swagger": "^11.4.6",
|
|
17
17
|
"class-transformer": "^0.5.1",
|
|
18
18
|
"class-validator": "^0.15.1",
|
|
19
|
-
"typeorm": "^1.
|
|
20
|
-
"@wisemen/nestjs-typeorm": "^1.2.
|
|
19
|
+
"typeorm": "^1.1.0",
|
|
20
|
+
"@wisemen/nestjs-typeorm": "^1.2.5"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"eslint": "10.2.1",
|