https://github.com/smallhelm/css-to-css.js
Compile css into js code that injects styles on the browser and is safe to run on the server.
https://github.com/smallhelm/css-to-css.js
Last synced: 7 months ago
JSON representation
Compile css into js code that injects styles on the browser and is safe to run on the server.
- Host: GitHub
- URL: https://github.com/smallhelm/css-to-css.js
- Owner: smallhelm
- License: mit
- Created: 2015-10-12T14:09:50.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-10-12T16:41:33.000Z (over 10 years ago)
- Last Synced: 2025-01-11T01:56:14.878Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 141 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# css-to-css.js
Compile css into js code that injects styles on the browser and is safe to run on the server.
## How to use it
```js
var cssToCssJs = require("css-to-css.js");
var js = cssToCssJs("body {color: blue;}");
```
Which returns
```js
(function(e){if("undefined"==typeof document)return e;var t=document,n="CSS_TO_CSSJS";if(t[n]=t[n]||{},!t[n][e]){t[n][e]=!0;var r=t.createElement("style");return r.setAttribute("type","text/css"),"textContent"in r?r.textContent=e:r.styleSheet.cssText=e,t.getElementsByTagName("head")[0].appendChild(r),e}})("body {color: blue;}");
```
When you execute that javascript:
In the browser
* injects the css into the ``
* returns the css code as a string
On the server
* returns the css code as a string
Typically you save the javascript to a file then you can `require` it using browserify/node.
## Install
```sh
$ npm install --save css-to-css.js
```
## License
MIT