From e01ddbf82d441d80d78b8e3ec6d1ff2cce9a88c7 Mon Sep 17 00:00:00 2001 From: John Grishin Date: Mon, 21 Jan 2019 02:16:53 +0300 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Improve=20`splitUnit`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/index.js b/src/utils/index.js index 45e2843..2091545 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -28,11 +28,11 @@ export const wrapIfMedia = (query, style) => wrap( style ) -const parseUnit = (str) => str.replace(/([\d.]+)(\D+)?$/, '$2').trim() +const parseUnit = (str) => str.replace(/([\d.]+)(\D+)?$/, '$2').trim() || undefined export const splitUnit = (input) => isStr(input) - ? [ parseFloat(input, 10), parseUnit(input) || undefined ] - : [ input, undefined ] + ? [ parseFloat(input, 10), parseUnit(input) ] + : (isNum(input) ? [ input, undefined ] : []) export const floor = (number, precision = 0) => { const factor = Math.pow(10, precision)