blob: 2d0170bd927b91f6e7a1800fdaf05f6f28e1eca0 [file] [log] [blame]
const HUNDRED_PERCENT = { isDynamic: true, multiplier: 1 } as const;
export default function parseLength(
input: string | number,
): { isDynamic: true; multiplier: number } | { isDynamic: false; value: number } {
if (input === 'auto' || input === '100%') {
return HUNDRED_PERCENT;
}
if (typeof input === 'string' && input.length > 0 && input[input.length - 1] === '%') {
return { isDynamic: true, multiplier: parseFloat(input) / 100 };
}
const value = typeof input === 'number' ? input : parseFloat(input);
return { isDynamic: false, value };
}