Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

Commit

Permalink
fix: address Kim's comment
Browse files Browse the repository at this point in the history
  • Loading branch information
kristw committed Jun 12, 2019
1 parent db44a97 commit 5408178
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions packages/superset-ui-dimension/src/parseLength.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
const HUNDRED_PERCENT = { isDynamic: true, multiplier: 1 } as const;

const pxPattern = /px$/;

export default function parseLength(
input: string | number,
): { isDynamic: true; multiplier: number } | { isDynamic: false; value: number } {
if (input === 'auto' || input === '100%') {
return HUNDRED_PERCENT;
} else if (typeof input === 'string' && input.length > 0 && input[input.length - 1] === '%') {
// eslint-disable-next-line no-magic-numbers
return { isDynamic: true, multiplier: parseFloat(input.substring(0, input.length - 1)) / 100 };
return { isDynamic: true, multiplier: parseFloat(input) / 100 };
}
const value = typeof input === 'number' ? input : parseFloat(input.replace(pxPattern, ''));
const value = typeof input === 'number' ? input : parseFloat(input);

return { isDynamic: false, value };
}

0 comments on commit 5408178

Please sign in to comment.