Skip to content
This repository has been archived by the owner on Jul 4, 2019. It is now read-only.

Latest commit

 

History

History
55 lines (44 loc) · 813 Bytes

README.md

File metadata and controls

55 lines (44 loc) · 813 Bytes

css-to-object

Convert flat CSS rules to JavaScript style objects

Useful for css-in-js libraries

npm i css-to-object
const cssToObject = require('css-to-object')

const style = cssToObject(`
  color: tomato;
  padding: 16px;
  @media (min-width: 40em) {
    paddingLeft: 32px;
    paddingRight: 32px;
  }
  &:hover: {
    color: black;
  }
  & h1 {
    font-size: 48px;
  }
`, {
  camelCase: true,
  numbers: true
})

// {
//   color: 'tomato',
//   padding: 16,
//   '@media (min-width: 40em)': {
//     paddingLeft: 32,
//     paddingRight: 32,
//   },
//   ':hover': {
//     color: 'black'
//   },
//   h1: {
//     fontSize: 48
//   }
// }

Options

  • numbers: Converts px values to numbers
  • camelCase: converts CSS properties to camelCased keys

MIT License