Use style-to-js
to parse a CSS inline style to a JavaScript object that’s camelCased.
Install
npm install style-to-js
Usage
Parse:
const styleToJS = require('style-to-js').default;
styleToJS('background-color: #BADA55');
Output:
{ "backgroundColor": "#BADA55" }
To support React, enable the option reactCompat
:
styleToJS('-webkit-transition: all 4s ease', { reactCompat: true });
Output:
{ "WebkitTransition": "all 4s ease" }
See README.
Demo
Misc
Use style-to-object
to parse a CSS inline style to a JavaScript object that’s kebab-cased.
npm install style-to-object
Parse:
const styleToObject = require('style-to-object');
styleToObject('background-color: #BADA55');
Output:
{ "background-color": "#BADA55" }
See README.