├── .gitignore ├── README.md ├── package.json └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Convert a JS object to CSS string. Similar to React's output of CSS, extracted into a module. 2 | 3 | Only difference is it adds px to 0 values, which is ok in CSS. -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "object-to-css", 3 | "version": "1.0.4", 4 | "description": "Convert a JS object to CSS string. Similar to React's output of CSS, extracted into a module.", 5 | "main": "index.js", 6 | "scripts": {}, 7 | "author": "Nate Wienert", 8 | "license": "MIT", 9 | "dependencies": { 10 | "add-px-to-style": "^1.0.0", 11 | "hyphenate-style-name": "^1.0.0" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var addPx = require('add-px-to-style') 2 | var hyphenate = require('hyphenate-style-name') 3 | 4 | module.exports = function createMarkup(obj) { 5 | var keys = Object.keys(obj) 6 | if (!keys.length) return '' 7 | var i, len = keys.length 8 | var result = '' 9 | 10 | for (i = 0; i < len; i++) { 11 | var key = keys[i] 12 | var val = obj[key] 13 | result += hyphenate(key) + ':' + addPx(key, val) + ';' 14 | } 15 | 16 | return result 17 | } --------------------------------------------------------------------------------