mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Use parseFloat
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
e308e8f963
commit
8b34be0aea
@ -20,7 +20,7 @@ const unitConverters = new Map([
|
|||||||
["E", 1000 ** 6],
|
["E", 1000 ** 6],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const cpuUnitsRegex = TypedRegEx("^(?<digits>\\d+)(?<unit>.*)$");
|
const cpuUnitsRegex = TypedRegEx("^(?<digits>[+-]?[0-9.]+(e[-+]?[0-9]+)?)(?<unit>[EinumkKMGTP]*)$");
|
||||||
|
|
||||||
export function cpuUnitsToNumber(value: string) {
|
export function cpuUnitsToNumber(value: string) {
|
||||||
const match = cpuUnitsRegex.captures(value);
|
const match = cpuUnitsRegex.captures(value);
|
||||||
@ -29,12 +29,12 @@ export function cpuUnitsToNumber(value: string) {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { digits, unit } = match;
|
const { digits = "", unit } = match;
|
||||||
const conversion = unitConverters.get(unit);
|
const conversion = unitConverters.get(unit);
|
||||||
|
|
||||||
if (conversion === undefined) {
|
if (conversion === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parseInt(digits) * conversion;
|
return parseFloat(digits) * conversion;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user