1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/utils/convertCpu.ts
Panu Horsmalahti dcf253e7d5
Add eslint rule padding-line-between-statements (#1593)
Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
2020-12-02 09:55:52 +02:00

16 lines
415 B
TypeScript

// Helper to convert CPU K8S units to numbers
const thousand = 1000;
const million = thousand * thousand;
const shortBillion = thousand * million;
export function cpuUnitsToNumber(cpu: string) {
const cpuNum = parseInt(cpu);
if (cpu.includes("m")) return cpuNum / thousand;
if (cpu.includes("u")) return cpuNum / million;
if (cpu.includes("n")) return cpuNum / shortBillion;
return parseFloat(cpu);
}