happy-style
css to js ast parser
Last updated 2 months ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install happy-style 
SYNC missed versions from official npm registry.

Happy Style License NPM version Build Status

CSS to JS AST parser.

Install

npm i happy-style --save

How to use?

Binary

cat style.css | happy-style

For full loop use (format detected automatically):

cat style.css | happy-style | happy-style

Reference

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)]).

API

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;
}
`;

License

MIT

Current Tags

  • 1.0.9                                ...           latest (2 months ago)

11 Versions

  • 1.0.9                                ...           2 months ago
  • 1.0.8                                ...           2 months ago
  • 1.0.7                                ...           2 months ago
  • 1.0.6                                ...           2 months ago
  • 1.0.5                                ...           2 months ago
  • 1.0.4                                ...           2 months ago
  • 1.0.3                                ...           2 months ago
  • 1.0.2                                ...           2 months ago
  • 1.0.1                                ...           2 months ago
  • 1.0.0                                ...           2 months ago
  • 0.1.0                                ...           2 months ago
Maintainers (1)
Downloads
Total 36
Today 0
This Week 0
This Month 15
Last Day 0
Last Week 12
Last Month 21
Dependencies (5)
Dev Dependencies (14)

© 2010 - cnpmjs.org x YWFE | Home | YWFE