Socket
Socket
Sign inDemoInstall

to-style

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    to-style

Convert style objects to style strings


Version published
Weekly downloads
20K
decreased by-30.64%
Maintainers
1
Install size
90.3 kB
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 22 Jan 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc