diff --git a/packages/system/src/unit.js b/packages/system/src/unit.js deleted file mode 100644 index 91d8a147c3..0000000000 --- a/packages/system/src/unit.js +++ /dev/null @@ -1,7 +0,0 @@ -const toUnit = (unit = 'px') => { - return value => (Number(value) && value !== 0 ? `${value}${unit}` : value); -}; - -const toPx = toUnit('px'); - -export { toUnit, toPx }; diff --git a/packages/system/src/unit.test.ts b/packages/system/src/unit.test.ts new file mode 100644 index 0000000000..65dd5f0032 --- /dev/null +++ b/packages/system/src/unit.test.ts @@ -0,0 +1,22 @@ +import { toPx } from './unit'; + +describe('Unit', () => { + describe('toPx', () => { + it('should add "px" to the number', () => { + expect(toPx(10)).toBe('10px'); + }); + + it('should return 0 without adding unit', () => { + expect(toPx(0)).toBe(0); + }); + + it('should return a numeric string with "px"', () => { + expect(toPx('20')).toBe('20px'); + }); + + it('should add "px" to a decimal numeric string or number', () => { + expect(toPx(0.5)).toBe('0.5px'); + expect(toPx('0.5')).toBe('0.5px'); + }); + }); +}); diff --git a/packages/system/src/unit.ts b/packages/system/src/unit.ts new file mode 100644 index 0000000000..4ac5ff4eb9 --- /dev/null +++ b/packages/system/src/unit.ts @@ -0,0 +1,7 @@ +const toUnit = (unit = 'px') => + (value: string | number) => + Number(value) && value !== 0 ? `${value}${unit}` : value; + +const toPx = toUnit('px'); + +export { toUnit, toPx };