7
mirror of https://github.com/EEVengers/ThunderScope.git synced 2025-04-08 06:25:30 +00:00

Add convert.ts

This commit is contained in:
Ratan Varghese 2021-03-22 02:14:03 -04:00
parent 20b898c08b
commit cee643ad5e

View File

@ -0,0 +1,24 @@
import VoltageUnit from '../configuration/enums/voltageUnit';
import TimeUnit from '../configuration/enums/timeUnit';
function convertVoltage(x: number, from: VoltageUnit, to: VoltageUnit) {
let power = {
[VoltageUnit.NanoVolt]: -9,
[VoltageUnit.MicroVolt]: -6,
[VoltageUnit.MilliVolt]: -3,
[VoltageUnit.Volt]: 0
}
return x * Math.pow(10, power[from] - power[to]);
}
function convertTime(x: number, from: TimeUnit, to: TimeUnit) {
let power = {
[TimeUnit.NanoSecond]: -9,
[TimeUnit.MicroSecond]: -6,
[TimeUnit.MilliSecond]: -3,
[TimeUnit.Second]: 0
}
return x * Math.pow(10, power[from] - power[to]);
}
export {convertVoltage, convertTime}