Skip to content

Commit

Permalink
toRem: Bypasses value transformations for string type values
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed May 29, 2018
1 parent 01dbee3 commit fae4c69
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/utils/toRem.js
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}`
}
6 changes: 5 additions & 1 deletion src/utils/toRem.test.js
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')
})

0 comments on commit fae4c69

Please sign in to comment.