GitXplorerGitXplorer
r

toStyle

public
17 stars
4 forks
4 issues

Commits

List of commits on branch master.
Unverified
fb1cf7eb32bc504d67faab4968e765460a007726

Merge pull request #1 from apalm/patch-1

rradubrehar committed 8 years ago
Unverified
8d447a2abeffe2ecf91cd0bac4f9ebbf5139b729

Actually make order unitless

aapalm committed 9 years ago
Unverified
43e38cfbfb361091f916666954a501669997da15

1.3.3

rradubrehar committed 10 years ago
Unverified
25ab7cb81499a20341071625a7c4759367fe1e09

fix

rradubrehar committed 10 years ago
Unverified
c3c3e35b1f07619453e0f797b6af173694588829

1.3.2

rradubrehar committed 10 years ago
Unverified
87f6c1b7d5ab860fa56a4804a02a4755a368ea3e

remove ustring dependency

rradubrehar committed 10 years ago

README

The README file for this repository.

toStyle

Converts style objects to strings. Can be used on node or in the browser.

Install

npm install to-style

Usage

var toStyleString = require('to-style').string
var toStyleObject = require('to-style').object

toStyleString

toStyleString({
    border: {
        width: 1,
        color: 'red'
    },
    padding: 4,
    margin: {
        top: 5
    }
}) == 'border-width: 1px; border-color: red; padding: 4px; margin-top: 5px;'

toStyleObject

toStyleObject({
    padding: {
        top: 3,
        bottom: 2
    },
    border: '1px solid red',
    margin: 4
}) // =>
/*
{
    'padding-top': '3px',
    'padding-bottom': '2px',
    'border': '1px solid red',
    'margin': '4px'
}
 */

You can also get your styles in camel-case, just pass a config object as a second argument to toStyleObject, with camelize: true

Example:

toStyleObject({
    padding: {
        top: 10
    },
    'border-width': 20
}, { camelize: true})

/**
 *  {
 *      paddingTop: '10px',
 *      borderWidth: '20px'
 *  }
 */

Usage in browser

In browser, make sure you add dist/toStyle.js to your page. This exposes a global toStyle variable.

var toStyleString = toStyle.string
var toStyleObject = toStyle.object