$ npm install happy-style
CSS to JS AST parser.
npm i happy-style --save
cat style.css | happy-style
For full loop use (format detected automatically):
cat style.css | happy-style | happy-style
Happy Style converts CSS to a JavaScript AST and back this way:
| CSS | Becomes |
|---|---|
.button { color: red } |
rule(selector([classSelector('button')]), [declaration('color', 'red')]) |
@media (min-width: 100px) |
mediaQuery([...]) |
@keyframes anim { ... } |
keyframes('anim', [ ... ]) |
The arguments of functionValue are always printed the same way: a single
space fills every gap between them, and a comma is an argument of its own, so
rgb(255, 0, 0) is
functionValue('rgb', [255, operator(','), 0, operator(','), 0]) while
rgb(0 0 0 / 20%) is
functionValue('rgb', [0, 0, 0, operator('/'), percentage(20)]).
import {montag} from 'montag';
import {
convertCssToJs,
convertJsToCss,
parseCss,
printCss,
} from 'happy-style';
const source = montag`
.button {
color: red;
}
`;
const js = convertCssToJs(source);
// returns
`
[
rule(
selector([classSelector('button')]),
[declaration('color', 'red')],
),
];
`;
convertJsToCss(js);
// returns
`
.button {
color: red;
}
`;
MIT
© 2010 - cnpmjs.org x YWFE | Home | YWFE