-
Notifications
You must be signed in to change notification settings - Fork 1
/
SimpleBaseUnit.ts
34 lines (30 loc) · 1.04 KB
/
SimpleBaseUnit.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* This file is part of Measurement Toolkit
*
* (c) Bas Peeters <bas@peete.rs>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import {IBaseUnit} from "./IBaseUnit";
import {ISimpleUnit} from "./ISimpleUnit";
import {SimpleUnit} from "./SimpleUnit";
export abstract class SimpleBaseUnit extends SimpleUnit implements ISimpleUnit, IBaseUnit {
public derivedUnits = {};
public getConverters(): { [key: string]: () => ISimpleUnit } {
for (const converter of Object.keys(this.converters)) {
const unit = this.converters[converter]();
if ("derivedUnits" in unit) {
// @ts-ignore
for (const derivedUnit of Object.keys(unit.derivedUnits)) {
// @ts-ignore
this.converters[derivedUnit] = unit.derivedUnits[derivedUnit];
}
}
}
return {
...super.getConverters(),
...this.derivedUnits,
};
}
}