parse-size-with-unit
A helper to parse 'size like' value into a valid size with unit.
Install
yarn add @lawrence_ch/parse-size-with-unit
# or
npm install --save @lawrence_ch/parse-size-with-unit
Usage
import parseSize from '@lawrence_ch/parse-size-with-unit'
parseSize(50) // '50px'
parseSize('50') // '50px'
parseSize('50px') // '50px'
parseSize('50%') // '50%'
parseSize('50.5px') // '50.5px'
parseSize('50.5%') // '50.5%'
parseSize('a') // null
// Default unit. Supports all CSS valid unit.
parseSize(50, 'em') // '50em'