https://github.com/richardlitt/inline-style-2-json
Convert CSS inline stlyes to JSON
https://github.com/richardlitt/inline-style-2-json
css json stringify
Last synced: 4 months ago
JSON representation
Convert CSS inline stlyes to JSON
- Host: GitHub
- URL: https://github.com/richardlitt/inline-style-2-json
- Owner: RichardLitt
- License: mit
- Created: 2015-10-01T17:13:01.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-05-23T12:07:01.000Z (about 6 years ago)
- Last Synced: 2025-04-14T20:19:16.165Z (about 1 year ago)
- Topics: css, json, stringify
- Language: JavaScript
- Size: 598 KB
- Stars: 9
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
- License: license
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# inline-style-2-json
[](https://greenkeeper.io/)
[](https://travis-ci.org/RichardLitt/inline-style-2-json)
> Convert CSS inline styles to JSON
This is a small function that takes the content of a `style` tag (as a string) and outputs an object or a JSON string. This is useful if you are piping HTML through [xml-objects](https://github.com/timhudson/xml-objects) or something similar and you want finer granularity.
## Install
```
$ npm install --save inline-style-2-json
```
## Usage
```js
var inlineStyle2Json = require('inline-style-2-json');
inlineStyle2Json('position:absolute;h-index:9001;');
//=> "{ position: 'absolute', 'h-index': '9001'}"
inlineStyle2Json('position:absolute;h-index:9001;', {stringify: true});
//=> '{"position":"absolute","h-index":"9001"}'
```
## API
### inlineStyle2Json(input, [options])
#### input
Type: `string`
This should be your inline style string.
#### options
##### stringify
Type: `boolean`
Default: `false`
Return stringified object.
## Contribute
Sure! Open an issue, open a PR.
## License
[MIT](license) © 2018 [Richard Littauer](http://burntfen.com)