Skip to content

Add default unit to css numeric-like values, which have to specify an unit.

Notifications You must be signed in to change notification settings

cssobj/cssobj-plugin-default-unit

Repository files navigation

cssobj-plugin-default-unit

Join the chat at https://gitter.im/css-in-js/cssobj Build Status

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.

About

Add default unit to css numeric-like values, which have to specify an unit.

Resources

Stars

Watchers

Forks

Packages

No packages published