@etainabl/nodejs-sdk 1.1.25 → 1.1.26
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 +4 -4
- 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
|
@@ -5,16 +5,16 @@ interface Item {
|
|
|
5
5
|
value: number;
|
|
6
6
|
[key: string]: any;
|
|
7
7
|
}
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
8
|
+
export type AccountType = 'electricity' | 'gas' | 'water' | 'waste' | 'solar' | 'heating' | 'flow' | 'cooling' | 'temperature' | 'other';
|
|
9
|
+
export type ETNUnit = 'kwh' | 'kg' | 'm3' | 'lbs' | 'tonnes' | 'wh' | 'mwh' | 'ft3' | 'hcf' | 'm3/h' | 'qty' | 'l' | 'C';
|
|
10
|
+
export type BaseUnit = 'kwh' | 'm3' | 'C' | 'kg' | 'm3/h';
|
|
11
11
|
export declare const accountTypeMap: {
|
|
12
12
|
[key: string]: BaseUnit;
|
|
13
13
|
};
|
|
14
14
|
export declare const accountTypeUnitMap: {
|
|
15
15
|
[key: string]: ETNUnit[];
|
|
16
16
|
};
|
|
17
|
-
export declare const convertItems: (items: Item[], type: AccountType, defaultUnits: ETNUnit | undefined) => any;
|
|
17
|
+
export declare const convertItems: (items: Item[], type: AccountType, defaultUnits: ETNUnit | undefined, accountFactor: number | undefined) => any;
|
|
18
18
|
export declare const checkAccountTypeVsUnits: (type: string, unit: string, additionalLog?: number | '') => {
|
|
19
19
|
type: AccountType;
|
|
20
20
|
unit: ETNUnit;
|
package/dist/units.js
CHANGED
|
@@ -46,14 +46,14 @@ export const accountTypeUnitMap = {
|
|
|
46
46
|
temperature: ['C']
|
|
47
47
|
};
|
|
48
48
|
// Convert units to base format
|
|
49
|
-
export const convertItems = (items, type, defaultUnits) => {
|
|
49
|
+
export const convertItems = (items, type, defaultUnits, accountFactor) => {
|
|
50
50
|
if (!type)
|
|
51
51
|
throw new Error('Account type is required');
|
|
52
52
|
const baseUnit = accountTypeMap[type];
|
|
53
53
|
if (!baseUnit)
|
|
54
54
|
throw new Error(`Account type ${type} is not supported`);
|
|
55
55
|
const convertedItems = items.map(item => {
|
|
56
|
-
const factor = item.factor || 1;
|
|
56
|
+
const factor = item.factor || accountFactor || 1;
|
|
57
57
|
const units = item.units || item.unit || defaultUnits || baseUnit;
|
|
58
58
|
const convertedValue = item.value * _getConversionFactor(units, baseUnit) * factor;
|
|
59
59
|
return { ...item, value: convertedValue, units: baseUnit };
|
package/dist/units.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"units.js","sourceRoot":"","sources":["../src/units.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,MAAM,cAAc,GAAgC;IACzD,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,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KAAK,CAAC,kBAAkB,CAAC,CAAC;IAE/C,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC;IAE7C,MAAM,gBAAgB,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;IACxD,IAAI,CAAC,gBAAgB;QAAE,MAAM,IAAI,KAAK,CAAC,iBAAiB,UAAU,sBAAsB,aAAa,EAAE,CAAC,CAAC;IAEzG,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,EAAa,CAAC;IAExD,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;QAC1C,MAAM,IAAI,KAAK,CAAC,iBAAiB,UAAU,4BAA4B,UAAU,KAAK,aAAa,EAAE,CAAC,CAAC;KACxG;IAED,OAAO,EAAE,IAAI,EAAE,UAAyB,EAAE,IAAI,EAAE,UAAU,EAAC,CAAC;AAC9D,CAAC,CAAC"}
|
package/package.json
CHANGED
package/src/units.ts
CHANGED
|
@@ -60,14 +60,14 @@ export const accountTypeUnitMap: { [key: string]: ETNUnit[] } = {
|
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
// Convert units to base format
|
|
63
|
-
export const convertItems = (items: Item[], type: AccountType, defaultUnits: ETNUnit | undefined): any => {
|
|
63
|
+
export const convertItems = (items: Item[], type: AccountType, defaultUnits: ETNUnit | undefined, accountFactor: number | undefined): any => {
|
|
64
64
|
if (!type) throw new Error('Account type is required');
|
|
65
65
|
|
|
66
66
|
const baseUnit = accountTypeMap[type];
|
|
67
67
|
if (!baseUnit) throw new Error(`Account type ${type} is not supported`);
|
|
68
68
|
|
|
69
69
|
const convertedItems = items.map(item => {
|
|
70
|
-
const factor = item.factor || 1;
|
|
70
|
+
const factor = item.factor || accountFactor || 1;
|
|
71
71
|
const units = item.units || item.unit || defaultUnits || baseUnit;
|
|
72
72
|
const convertedValue = item.value * _getConversionFactor(units, baseUnit) * factor;
|
|
73
73
|
return { ...item, value: convertedValue, units: baseUnit };
|