
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Generate CSS from a JavaScript Object
This module does not convert property names to their dasherized counterparts, this is just a plain object to CSS stringification, though see property and value options below.
Install to-css using npm:
npm install --save to-css
var toCss = require('to-css');
toCss({body: {'font-size': '10px'}}, {indent: ' '});
/**
* body {
* font-size: 10px;
* }
*/
Sometimes you want to have a CSS declaration with the same property specified multiple times with different values, for fallback values. You can use arrays for that, e.g:
var toCss = require('to-css');
toCss({body: {color: ['rgba(0,0,0,.5)', 'black']}}, {indent: ' '});
/**
* body {
* color: rgba(0,0,0,.5);
* color: black;
* }
*/
@font-faceDefining multiple @font-face's can be done using arrays like this:
var toCss = require('to-css');
toCss({
'@font-face': [
{'font-family': '"MyWebFont"', src: 'url("myfont.woff2") format("woff2"), url("myfont.woff") format("woff")'},
{'font-family': 'MyOtherFont', src: 'url("otherfont.woff2") format("woff2"), url("otherfont.woff") format("woff")'}
]
});
/**
* @font-face {
* font-family: "MyWebFont";
* src: url("myfont.woff2") format("woff2"), url("myfont.woff") format("woff");
* }
* @font-face {
* font-family: "MyOtherFont";
* src: url("otherfont.woff2") format("woff2"), url("otherfont.woff") format("woff");
* }
*/
Or like this:
var toCss = require('to-css');
toCss([
{
'@font-face': {
'font-family': '"MyWebFont"',
src: 'url("myfont.woff2") format("woff2"), url("myfont.woff") format("woff")'
}
},
{
'@font-face': {
'font-family': 'MyOtherFont',
src: 'url("otherfont.woff2") format("woff2"), url("otherfont.woff") format("woff")'
}
}
]);
/**
* @font-face {
* font-family: "MyWebFont";
* src: url("myfont.woff2") format("woff2"), url("myfont.woff") format("woff");
* }
* @font-face {
* font-family: "MyOtherFont";
* src: url("otherfont.woff2") format("woff2"), url("otherfont.woff") format("woff");
* }
*/
toCss(object [, options])| Name | Type | Description |
|---|---|---|
| object | `Object | Array` |
| options | Object | Options |
Returns: String, the generated CSS string.
options.indentType: String|Number
Default: ""
Works like JSON.stringify's space parameter. I.e. if it's a number it indicates the number of spaces to use as white space, and if it's a string the string itself is used as white space. When empty (or NULL) no white space is used.
options.valueType: Function
Default: NOOP
A transform function for property values, gets called for each CSS rule with value and property as params: options.value(value, property). Can return a String or an array of strings!
options.propertyType: Function
Default: NOOP
A transform function for property names, gets called for each CSS rule with property and value as params: options.property(property, value). Can return a String or an array of strings!
options.selectorType: Function
Default: NOOP
A transform function for selectors, gets called for each CSS declaration with selector and declaration object as params: options.selector(selector, declaration). Can return a String or an array of strings!
MIT © Joakim Carlstein
FAQs
Generate CSS from a JavaScript Object
We found that to-css demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.