JSPM

css-to-object

1.1.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 4017
    • Score
      100M100P100Q116044F
    • License MIT

    Convert flat CSS rule to JavaScript style object

    Package Exports

    • css-to-object

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (css-to-object) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    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