项目作者: dan-lee

项目描述 :
Easily convert CSS declarations to JavaScript inline styles
高级语言: JavaScript
项目地址: git://github.com/dan-lee/css2js.git
创建时间: 2017-04-03T19:43:49Z
项目社区:https://github.com/dan-lee/css2js

开源协议:

下载


CSS to JavaScript style

About

I created this tool for projects, where I’d constantly write CSS and then convert it into object literals for glamor, inline styles or other css-in-js libraries.

Example GIF

It takes following things into account:

  • Unitless values (opacity, line-height, font-weight, …)
  • Vendor prefixed values
  • Escaping different quotes in a single value (e.g. in font-family)
  • Not-enclosed CSS declarations (i.e. without selector) for fast copy & paste

Online version

Simply copy & paste the styles you want to convert.

Example input

  1. width: 600px;
  2. min-height: 100vh;
  3. font-weight: 800;
  4. color: #bada55;
  5. opacity: .5;
  6. -webkit-font-smoothing: antialiased;
  7. font-family: "Roboto", 'Open Sans';

(For convenience this works without selectors)

Example output

  1. {
  2. width: 600,
  3. minHeight: '100vh',
  4. fontWeight: 800,
  5. color: '#bada55',
  6. opacity: .5,
  7. WebkitFontSmoothing: 'antialiased',
  8. fontFamily: '"Roboto", \'Open Sans\''
  9. }

^ This is with disabled px output (helpful for React projects)

Check it out by yourself