-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
toRem: Bypasses value transformations for string type values
- Loading branch information
1 parent
01dbee3
commit fae4c69
Showing
2 changed files
with
16 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
export default function toRem(num) { | ||
return num && `${num}rem` | ||
/** | ||
* @param {Number|String|null} value | ||
*/ | ||
export default function toRem(value) { | ||
if (!value) { | ||
return | ||
} | ||
|
||
const suffix = Number.isInteger(value) ? 'rem' : '' | ||
|
||
return `${value}${suffix}` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
import { expect } from 'chai' | ||
import toRem from './toRem' | ||
|
||
test('converts to rem value properly', () => { | ||
test('Suffixes numeric values with "rem" string', () => { | ||
expect(toRem(5)).to.equal('5rem') | ||
}) | ||
|
||
test('Returns string values as is', () => { | ||
expect(toRem('2vh')).to.equal('2vh') | ||
}) |