@wisemen/quantity 0.9.3 → 0.11.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/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 +4 -2
- package/dist/quantities/distance/distance.js +8 -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/duration/duration.column.d.ts +1 -1
- package/dist/quantities/duration/duration.column.js.map +1 -1
- package/dist/quantities/duration/duration.d.ts +4 -2
- package/dist/quantities/duration/duration.js +8 -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/energy/energy-unit.enum.d.ts +3 -1
- package/dist/quantities/energy/energy-unit.enum.js +2 -0
- package/dist/quantities/energy/energy-unit.enum.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 +4 -2
- package/dist/quantities/energy/energy.js +12 -3
- 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 +24 -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 +4 -2
- package/dist/quantities/power/power.js +8 -2
- package/dist/quantities/power/power.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 +4 -2
- package/dist/quantities/speed/speed.js +8 -2
- package/dist/quantities/speed/speed.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 +36 -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
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseQuantity, ScalableQuantity } from '../../quantity.js';
|
|
2
2
|
import { TemperatureUnit } from './temperature-unit.enum.js';
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class TemperatureDelta extends ScalableQuantity<TemperatureUnit, TemperatureDelta, TemperatureDelta> {
|
|
4
|
+
protected getQuantity(): typeof TemperatureDelta;
|
|
5
|
+
protected getDelta(): typeof TemperatureDelta;
|
|
6
|
+
protected getBaseUnit(): TemperatureUnit;
|
|
7
|
+
protected getUnits(): readonly TemperatureUnit[];
|
|
8
|
+
protected convertValueToBaseUnit(value: number, unit: TemperatureUnit): number;
|
|
9
|
+
protected convertBaseUnitValueTo(value: number, unit: TemperatureUnit): number;
|
|
10
|
+
static ZERO: TemperatureDelta;
|
|
11
|
+
}
|
|
12
|
+
export declare class Temperature extends BaseQuantity<TemperatureUnit, Temperature, TemperatureDelta> {
|
|
13
|
+
protected getQuantity(): typeof Temperature;
|
|
14
|
+
protected getDelta(): typeof TemperatureDelta;
|
|
4
15
|
protected getBaseUnit(): TemperatureUnit;
|
|
5
16
|
protected getUnits(): readonly TemperatureUnit[];
|
|
6
17
|
protected convertValueToBaseUnit(value: number, unit: TemperatureUnit): number;
|
|
@@ -1,6 +1,49 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseQuantity, ScalableQuantity } from '../../quantity.js';
|
|
2
2
|
import { TemperatureUnit } from './temperature-unit.enum.js';
|
|
3
|
-
export class
|
|
3
|
+
export class TemperatureDelta extends ScalableQuantity {
|
|
4
|
+
getQuantity() {
|
|
5
|
+
return TemperatureDelta;
|
|
6
|
+
}
|
|
7
|
+
getDelta() {
|
|
8
|
+
return TemperatureDelta;
|
|
9
|
+
}
|
|
10
|
+
getBaseUnit() {
|
|
11
|
+
return TemperatureUnit.KELVIN;
|
|
12
|
+
}
|
|
13
|
+
getUnits() {
|
|
14
|
+
return Object.values(TemperatureUnit);
|
|
15
|
+
}
|
|
16
|
+
convertValueToBaseUnit(value, unit) {
|
|
17
|
+
switch (unit) {
|
|
18
|
+
case TemperatureUnit.KELVIN:
|
|
19
|
+
case TemperatureUnit.CELSIUS:
|
|
20
|
+
return value;
|
|
21
|
+
case TemperatureUnit.FAHRENHEIT:
|
|
22
|
+
return value * 5 / 9;
|
|
23
|
+
case TemperatureUnit.MILLI_DEGREE_CELSIUS:
|
|
24
|
+
return value / 1000;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
convertBaseUnitValueTo(value, unit) {
|
|
28
|
+
switch (unit) {
|
|
29
|
+
case TemperatureUnit.KELVIN:
|
|
30
|
+
case TemperatureUnit.CELSIUS:
|
|
31
|
+
return value;
|
|
32
|
+
case TemperatureUnit.FAHRENHEIT:
|
|
33
|
+
return value * 9 / 5;
|
|
34
|
+
case TemperatureUnit.MILLI_DEGREE_CELSIUS:
|
|
35
|
+
return value * 1000;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
static ZERO = new TemperatureDelta(0, TemperatureUnit.KELVIN);
|
|
39
|
+
}
|
|
40
|
+
export class Temperature extends BaseQuantity {
|
|
41
|
+
getQuantity() {
|
|
42
|
+
return Temperature;
|
|
43
|
+
}
|
|
44
|
+
getDelta() {
|
|
45
|
+
return TemperatureDelta;
|
|
46
|
+
}
|
|
4
47
|
getBaseUnit() {
|
|
5
48
|
return TemperatureUnit.KELVIN;
|
|
6
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temperature.js","sourceRoot":"","sources":["../../../lib/quantities/temperature/temperature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{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CAAC,MAAM,CAAC,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, it } from 'node:test';
|
|
2
2
|
import { expect } from 'expect';
|
|
3
|
-
import { Temperature } from '../temperature.js';
|
|
3
|
+
import { Temperature, TemperatureDelta } from '../temperature.js';
|
|
4
4
|
import { TemperatureUnit } from '../temperature-unit.enum.js';
|
|
5
5
|
void describe('Temperature class', () => {
|
|
6
6
|
void describe('Temperature parsing', () => {
|
|
@@ -10,5 +10,22 @@ void describe('Temperature class', () => {
|
|
|
10
10
|
expect(temperature.unit).toBe(TemperatureUnit.CELSIUS);
|
|
11
11
|
});
|
|
12
12
|
});
|
|
13
|
+
void describe('Temperature calculations', () => {
|
|
14
|
+
void it('adds temperatures', () => {
|
|
15
|
+
const T1 = new Temperature(20, TemperatureUnit.CELSIUS);
|
|
16
|
+
const T2 = new TemperatureDelta(5, TemperatureUnit.KELVIN);
|
|
17
|
+
const r = T1.add(T2);
|
|
18
|
+
expect(r.isEqualTo(25, TemperatureUnit.CELSIUS)).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
void it('subtracts temperatures', () => {
|
|
21
|
+
const T1 = new Temperature(20, TemperatureUnit.CELSIUS);
|
|
22
|
+
const T2 = new Temperature(5, TemperatureUnit.KELVIN);
|
|
23
|
+
const T3 = new TemperatureDelta(5, TemperatureUnit.KELVIN);
|
|
24
|
+
const r1 = T1.subtract(T2);
|
|
25
|
+
const r2 = T1.subtract(T3);
|
|
26
|
+
expect(r1.isEqualTo(288.15, TemperatureUnit.CELSIUS)).toBe(true);
|
|
27
|
+
expect(r2.isEqualTo(15, TemperatureUnit.CELSIUS)).toBe(true);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
13
30
|
});
|
|
14
31
|
//# sourceMappingURL=temperature.unit.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temperature.unit.test.js","sourceRoot":"","sources":["../../../../lib/quantities/temperature/tests/temperature.unit.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"temperature.unit.test.js","sourceRoot":"","sources":["../../../../lib/quantities/temperature/tests/temperature.unit.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAE7D,KAAK,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACtC,KAAK,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;QACxC,KAAK,EAAE,CAAC,4BAA4B,EAAE,GAAG,EAAE;YACzC,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAA;YAE3C,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAA;YACnC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;QACxD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,KAAK,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;QAC7C,KAAK,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE;YAChC,MAAM,EAAE,GAAG,IAAI,WAAW,CAAC,EAAE,EAAE,eAAe,CAAC,OAAO,CAAC,CAAA;YACvD,MAAM,EAAE,GAAG,IAAI,gBAAgB,CAAC,CAAC,EAAE,eAAe,CAAC,MAAM,CAAC,CAAA;YAC1D,MAAM,CAAC,GAAgB,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;YAEjC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC7D,CAAC,CAAC,CAAA;QAEF,KAAK,EAAE,CAAC,wBAAwB,EAAE,GAAG,EAAE;YACrC,MAAM,EAAE,GAAG,IAAI,WAAW,CAAC,EAAE,EAAE,eAAe,CAAC,OAAO,CAAC,CAAA;YACvD,MAAM,EAAE,GAAG,IAAI,WAAW,CAAC,CAAC,EAAE,eAAe,CAAC,MAAM,CAAC,CAAA;YACrD,MAAM,EAAE,GAAG,IAAI,gBAAgB,CAAC,CAAC,EAAE,eAAe,CAAC,MAAM,CAAC,CAAA;YAC1D,MAAM,EAAE,GAAqB,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;YAC5C,MAAM,EAAE,GAAgB,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;YAEvC,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YAChE,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC9D,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { IsQuantityOptions } from '../../validators/is-quantity.decorator.js';
|
|
2
|
-
import { VoltageUnit } from './voltage-unit.enum.js';
|
|
3
2
|
import { Voltage } from './voltage.js';
|
|
4
|
-
export declare function IsVoltage(options?: IsQuantityOptions<
|
|
3
|
+
export declare function IsVoltage(options?: IsQuantityOptions<Voltage>): PropertyDecorator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-voltage.validator.js","sourceRoot":"","sources":["../../../lib/quantities/voltage/is-voltage.validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,UAAU,EAAqB,MAAM,2CAA2C,CAAA;
|
|
1
|
+
{"version":3,"file":"is-voltage.validator.js","sourceRoot":"","sources":["../../../lib/quantities/voltage/is-voltage.validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,UAAU,EAAqB,MAAM,2CAA2C,CAAA;AAEzF,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,MAAM,UAAU,SAAS,CACvB,OAAoC;IAEpC,OAAO,eAAe,CAAC,UAAU,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAA;AACzD,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { QuantityColumnOptions } from '../../quantity.column.js';
|
|
2
2
|
import { VoltageUnit } from './voltage-unit.enum.js';
|
|
3
3
|
import { Voltage } from './voltage.js';
|
|
4
|
-
export declare function VoltageColumn(storeAsUnit: VoltageUnit, options?: QuantityColumnOptions<
|
|
4
|
+
export declare function VoltageColumn(storeAsUnit: VoltageUnit, options?: QuantityColumnOptions<Voltage>): PropertyDecorator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"voltage.column.js","sourceRoot":"","sources":["../../../lib/quantities/voltage/voltage.column.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAEhF,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,MAAM,UAAU,aAAa,CAC3B,WAAwB,EACxB,
|
|
1
|
+
{"version":3,"file":"voltage.column.js","sourceRoot":"","sources":["../../../lib/quantities/voltage/voltage.column.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAEhF,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,MAAM,UAAU,aAAa,CAC3B,WAAwB,EACxB,OAAwC;IAExC,OAAO,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,CAAA;AACtD,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ScalableQuantity } from '../../quantity.js';
|
|
2
2
|
import { VoltageUnit } from './voltage-unit.enum.js';
|
|
3
|
-
export declare class Voltage extends
|
|
3
|
+
export declare class Voltage extends ScalableQuantity<VoltageUnit, Voltage, Voltage> {
|
|
4
|
+
protected getQuantity(): typeof Voltage;
|
|
5
|
+
protected getDelta(): typeof Voltage;
|
|
4
6
|
protected getBaseUnit(): VoltageUnit;
|
|
5
7
|
protected getUnits(): readonly VoltageUnit[];
|
|
6
8
|
protected convertValueToBaseUnit(value: number, fromUnit: VoltageUnit): number;
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ScalableQuantity } from '../../quantity.js';
|
|
2
2
|
import { VoltageUnit } from './voltage-unit.enum.js';
|
|
3
3
|
const VOLTAGE_MULTIPLIERS = {
|
|
4
4
|
[VoltageUnit.VOLT]: 1,
|
|
5
5
|
[VoltageUnit.MILLIVOLT]: 1e-3,
|
|
6
6
|
[VoltageUnit.KILOVOLT]: 1e3
|
|
7
7
|
};
|
|
8
|
-
export class Voltage extends
|
|
8
|
+
export class Voltage extends ScalableQuantity {
|
|
9
|
+
getQuantity() {
|
|
10
|
+
return Voltage;
|
|
11
|
+
}
|
|
12
|
+
getDelta() {
|
|
13
|
+
return Voltage;
|
|
14
|
+
}
|
|
9
15
|
getBaseUnit() {
|
|
10
16
|
return VoltageUnit.VOLT;
|
|
11
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"voltage.js","sourceRoot":"","sources":["../../../lib/quantities/voltage/voltage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"voltage.js","sourceRoot":"","sources":["../../../lib/quantities/voltage/voltage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAEpD,MAAM,mBAAmB,GAAgC;IACvD,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;IACrB,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,IAAI;IAC7B,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,GAAG;CAC5B,CAAA;AAED,MAAM,OAAO,OAAQ,SAAQ,gBAA+C;IAChE,WAAW;QACnB,OAAO,OAAO,CAAA;IAChB,CAAC;IAES,QAAQ;QAChB,OAAO,OAAO,CAAA;IAChB,CAAC;IAES,WAAW;QACnB,OAAO,WAAW,CAAC,IAAI,CAAA;IACzB,CAAC;IAES,QAAQ;QAChB,OAAO,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;IACnC,CAAC;IAES,sBAAsB,CAAE,KAAa,EAAE,QAAqB;QACpE,OAAO,KAAK,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAA;IAC9C,CAAC;IAES,sBAAsB,CAAE,KAAa,EAAE,MAAmB;QAClE,OAAO,KAAK,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAA;IAC5C,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;IACxC,CAAC;IAED,MAAM,CAAC,IAAI,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,WAAW,CAAC,IAAI,CAAC,CAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ColumnOptions, ValueTransformer } from 'typeorm';
|
|
2
2
|
import { Quantity, QuantityConstructor } from './quantity.js';
|
|
3
|
-
export type QuantityColumnOptions<
|
|
3
|
+
export type QuantityColumnOptions<Q extends Quantity> = Omit<ColumnOptions, 'type' | 'transformer' | 'default'> & {
|
|
4
4
|
default?: Q;
|
|
5
5
|
};
|
|
6
|
-
export declare function QuantityColumn<U extends string, Q extends Quantity<U
|
|
7
|
-
export declare class QuantityTypeOrmTransformer<U extends string, Q extends Quantity<U
|
|
6
|
+
export declare function QuantityColumn<U extends string, Q extends Quantity<U>>(QuantityConstructor: QuantityConstructor<U, Q>, storeAsUnit: U, options?: QuantityColumnOptions<Q>): PropertyDecorator;
|
|
7
|
+
export declare class QuantityTypeOrmTransformer<U extends string, Q extends Quantity<U>> implements ValueTransformer {
|
|
8
8
|
private readonly QuantityConstructor;
|
|
9
9
|
private readonly storedUnit;
|
|
10
10
|
constructor(QuantityConstructor: QuantityConstructor<U, Q>, storedUnit: U);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quantity.column.js","sourceRoot":"","sources":["../lib/quantity.column.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAmC,MAAM,SAAS,CAAA;AAMjE,MAAM,UAAU,cAAc;AAC5B,gEAAgE;AAChE,mBAA8C,EAC9C,WAAc,EACd,
|
|
1
|
+
{"version":3,"file":"quantity.column.js","sourceRoot":"","sources":["../lib/quantity.column.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAmC,MAAM,SAAS,CAAA;AAMjE,MAAM,UAAU,cAAc;AAC5B,gEAAgE;AAChE,mBAA8C,EAC9C,WAAc,EACd,OAAkC;IAElC,MAAM,WAAW,GAAG,IAAI,0BAA0B,CAAC,mBAAmB,EAAE,WAAW,CAAC,CAAA;IAEpF,OAAO,MAAM,CAAC;QACZ,GAAG,OAAO;QACV,OAAO,EAAE,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC;QACzC,IAAI,EAAE,OAAO;QACb,WAAW;KACZ,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,OAAO,0BAA0B;IAIlB;IACA;IAHnB;IACE,gEAAgE;IAC/C,mBAA8C,EAC9C,UAAa;QADb,wBAAmB,GAAnB,mBAAmB,CAA2B;QAC9C,eAAU,GAAV,UAAU,CAAG;IAC7B,CAAC;IAIJ,IAAI,CAAE,KAAoB;QACxB,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACnB,OAAO,IAAI,CAAA;QACb,CAAC;QAED,OAAO,IAAI,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAA;IAC7D,CAAC;IAKD,EAAE,CAAE,QAA8B;QAChC,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YAChD,OAAO,QAAQ,CAAA;QACjB,CAAC;QAED,OAAO,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IAC3C,CAAC;CACF"}
|
package/dist/quantity.d.ts
CHANGED
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import { Rate } from './rate/rate.js';
|
|
2
|
-
export
|
|
2
|
+
export interface Comparable {
|
|
3
|
+
valueOf(): number;
|
|
4
|
+
isEqualTo(other: Comparable): boolean;
|
|
5
|
+
isLessThan(other: Comparable): boolean;
|
|
6
|
+
isLessThanOrEqualTo(other: Comparable): boolean;
|
|
7
|
+
isMoreThan(other: Comparable): boolean;
|
|
8
|
+
isMoreThanOrEqualTo(other: Comparable): boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface Quantity<U extends string = string> {
|
|
11
|
+
value: number;
|
|
12
|
+
unit: U;
|
|
13
|
+
asNumber(unit?: U): number;
|
|
14
|
+
}
|
|
15
|
+
export type QuantityConstructor<U extends string, Q extends Quantity<U>> = {
|
|
3
16
|
new (quantity: Q): Q;
|
|
4
17
|
new (value: number, unit: U): Q;
|
|
5
18
|
new (value: 0): Q;
|
|
6
19
|
new (s: string): Q;
|
|
7
20
|
};
|
|
8
|
-
export declare abstract class
|
|
21
|
+
export declare abstract class BaseQuantity<U extends string, Q extends BaseQuantity<U, Q, D>, D extends BaseQuantity<U, D, D>> implements Quantity<U>, Comparable {
|
|
22
|
+
protected abstract getQuantity(): QuantityConstructor<U, Q>;
|
|
23
|
+
protected abstract getDelta(): QuantityConstructor<U, D>;
|
|
9
24
|
protected abstract getBaseUnit(): U;
|
|
10
25
|
protected abstract getUnits(): readonly U[];
|
|
11
26
|
protected abstract convertValueToBaseUnit(value: number, fromUnit: U): number;
|
|
@@ -16,7 +31,10 @@ export declare abstract class Quantity<U extends string, Q extends Quantity<U, Q
|
|
|
16
31
|
constructor(value: number, unit: U);
|
|
17
32
|
constructor(value: 0);
|
|
18
33
|
constructor(s: string);
|
|
19
|
-
|
|
34
|
+
protected isQuantity(quantityOrValue: unknown): quantityOrValue is Q;
|
|
35
|
+
protected isDelta(quantityOrValue: unknown): quantityOrValue is D;
|
|
36
|
+
protected constructQuantity(quantityOrValue: Q | number, unit?: U): Q;
|
|
37
|
+
protected constructDelta(quantityOrValue: D | number, unit?: U): D;
|
|
20
38
|
/** Converts the quantity to the specified unit */
|
|
21
39
|
to(unit: U): Q;
|
|
22
40
|
/** Returns the numeric value of the quantity in the specified unit */
|
|
@@ -38,18 +56,11 @@ export declare abstract class Quantity<U extends string, Q extends Quantity<U, Q
|
|
|
38
56
|
isMoreThanOrEqualTo(quantity: Q): boolean;
|
|
39
57
|
/** Creates a new quantity by adding the current quantity to another quantity */
|
|
40
58
|
add(value: number, unit: U): Q;
|
|
41
|
-
add(quantity:
|
|
59
|
+
add(quantity: D): Q;
|
|
42
60
|
/** Creates a new quantity by subtracting another quantity from the current quantity */
|
|
43
61
|
subtract(value: number, unit: U): Q;
|
|
44
|
-
subtract(quantity: Q):
|
|
45
|
-
|
|
46
|
-
multiply(factor: number): Q;
|
|
47
|
-
multiply(rate: Rate): Q;
|
|
48
|
-
/** Creates a new quantity by dividing the current quantity by the specified divisor */
|
|
49
|
-
divide(divisor: number): Q;
|
|
50
|
-
divide(rate: Rate): Q;
|
|
51
|
-
divide(value: number, unit: U): number;
|
|
52
|
-
divide(quantity: Q): number;
|
|
62
|
+
subtract(quantity: Q): D;
|
|
63
|
+
subtract(quantity: D): Q;
|
|
53
64
|
/** Creates a new quantity by calculating the modulus of
|
|
54
65
|
* the current quantity and another quantity */
|
|
55
66
|
modulo(value: number, unit: U): Q;
|
|
@@ -71,12 +82,22 @@ export declare abstract class Quantity<U extends string, Q extends Quantity<U, Q
|
|
|
71
82
|
toJSON(): object;
|
|
72
83
|
format(locale?: string, options?: Intl.NumberFormatOptions): string;
|
|
73
84
|
/** Returns the maximum quantity from the provided quantities */
|
|
74
|
-
static max<
|
|
85
|
+
static max<Q extends Comparable>(...quantities: Q[]): Q;
|
|
75
86
|
/** Returns the minimum quantity from the provided quantities */
|
|
76
|
-
static min<
|
|
87
|
+
static min<Q extends Comparable>(...quantities: Q[]): Q;
|
|
77
88
|
protected parseString(s: string, units: readonly U[]): {
|
|
78
89
|
value: number;
|
|
79
90
|
unit: U;
|
|
80
91
|
};
|
|
81
92
|
private static escapeRegex;
|
|
82
93
|
}
|
|
94
|
+
export declare abstract class ScalableQuantity<U extends string, Q extends BaseQuantity<U, Q, D>, D extends BaseQuantity<U, D, D>> extends BaseQuantity<U, Q, D> {
|
|
95
|
+
/** Creates a new quantity by multiplying the current quantity with the specified factor */
|
|
96
|
+
multiply(factor: number): Q;
|
|
97
|
+
multiply(rate: Rate): Q;
|
|
98
|
+
/** Creates a new quantity by dividing the current quantity by the specified divisor */
|
|
99
|
+
divide(divisor: number): Q;
|
|
100
|
+
divide(rate: Rate): Q;
|
|
101
|
+
divide(value: number, unit: U): number;
|
|
102
|
+
divide(quantity: Q): number;
|
|
103
|
+
}
|
package/dist/quantity.dto.d.ts
CHANGED
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(factorOrRate) {
|
|
163
|
+
const factor = factorOrRate instanceof Rate ? factorOrRate.asDecimal() : factorOrRate;
|
|
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,CAAC;YACjC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAA;YACd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAA;QAChC,CAAC;aAAM,IAAI,OAAO,eAAe,KAAK,QAAQ,EAAE,CAAC;YAC/C,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;YACvE,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC,KAAK,CAAA;YAC/B,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC,IAAI,CAAA;QAC/B,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE,8DAA8D,CAAC,CAAA;YAC1F,IAAI,CAAC,KAAK,GAAG,eAAe,CAAA;YAC5B,IA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K,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAA;IACrD,CAAC;CACF;AAED,MAAM,OAAgB,gBAIpB,SAAQ,YAAqB;IAI7B,QAAQ,CAAE,YAA2B;QACnC,MAAM,MAAM,GAAG,YAAY,YAAY,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,YAAY,CAAA;QACrF,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;IAC1F,CAAC;IAOD,MAAM,CAAE,OAA0B,EAAE,IAAQ;QAC1C,IAAI,OAAO,YAAY,YAAY,IAAI,CAAC,OAAO,OAAO,KAAK,QAAQ,IAAI,IAAI,KAAK,SAAS,CAAC,EAAE,CAAC;YAC3F,MAAM,KAAK,GAAG,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;YAEnD,OAAO,IAAI,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,OAAO,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.0",
|
|
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.4"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"eslint": "10.2.1",
|