From e37f1e67d3b7e918a83f8de5b341555da5a6ca06 Mon Sep 17 00:00:00 2001 From: Callum Whyte Date: Fri, 29 Oct 2021 20:38:02 +0000 Subject: [PATCH 1/2] Defaulting to 0 for toInt and toFloat --- src/utils/unit.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/utils/unit.js b/src/utils/unit.js index 3c90e70e..c33a687e 100644 --- a/src/utils/unit.js +++ b/src/utils/unit.js @@ -6,7 +6,7 @@ * @returns {Number} */ export function toInt (value) { - return parseInt(value) + return parseInt(value) || 0 } /** @@ -17,7 +17,7 @@ export function toInt (value) { * @returns {Number} */ export function toFloat (value) { - return parseFloat(value) + return parseFloat(value) || 0 } /** @@ -40,7 +40,6 @@ export function isString (value) { */ export function isObject (value) { let type = typeof value - return type === 'function' || type === 'object' && !!value // eslint-disable-line no-mixed-operators } From 96dfa72075ae78e17debaa51264d24c302a64991 Mon Sep 17 00:00:00 2001 From: Callum Whyte Date: Fri, 29 Oct 2021 20:38:27 +0000 Subject: [PATCH 2/2] Updating tests around toInt --- tests/unit/unit.test.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/unit/unit.test.js b/tests/unit/unit.test.js index db11129c..e1270fe9 100644 --- a/tests/unit/unit.test.js +++ b/tests/unit/unit.test.js @@ -9,10 +9,11 @@ import { } from '../../src/utils/unit' describe('Function', () => { - test('`toInt` should covert entered value in various formats to actual width number', () => { - expect(toInt(1, 100)).toBe(1) - expect(toInt('1', 100)).toBe(1) - expect(toInt('1px', 100)).toBe(1) + test('`toInt` should covert entered value in various formats to actual number', () => { + expect(toInt(1)).toBe(1) + expect(toInt('1')).toBe(1) + expect(toInt('1px')).toBe(1) + expect(toInt(null)).toBe(0) }) test('`isString` return `true` on valid string', () => {