cssobj-plugin-default-unit
v2.3.4
Published
Add default unit to cssobj numeric
Downloads
20
Readme
cssobj-plugin-default-unit
Add default unit to css numeric-like values, which have to specify an unit.
Install
npm install cssobj/cssobj-plugin-default-unit
Usage
var cssobj_core = require('cssobj-core')
var defaultUnit = require('cssobj-plugin-default-unit')
var cssobj = cssobj_core({plugins: [ defaultUnit('px') ]})
var obj = { p: { fontSize: 12 } }
var result = cssobj(obj)
// the css: p {font-size: 12px;}
API
var plugin = defaultUnit(unit)
Get plugin function to apply, pass unit.
PARAMS
unit
- Type: string
- Default: 'px'
The unit as default unit to add to numeric-like values, accordingly to Unitless List
RETURN
A function can be as cssobj plugin.
Example
defaultUnit() // default unit is 'px'
defaultUnit('em') // default unit is 'em'
Caveat
line-height
will NOT add unit, since below:
p { lineHeight: 1.5 }
p { lineHeight: '22px' }
It's both valid with or w/o unit, so this plugin don't touch it.