https://github.com/cssobj/cssobj-converter
Convert from CSS to CSSOBJ.
https://github.com/cssobj/cssobj-converter
Last synced: about 1 year ago
JSON representation
Convert from CSS to CSSOBJ.
- Host: GitHub
- URL: https://github.com/cssobj/cssobj-converter
- Owner: cssobj
- Created: 2016-07-14T21:37:25.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2023-01-11T18:51:58.000Z (over 3 years ago)
- Last Synced: 2025-04-23T09:58:30.037Z (about 1 year ago)
- Language: JavaScript
- Homepage: http://convertcssobj-futurist.rhcloud.com/
- Size: 393 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# CSSOBJ Converter
[](https://gitter.im/css-in-js/cssobj) [](https://travis-ci.org/cssobj/cssobj-converter)
Convert from normal css/LESS/SASS/SCSS to [cssobj](https://github.com/cssobj/cssobj).
The online version is below:
http://convertcssobj-futurist.rhcloud.com/
( Currently using [OpenShift](https://www.openshift.com/) free hosting for nodejs backend, it will sleep for some idle time.
If you cannot open the page, try again after few seconds, it will wake up.
Someone can help with this? Or provide a node js hosting? )
## CLI
### Install
``` javascript
npm install -g cssobj-converter
```
### Usage
``` bash
cssobj [option] [cssfile]
```
### Option
option | short | description
---|---|---
--output | -o | output file name(.js file)
--pretty | -p | pretty format output js object **default: true**
--css | -c | css code from command line
--format | -f | supported: css,less,js. If **js** then convert from cssobj into css. **default: css**
--watch | -w | watch [dir] for changes **default: false**
--recursive | -r | recursive convert all [css/less] files in [dir]; **default: false**
--keepVendor | -k | keep vendor prefix for css props
--nameStore | -n | export nameStore as `classes`/`ids`, and js object as `obj`
If no `cssfile` and no `-c`, then cssobj will read from **STDIN**.
### Example
``` bash
#read from stdin, (Ctrl+D) to convert
cssobj
#convert abc.css into cssobj, output to stdout
cssobj abc.css
#convert abc.css into cssobj, output to abc.js
cssobj abc.css -o abc.js
#convert abc.js into css then output
cssobj -c '{p:{color: "red"}}' -f js
cssobj abc.js -f js
#convert abc.css into cssobj, output to abc.js, without pretty format
cssobj abc.css -o abc.js -p false
#convert less
cssobj abc.less -f less -o abc.js
cssobj abc.less -o abc.js #same as above
#convert css in command line
cssobj -c "p{ color:red; }"
# all files in folder convert to .js
cssobj ./abc
# convert all files in folder and watch
cssobj ./abc -w
# convert all files in folder and watch, result as {obj, ids, classes}
cssobj ./abc -wn
```
## NodeJS
### Install
``` bash
npm install -S cssobj-converter
```
### Usage
``` javascript
var converter = require('cssobj-converter')
console.log( converter('p { color: red; }') )
```
## Server
From the lib folder, `npm i` then run below script:
``` bash
npm run server
```
Service URL: `http://localhost:8080`
Accept `POST` json data as below:
``` bash
curl -d '{ "text" : "p {color:red;}" }' localhost:8080
```