@etainabl/nodejs-sdk 1.1.3 → 1.1.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/dist/units.d.ts +2 -2
- package/dist/units.js +2 -2
- package/dist/units.js.map +1 -1
- package/package.json +1 -1
- package/src/units.ts +2 -2
package/dist/units.d.ts
CHANGED
|
@@ -7,14 +7,14 @@ interface Item {
|
|
|
7
7
|
export declare type AccountType = 'electricity' | 'gas' | 'water' | 'waste' | 'solar' | 'heating' | 'flow' | 'cooling' | 'temperature';
|
|
8
8
|
export declare type ETNUnit = 'kwh' | 'kg' | 'm3' | 'lbs' | 'tonnes' | 'wh' | 'mwh' | 'ft3' | 'hcf' | 'm3/h' | 'wh' | 'qty' | 'l' | 'C';
|
|
9
9
|
export declare type BaseUnit = 'kwh' | 'm3' | 'C' | 'kg' | 'm3/h';
|
|
10
|
-
export declare const convertItems: (items: Item[], type: AccountType) => {
|
|
10
|
+
export declare const convertItems: (items: Item[], type: AccountType, defaultUnits: ETNUnit | undefined) => {
|
|
11
11
|
value: number;
|
|
12
12
|
units: BaseUnit;
|
|
13
13
|
unit: string | null;
|
|
14
14
|
factor: number | null;
|
|
15
15
|
}[];
|
|
16
16
|
declare const _default: {
|
|
17
|
-
convertItems: (items: Item[], type: AccountType) => {
|
|
17
|
+
convertItems: (items: Item[], type: AccountType, defaultUnits: ETNUnit | undefined) => {
|
|
18
18
|
value: number;
|
|
19
19
|
units: BaseUnit;
|
|
20
20
|
unit: string | null;
|
package/dist/units.js
CHANGED
|
@@ -35,7 +35,7 @@ const unitConversionFactors = {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
// Convert units to base format
|
|
38
|
-
export const convertItems = (items, type) => {
|
|
38
|
+
export const convertItems = (items, type, defaultUnits) => {
|
|
39
39
|
if (!type)
|
|
40
40
|
throw new Error('Account type is required');
|
|
41
41
|
const baseUnit = accountTypeMap[type];
|
|
@@ -43,7 +43,7 @@ export const convertItems = (items, type) => {
|
|
|
43
43
|
throw new Error(`Account type ${type} is not supported`);
|
|
44
44
|
const convertedItems = items.map(item => {
|
|
45
45
|
const factor = item.factor || 1;
|
|
46
|
-
const units = item.units || item.unit || baseUnit;
|
|
46
|
+
const units = item.units || item.unit || defaultUnits || baseUnit;
|
|
47
47
|
const convertedValue = item.value * _getConversionFactor(units, baseUnit) * factor;
|
|
48
48
|
return { ...item, value: convertedValue, units: baseUnit };
|
|
49
49
|
});
|
package/dist/units.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"units.js","sourceRoot":"","sources":["../src/units.ts"],"names":[],"mappings":"AAUA,MAAM,cAAc,GAAgC;IAClD,WAAW,EAAE,KAAK;IAClB,GAAG,EAAE,KAAK;IACV,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,KAAK;IACZ,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,KAAK;IACd,WAAW,EAAE,GAAG;CACjB,CAAC;AAEF,MAAM,qBAAqB,GAA2B;IACpD,GAAG,EAAE;QACH,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,IAAI;QACT,EAAE,EAAE,KAAK;QACT,EAAE,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,GAAG,GAAG;QACxB,GAAG,EAAE,CAAC,MAAM,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,GAAG;QAClC,GAAG,EAAE,CAAC,IAAI,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,GAAG;KACjC;IACD,EAAE,EAAE;QACF,EAAE,EAAE,CAAC;QACL,CAAC,EAAE,KAAK;KACT;IACD,CAAC,EAAE;QACD,CAAC,EAAE,CAAC;KACL;IACD,EAAE,EAAE;QACF,EAAE,EAAE,CAAC;QACL,GAAG,EAAE,UAAU;QACf,MAAM,EAAE,IAAI;KACb;IACD,MAAM,EAAE;QACN,MAAM,EAAE,CAAC;KACV;CACF,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,IAAI,CAAC,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,gBAAgB,IAAI,mBAAmB,CAAC,CAAC;IAExE,MAAM,cAAc,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QACtC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC;QAChC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,IAAI,YAAY,IAAI,QAAQ,CAAC;QAClE,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,GAAG,oBAAoB,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,MAAM,CAAC;QACnF,OAAO,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;IAC7D,CAAC,CAAC,CAAC;IAEH,OAAO,cAAc,CAAC;AACxB,CAAC,CAAC;AAEF,MAAM,oBAAoB,GAAG,CAAC,WAAmB,KAAK,EAAE,MAAc,EAAE,EAAE;IACxE,MAAM,iBAAiB,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAExD,IAAI,CAAC,iBAAiB,EAAE;QACtB,MAAM,IAAI,KAAK,CAAC,+BAA+B,MAAM,iBAAiB,CAAC,CAAC;KACzE;IAED,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE;QAChC,MAAM,IAAI,KAAK,CAAC,+BAA+B,QAAQ,iBAAiB,CAAC,CAAC;KAC3E;IAED,OAAO,iBAAiB,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF,eAAe;IACb,YAAY;CACb,CAAC"}
|
package/package.json
CHANGED
package/src/units.ts
CHANGED
|
@@ -47,7 +47,7 @@ const unitConversionFactors: { [key: string]: any } = {
|
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
// Convert units to base format
|
|
50
|
-
export const convertItems = (items: Item[], type: AccountType) => {
|
|
50
|
+
export const convertItems = (items: Item[], type: AccountType, defaultUnits: ETNUnit | undefined) => {
|
|
51
51
|
if (!type) throw new Error('Account type is required');
|
|
52
52
|
|
|
53
53
|
const baseUnit = accountTypeMap[type];
|
|
@@ -55,7 +55,7 @@ export const convertItems = (items: Item[], type: AccountType) => {
|
|
|
55
55
|
|
|
56
56
|
const convertedItems = items.map(item => {
|
|
57
57
|
const factor = item.factor || 1;
|
|
58
|
-
const units = item.units || item.unit || baseUnit;
|
|
58
|
+
const units = item.units || item.unit || defaultUnits || baseUnit;
|
|
59
59
|
const convertedValue = item.value * _getConversionFactor(units, baseUnit) * factor;
|
|
60
60
|
return { ...item, value: convertedValue, units: baseUnit };
|
|
61
61
|
});
|