@hahnpro/flow-sdk 4.14.4
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/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/FlowApplication.d.ts +35 -0
- package/dist/FlowApplication.js +270 -0
- package/dist/FlowElement.d.ts +50 -0
- package/dist/FlowElement.js +143 -0
- package/dist/FlowEvent.d.ts +19 -0
- package/dist/FlowEvent.js +71 -0
- package/dist/FlowLogger.d.ts +23 -0
- package/dist/FlowLogger.js +57 -0
- package/dist/FlowModule.d.ts +7 -0
- package/dist/FlowModule.js +14 -0
- package/dist/RpcClient.d.ts +11 -0
- package/dist/RpcClient.js +70 -0
- package/dist/TestModule.d.ts +2 -0
- package/dist/TestModule.js +27 -0
- package/dist/amqp.d.ts +33 -0
- package/dist/amqp.js +12 -0
- package/dist/api/Queue.d.ts +15 -0
- package/dist/api/Queue.js +27 -0
- package/dist/api/api.d.ts +62 -0
- package/dist/api/api.js +52 -0
- package/dist/api/asset.interface.d.ts +54 -0
- package/dist/api/asset.interface.js +2 -0
- package/dist/api/asset.service.d.ts +10 -0
- package/dist/api/asset.service.js +21 -0
- package/dist/api/assettypes.service.d.ts +6 -0
- package/dist/api/assettypes.service.js +10 -0
- package/dist/api/content.interface.d.ts +35 -0
- package/dist/api/content.interface.js +12 -0
- package/dist/api/content.service.d.ts +17 -0
- package/dist/api/content.service.js +39 -0
- package/dist/api/data.interface.d.ts +29 -0
- package/dist/api/data.interface.js +2 -0
- package/dist/api/data.service.d.ts +15 -0
- package/dist/api/data.service.js +49 -0
- package/dist/api/endpoint.interface.d.ts +22 -0
- package/dist/api/endpoint.interface.js +2 -0
- package/dist/api/endpoint.service.d.ts +8 -0
- package/dist/api/endpoint.service.js +17 -0
- package/dist/api/events.interface.d.ts +16 -0
- package/dist/api/events.interface.js +2 -0
- package/dist/api/events.service.d.ts +7 -0
- package/dist/api/events.service.js +13 -0
- package/dist/api/http.service.d.ts +26 -0
- package/dist/api/http.service.js +74 -0
- package/dist/api/index.d.ts +12 -0
- package/dist/api/index.js +16 -0
- package/dist/api/mock/api.mock.d.ts +158 -0
- package/dist/api/mock/api.mock.js +111 -0
- package/dist/api/mock/asset.mock.service.d.ts +12 -0
- package/dist/api/mock/asset.mock.service.js +21 -0
- package/dist/api/mock/assetTypes.mock.service.d.ts +6 -0
- package/dist/api/mock/assetTypes.mock.service.js +11 -0
- package/dist/api/mock/content.mock.service.d.ts +18 -0
- package/dist/api/mock/content.mock.service.js +64 -0
- package/dist/api/mock/data.mock.service.d.ts +13 -0
- package/dist/api/mock/data.mock.service.js +52 -0
- package/dist/api/mock/endpoint.mock.service.d.ts +15 -0
- package/dist/api/mock/endpoint.mock.service.js +24 -0
- package/dist/api/mock/events.mock.service.d.ts +7 -0
- package/dist/api/mock/events.mock.service.js +14 -0
- package/dist/api/mock/index.d.ts +9 -0
- package/dist/api/mock/index.js +12 -0
- package/dist/api/mock/secret.mock.service.d.ts +6 -0
- package/dist/api/mock/secret.mock.service.js +11 -0
- package/dist/api/mock/task.mock.service.d.ts +7 -0
- package/dist/api/mock/task.mock.service.js +15 -0
- package/dist/api/mock/timeseries.mock.service.d.ts +19 -0
- package/dist/api/mock/timeseries.mock.service.js +69 -0
- package/dist/api/mock/user.mock.service.d.ts +7 -0
- package/dist/api/mock/user.mock.service.js +14 -0
- package/dist/api/proxy.service.d.ts +11 -0
- package/dist/api/proxy.service.js +17 -0
- package/dist/api/secret.interface.d.ts +7 -0
- package/dist/api/secret.interface.js +2 -0
- package/dist/api/secret.service.d.ts +6 -0
- package/dist/api/secret.service.js +10 -0
- package/dist/api/sidriveiq.interface.d.ts +104 -0
- package/dist/api/sidriveiq.interface.js +2 -0
- package/dist/api/sidriveiq.service.d.ts +97 -0
- package/dist/api/sidriveiq.service.js +97 -0
- package/dist/api/task.interface.d.ts +22 -0
- package/dist/api/task.interface.js +2 -0
- package/dist/api/task.service.d.ts +7 -0
- package/dist/api/task.service.js +13 -0
- package/dist/api/timeseries.interface.d.ts +39 -0
- package/dist/api/timeseries.interface.js +2 -0
- package/dist/api/timeseries.service.d.ts +17 -0
- package/dist/api/timeseries.service.js +38 -0
- package/dist/api/user.service.d.ts +6 -0
- package/dist/api/user.service.js +21 -0
- package/dist/extra-validators.d.ts +1 -0
- package/dist/extra-validators.js +52 -0
- package/dist/flow.interface.d.ts +41 -0
- package/dist/flow.interface.js +2 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +16 -0
- package/dist/rpc_server.py +115 -0
- package/dist/unit-decorators.d.ts +39 -0
- package/dist/unit-decorators.js +157 -0
- package/dist/unit-utils.d.ts +8 -0
- package/dist/unit-utils.js +143 -0
- package/dist/units.d.ts +31 -0
- package/dist/units.js +570 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.js +106 -0
- package/package.json +64 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IsElectricalFrequency = exports.IsElectricalEnergy = exports.IsElectricalPower = exports.IsThermalTransmittance = exports.IsSpecificHeatCapacity = exports.IsThermalEnergy = exports.IsHeatFlux = exports.IsMassFlow = exports.IsVolumeFlow = exports.IsDynamicViscosity = exports.IsMechanicalEnergy = exports.IsMechanicalPower = exports.IsRotatingUnbalance = exports.IsMomentOfInertia = exports.IsTorque = exports.IsRotationalDisplacement = exports.IsRotationalVelocity = exports.IsRotationalAcceleration = exports.IsSpringConstant = exports.IsTranslationalDisplacement = exports.IsTranslationalVelocity = exports.IsTranslationalAcceleration = exports.IsAngle = exports.IsVolume = exports.IsArea = exports.IsFrequency = exports.IsPressure = exports.IsPower = exports.IsEnergy = exports.IsForce = exports.IsVoltage = exports.IsLuminousIntensity = exports.IsAmountOfSubstance = exports.IsThermodynamicTemperature = exports.IsElectricCurrent = exports.IsMass = exports.IsLength = exports.IsTime = void 0;
|
|
4
|
+
const unit_utils_1 = require("./unit-utils");
|
|
5
|
+
const units_1 = require("./units");
|
|
6
|
+
function IsTime(unit = units_1.units.time.baseUnit, validationOptions) {
|
|
7
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'time', validationOptions);
|
|
8
|
+
}
|
|
9
|
+
exports.IsTime = IsTime;
|
|
10
|
+
function IsLength(unit = units_1.units.length.baseUnit, validationOptions) {
|
|
11
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'length', validationOptions);
|
|
12
|
+
}
|
|
13
|
+
exports.IsLength = IsLength;
|
|
14
|
+
function IsMass(unit = units_1.units.mass.baseUnit, validationOptions) {
|
|
15
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'mass', validationOptions);
|
|
16
|
+
}
|
|
17
|
+
exports.IsMass = IsMass;
|
|
18
|
+
function IsElectricCurrent(unit = units_1.units.electricCurrent.baseUnit, validationOptions) {
|
|
19
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'electricCurrent', validationOptions);
|
|
20
|
+
}
|
|
21
|
+
exports.IsElectricCurrent = IsElectricCurrent;
|
|
22
|
+
function IsThermodynamicTemperature(unit = units_1.units.thermodynamicTemperature.baseUnit, validationOptions) {
|
|
23
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'thermodynamicTemperature', validationOptions);
|
|
24
|
+
}
|
|
25
|
+
exports.IsThermodynamicTemperature = IsThermodynamicTemperature;
|
|
26
|
+
function IsAmountOfSubstance(unit = units_1.units.amountOfSubstance.baseUnit, validationOptions) {
|
|
27
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'amountOfSubstance', validationOptions);
|
|
28
|
+
}
|
|
29
|
+
exports.IsAmountOfSubstance = IsAmountOfSubstance;
|
|
30
|
+
function IsLuminousIntensity(unit = units_1.units.luminousIntensity.baseUnit, validationOptions) {
|
|
31
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'luminousIntensity', validationOptions);
|
|
32
|
+
}
|
|
33
|
+
exports.IsLuminousIntensity = IsLuminousIntensity;
|
|
34
|
+
function IsVoltage(unit = units_1.units.voltage.baseUnit, validationOptions) {
|
|
35
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'voltage', validationOptions);
|
|
36
|
+
}
|
|
37
|
+
exports.IsVoltage = IsVoltage;
|
|
38
|
+
function IsForce(unit = units_1.units.force.baseUnit, validationOptions) {
|
|
39
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'force', validationOptions);
|
|
40
|
+
}
|
|
41
|
+
exports.IsForce = IsForce;
|
|
42
|
+
function IsEnergy(unit = units_1.units.energy.baseUnit, validationOptions) {
|
|
43
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'energy', validationOptions);
|
|
44
|
+
}
|
|
45
|
+
exports.IsEnergy = IsEnergy;
|
|
46
|
+
function IsPower(unit = units_1.units.power.baseUnit, validationOptions) {
|
|
47
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'power', validationOptions);
|
|
48
|
+
}
|
|
49
|
+
exports.IsPower = IsPower;
|
|
50
|
+
function IsPressure(unit = units_1.units.pressure.baseUnit, validationOptions) {
|
|
51
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'pressure', validationOptions);
|
|
52
|
+
}
|
|
53
|
+
exports.IsPressure = IsPressure;
|
|
54
|
+
function IsFrequency(unit = units_1.units.frequency.baseUnit, validationOptions) {
|
|
55
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'frequency', validationOptions);
|
|
56
|
+
}
|
|
57
|
+
exports.IsFrequency = IsFrequency;
|
|
58
|
+
function IsArea(unit = units_1.units.area.baseUnit, validationOptions) {
|
|
59
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'area', validationOptions);
|
|
60
|
+
}
|
|
61
|
+
exports.IsArea = IsArea;
|
|
62
|
+
function IsVolume(unit = units_1.units.volume.baseUnit, validationOptions) {
|
|
63
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'volume', validationOptions);
|
|
64
|
+
}
|
|
65
|
+
exports.IsVolume = IsVolume;
|
|
66
|
+
function IsAngle(unit = units_1.units.angle.baseUnit, validationOptions) {
|
|
67
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'angle', validationOptions);
|
|
68
|
+
}
|
|
69
|
+
exports.IsAngle = IsAngle;
|
|
70
|
+
function IsTranslationalAcceleration(unit = units_1.units.translationalAcceleration.baseUnit, validationOptions) {
|
|
71
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'translationalAcceleration', validationOptions);
|
|
72
|
+
}
|
|
73
|
+
exports.IsTranslationalAcceleration = IsTranslationalAcceleration;
|
|
74
|
+
function IsTranslationalVelocity(unit = units_1.units.translationalVelocity.baseUnit, validationOptions) {
|
|
75
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'translationalVelocity', validationOptions);
|
|
76
|
+
}
|
|
77
|
+
exports.IsTranslationalVelocity = IsTranslationalVelocity;
|
|
78
|
+
function IsTranslationalDisplacement(unit = units_1.units.translationalDisplacement.baseUnit, validationOptions) {
|
|
79
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'translationalDisplacement', validationOptions);
|
|
80
|
+
}
|
|
81
|
+
exports.IsTranslationalDisplacement = IsTranslationalDisplacement;
|
|
82
|
+
function IsSpringConstant(unit = units_1.units.springConstant.baseUnit, validationOptions) {
|
|
83
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'springConstant', validationOptions);
|
|
84
|
+
}
|
|
85
|
+
exports.IsSpringConstant = IsSpringConstant;
|
|
86
|
+
function IsRotationalAcceleration(unit = units_1.units.rotationalAcceleration.baseUnit, validationOptions) {
|
|
87
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'rotationalAcceleration', validationOptions);
|
|
88
|
+
}
|
|
89
|
+
exports.IsRotationalAcceleration = IsRotationalAcceleration;
|
|
90
|
+
function IsRotationalVelocity(unit = units_1.units.rotationalVelocity.baseUnit, validationOptions) {
|
|
91
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'rotationalVelocity', validationOptions);
|
|
92
|
+
}
|
|
93
|
+
exports.IsRotationalVelocity = IsRotationalVelocity;
|
|
94
|
+
function IsRotationalDisplacement(unit = units_1.units.rotationalDisplacement.baseUnit, validationOptions) {
|
|
95
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'rotationalDisplacement', validationOptions);
|
|
96
|
+
}
|
|
97
|
+
exports.IsRotationalDisplacement = IsRotationalDisplacement;
|
|
98
|
+
function IsTorque(unit = units_1.units.torque.baseUnit, validationOptions) {
|
|
99
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'torque', validationOptions);
|
|
100
|
+
}
|
|
101
|
+
exports.IsTorque = IsTorque;
|
|
102
|
+
function IsMomentOfInertia(unit = units_1.units.momentOfInertia.baseUnit, validationOptions) {
|
|
103
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'momentOfInertia', validationOptions);
|
|
104
|
+
}
|
|
105
|
+
exports.IsMomentOfInertia = IsMomentOfInertia;
|
|
106
|
+
function IsRotatingUnbalance(unit = units_1.units.rotatingUnbalance.baseUnit, validationOptions) {
|
|
107
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'rotatingUnbalance', validationOptions);
|
|
108
|
+
}
|
|
109
|
+
exports.IsRotatingUnbalance = IsRotatingUnbalance;
|
|
110
|
+
function IsMechanicalPower(unit = units_1.units.mechanicalPower.baseUnit, validationOptions) {
|
|
111
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'mechanicalPower', validationOptions);
|
|
112
|
+
}
|
|
113
|
+
exports.IsMechanicalPower = IsMechanicalPower;
|
|
114
|
+
function IsMechanicalEnergy(unit = units_1.units.mechanicalEnergy.baseUnit, validationOptions) {
|
|
115
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'mechanicalEnergy', validationOptions);
|
|
116
|
+
}
|
|
117
|
+
exports.IsMechanicalEnergy = IsMechanicalEnergy;
|
|
118
|
+
function IsDynamicViscosity(unit = units_1.units.dynamicViscosity.baseUnit, validationOptions) {
|
|
119
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'dynamicViscosity', validationOptions);
|
|
120
|
+
}
|
|
121
|
+
exports.IsDynamicViscosity = IsDynamicViscosity;
|
|
122
|
+
function IsVolumeFlow(unit = units_1.units.volumeFlow.baseUnit, validationOptions) {
|
|
123
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'volumeFlow', validationOptions);
|
|
124
|
+
}
|
|
125
|
+
exports.IsVolumeFlow = IsVolumeFlow;
|
|
126
|
+
function IsMassFlow(unit = units_1.units.massFlow.baseUnit, validationOptions) {
|
|
127
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'massFlow', validationOptions);
|
|
128
|
+
}
|
|
129
|
+
exports.IsMassFlow = IsMassFlow;
|
|
130
|
+
function IsHeatFlux(unit = units_1.units.heatFlux.baseUnit, validationOptions) {
|
|
131
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'heatFlux', validationOptions);
|
|
132
|
+
}
|
|
133
|
+
exports.IsHeatFlux = IsHeatFlux;
|
|
134
|
+
function IsThermalEnergy(unit = units_1.units.thermalEnergy.baseUnit, validationOptions) {
|
|
135
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'thermalEnergy', validationOptions);
|
|
136
|
+
}
|
|
137
|
+
exports.IsThermalEnergy = IsThermalEnergy;
|
|
138
|
+
function IsSpecificHeatCapacity(unit = units_1.units.specificHeatCapacity.baseUnit, validationOptions) {
|
|
139
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'specificHeatCapacity', validationOptions);
|
|
140
|
+
}
|
|
141
|
+
exports.IsSpecificHeatCapacity = IsSpecificHeatCapacity;
|
|
142
|
+
function IsThermalTransmittance(unit = units_1.units.thermalTransmittance.baseUnit, validationOptions) {
|
|
143
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'thermalTransmittance', validationOptions);
|
|
144
|
+
}
|
|
145
|
+
exports.IsThermalTransmittance = IsThermalTransmittance;
|
|
146
|
+
function IsElectricalPower(unit = units_1.units.electricalPower.baseUnit, validationOptions) {
|
|
147
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'electricalPower', validationOptions);
|
|
148
|
+
}
|
|
149
|
+
exports.IsElectricalPower = IsElectricalPower;
|
|
150
|
+
function IsElectricalEnergy(unit = units_1.units.electricalEnergy.baseUnit, validationOptions) {
|
|
151
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'electricalEnergy', validationOptions);
|
|
152
|
+
}
|
|
153
|
+
exports.IsElectricalEnergy = IsElectricalEnergy;
|
|
154
|
+
function IsElectricalFrequency(unit = units_1.units.electricalFrequency.baseUnit, validationOptions) {
|
|
155
|
+
return (0, unit_utils_1.makeUnitDecorator)(unit, 'electricalFrequency', validationOptions);
|
|
156
|
+
}
|
|
157
|
+
exports.IsElectricalFrequency = IsElectricalFrequency;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ValidationOptions } from 'class-validator';
|
|
2
|
+
export declare function makeUnitDecorator(unit: string, metric: string, validationOptions?: ValidationOptions): (object: any, propertyName: string) => void;
|
|
3
|
+
export declare function verifyUnit(unit: string, metric: string): number;
|
|
4
|
+
export declare function computeUnitOptions(dimension: string): {
|
|
5
|
+
prefUnit: string;
|
|
6
|
+
convfactor: number;
|
|
7
|
+
offset: number;
|
|
8
|
+
}[];
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeUnitOptions = exports.verifyUnit = exports.makeUnitDecorator = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const class_validator_1 = require("class-validator");
|
|
6
|
+
const units_1 = require("./units");
|
|
7
|
+
function makeUnitDecorator(unit, metric, validationOptions) {
|
|
8
|
+
const conversionFactor = verifyUnit(unit, metric);
|
|
9
|
+
if (conversionFactor < 0)
|
|
10
|
+
throw `${unit} is not a valid ${metric}.`;
|
|
11
|
+
return (object, propertyName) => {
|
|
12
|
+
Reflect.defineMetadata(`conversionFactor:${propertyName}`, conversionFactor, object.constructor);
|
|
13
|
+
(0, class_validator_1.registerDecorator)({
|
|
14
|
+
target: object.constructor,
|
|
15
|
+
propertyName,
|
|
16
|
+
options: validationOptions,
|
|
17
|
+
constraints: [metric, unit],
|
|
18
|
+
validator: UnitArgsValidator,
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
exports.makeUnitDecorator = makeUnitDecorator;
|
|
23
|
+
let UnitArgsValidator = class UnitArgsValidator {
|
|
24
|
+
validate(value, validationArguments) {
|
|
25
|
+
return (0, class_validator_1.isNumber)(value);
|
|
26
|
+
}
|
|
27
|
+
defaultMessage(args) {
|
|
28
|
+
return `${args.property} must be a number conforming to the specified constraints`;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
UnitArgsValidator = (0, tslib_1.__decorate)([
|
|
32
|
+
(0, class_validator_1.ValidatorConstraint)({ async: false })
|
|
33
|
+
], UnitArgsValidator);
|
|
34
|
+
const prefixes = [
|
|
35
|
+
{ prefix: 'Y', convfactor: 1e24 },
|
|
36
|
+
{ prefix: 'Z', convfactor: 1e21 },
|
|
37
|
+
{ prefix: 'E', convfactor: 1e18 },
|
|
38
|
+
{ prefix: 'P', convfactor: 1e15 },
|
|
39
|
+
{ prefix: 'T', convfactor: 1e12 },
|
|
40
|
+
{ prefix: 'G', convfactor: 1e9 },
|
|
41
|
+
{ prefix: 'M', convfactor: 1e6 },
|
|
42
|
+
{ prefix: 'k', convfactor: 1e3 },
|
|
43
|
+
{ prefix: 'h', convfactor: 1e2 },
|
|
44
|
+
{ prefix: 'da', convfactor: 1e1 },
|
|
45
|
+
{ prefix: 'd', convfactor: 1e-1 },
|
|
46
|
+
{ prefix: 'c', convfactor: 1e-2 },
|
|
47
|
+
{ prefix: 'm', convfactor: 1e-3 },
|
|
48
|
+
{ prefix: 'μ', convfactor: 1e-6 },
|
|
49
|
+
{ prefix: 'n', convfactor: 1e-9 },
|
|
50
|
+
{ prefix: 'p', convfactor: 1e-12 },
|
|
51
|
+
{ prefix: 'f', convfactor: 1e-15 },
|
|
52
|
+
{ prefix: 'a', convfactor: 1e-18 },
|
|
53
|
+
{ prefix: 'z', convfactor: 1e-21 },
|
|
54
|
+
{ prefix: 'y', convfactor: 1e-24 },
|
|
55
|
+
];
|
|
56
|
+
function verifyUnit(unit, metric) {
|
|
57
|
+
if (unit === '' || metric === '')
|
|
58
|
+
return -1;
|
|
59
|
+
const definition = units_1.units[metric];
|
|
60
|
+
for (const dimension of definition.dimensions) {
|
|
61
|
+
const components = dimension.split('*');
|
|
62
|
+
const nominator = components.filter((v) => !v.includes('-'));
|
|
63
|
+
const denominator = components.filter((v) => v.includes('-'));
|
|
64
|
+
const nomIndices = computeIndices(unit.split('/')[0], nominator);
|
|
65
|
+
const denomIndices = computeIndices(unit.split('/')[1] || '', denominator);
|
|
66
|
+
const nomFactor = verifyIndices(nomIndices, unit.split('/')[0]);
|
|
67
|
+
const denomFactor = verifyIndices(denomIndices, unit.split('/')[1]);
|
|
68
|
+
if (nomFactor > 0 && denomFactor > 0) {
|
|
69
|
+
return nomFactor / denomFactor;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return -1;
|
|
73
|
+
}
|
|
74
|
+
exports.verifyUnit = verifyUnit;
|
|
75
|
+
function verifyIndices(indices, unit) {
|
|
76
|
+
if (indices.length === 0 || !unit)
|
|
77
|
+
return 1;
|
|
78
|
+
const filtered = indices
|
|
79
|
+
.map((arr) => arr.filter((v) => v.index !== -1))
|
|
80
|
+
.reduce((previousValue, currentValue) => {
|
|
81
|
+
if (currentValue.length > 1) {
|
|
82
|
+
for (let j = 0; j < currentValue.length - 1; j++) {
|
|
83
|
+
previousValue.forEach((value) => previousValue.push([...value]));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
let index = 0;
|
|
87
|
+
while (index < previousValue.length) {
|
|
88
|
+
previousValue[index].push(currentValue[index % currentValue.length]);
|
|
89
|
+
index++;
|
|
90
|
+
}
|
|
91
|
+
return previousValue;
|
|
92
|
+
}, [[]]);
|
|
93
|
+
outer: for (const filteredElement of filtered) {
|
|
94
|
+
let index = 0;
|
|
95
|
+
let convfactor = 1;
|
|
96
|
+
while (index != unit.length) {
|
|
97
|
+
const find = filteredElement.find((obj) => (obj === null || obj === void 0 ? void 0 : obj.index) === index);
|
|
98
|
+
if (!find)
|
|
99
|
+
continue outer;
|
|
100
|
+
index += find.length;
|
|
101
|
+
convfactor *= find.convfactor;
|
|
102
|
+
}
|
|
103
|
+
return convfactor;
|
|
104
|
+
}
|
|
105
|
+
return -1;
|
|
106
|
+
}
|
|
107
|
+
function computeIndices(unit, dimensions) {
|
|
108
|
+
return dimensions.map((dimension) => {
|
|
109
|
+
const options = computeUnitOptions(dimension);
|
|
110
|
+
const indices = options.map((preUnit) => unit.indexOf(preUnit.prefUnit));
|
|
111
|
+
return indices.map((ind, index) => ({
|
|
112
|
+
index: ind,
|
|
113
|
+
length: options[index].prefUnit.length,
|
|
114
|
+
convfactor: options[index].convfactor,
|
|
115
|
+
offset: options[index].offset,
|
|
116
|
+
}));
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
function computeUnitOptions(dimension) {
|
|
120
|
+
const definition = units_1.units[units_1.dimensionToUnitMap[dimension.substring(0, 1)]];
|
|
121
|
+
const exponent = dimension.length === 1 ? 1 : Number.parseInt(dimension.substring(dimension.length - 1));
|
|
122
|
+
const withPrefixes = definition.units
|
|
123
|
+
.filter((unit) => unit.SIPrefixes)
|
|
124
|
+
.map((unit) => prefixes.map((prefix) => ({
|
|
125
|
+
prefUnit: prefix.prefix.concat(unit.unit),
|
|
126
|
+
convfactor: Math.pow(prefix.convfactor * unit.conversionFactor, exponent),
|
|
127
|
+
offset: unit.offset || 0,
|
|
128
|
+
})))
|
|
129
|
+
.reduce((prev, curr) => prev.concat(curr), []);
|
|
130
|
+
const allUnits = withPrefixes.concat(definition.units.map((unit) => ({
|
|
131
|
+
prefUnit: unit.unit,
|
|
132
|
+
convfactor: Math.pow(unit.conversionFactor, exponent),
|
|
133
|
+
offset: unit.offset || 0,
|
|
134
|
+
})));
|
|
135
|
+
return dimension.length > 1 && !dimension.endsWith('-1')
|
|
136
|
+
? allUnits.map((unit) => ({
|
|
137
|
+
prefUnit: `${unit.prefUnit}^${dimension.substring(dimension.length - 1)}`,
|
|
138
|
+
convfactor: unit.convfactor,
|
|
139
|
+
offset: unit.offset,
|
|
140
|
+
}))
|
|
141
|
+
: allUnits;
|
|
142
|
+
}
|
|
143
|
+
exports.computeUnitOptions = computeUnitOptions;
|
package/dist/units.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare const dimensionToUnitMap: {
|
|
2
|
+
T: string;
|
|
3
|
+
L: string;
|
|
4
|
+
M: string;
|
|
5
|
+
I: string;
|
|
6
|
+
Θ: string;
|
|
7
|
+
N: string;
|
|
8
|
+
J: string;
|
|
9
|
+
U: string;
|
|
10
|
+
F: string;
|
|
11
|
+
E: string;
|
|
12
|
+
W: string;
|
|
13
|
+
P: string;
|
|
14
|
+
A: string;
|
|
15
|
+
V: string;
|
|
16
|
+
f: string;
|
|
17
|
+
};
|
|
18
|
+
export declare const units: UnitDefinitions;
|
|
19
|
+
export declare type UnitDefinitions = {
|
|
20
|
+
[key: string]: UnitDefinition;
|
|
21
|
+
};
|
|
22
|
+
export declare type UnitDefinition = {
|
|
23
|
+
units: {
|
|
24
|
+
unit: string;
|
|
25
|
+
conversionFactor: number;
|
|
26
|
+
SIPrefixes: boolean;
|
|
27
|
+
offset?: number;
|
|
28
|
+
}[];
|
|
29
|
+
baseUnit: string;
|
|
30
|
+
dimensions: string[];
|
|
31
|
+
};
|