1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/dashboard/client/utils/convertCpu.ts
Sebastian Malton b1ff34879a cleanup Lens repo with tighter linting
Signed-off-by: Sebastian Malton <smalton@mirantis.com>
2020-07-09 17:00:23 -04:00

16 lines
373 B
TypeScript

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