Skip to content

Commit

Permalink
Merge pull request #817 from gympass/DS-844
Browse files Browse the repository at this point in the history
🚀 feat(system): add types to unit file
  • Loading branch information
evilamaior authored May 29, 2024
2 parents 20153cb + e7c1ed2 commit 2fe1995
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
7 changes: 0 additions & 7 deletions packages/system/src/unit.js

This file was deleted.

22 changes: 22 additions & 0 deletions packages/system/src/unit.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
});
7 changes: 7 additions & 0 deletions packages/system/src/unit.ts
Original file line number Diff line number Diff line change
@@ -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 };

0 comments on commit 2fe1995

Please sign in to comment.