|
2 | 2 |
|
3 | 3 | CSS compiler using the AST provided by [css-parse](https://github.com/visionmedia/css-parse).
|
4 | 4 |
|
5 |
| -## Usage |
| 5 | +## API |
6 | 6 |
|
7 |
| -`css-stringify` exports a single function which dumps CSS AST: |
| 7 | +### stringify(object, [options]) |
8 | 8 |
|
9 |
| - var stringify = require('css-stringify'); |
10 |
| - var parse = require('css-parse'); |
| 9 | + Accepts an AST `object` from css-parse and returns a CSS string. |
11 | 10 |
|
12 |
| - var ast = parse('body { font-size: 12px; }'); |
| 11 | +```js |
| 12 | +var stringify = require('css-stringify'); |
| 13 | +var parse = require('css-parse'); |
13 | 14 |
|
14 |
| - var str = stringify(ast); |
| 15 | +var ast = parse('body { font-size: 12px; }'); |
| 16 | +var css = stringify(ast); |
| 17 | +``` |
15 | 18 |
|
16 |
| -To get compressed output pass `compress` option: |
| 19 | + Optionally you may `compress` the output: |
17 | 20 |
|
18 |
| - var compressed = stringify(ast, {compress: true}); |
| 21 | +```js |
| 22 | +var css = stringify(ast, { compress: true }); |
| 23 | +``` |
19 | 24 |
|
20 |
| -To get a source map pass `sourcemap` option: |
| 25 | + Or return a `sourcemap` along with the CSS output, |
| 26 | + which requires the use of the css-parse `position` option. |
21 | 27 |
|
22 |
| - var ast = parse('body { font-size: 12px; }', {position: true}); |
23 |
| - var result = stringify(ast, {sourcemap: true}); |
| 28 | +```js |
| 29 | +var ast = parse('body { font-size: 12px; }', { position: true }); |
| 30 | +var result = stringify(ast, { sourcemap: true }); |
24 | 31 |
|
25 |
| - result.code // string with CSS |
26 |
| - result.map // source map |
27 |
| - |
28 |
| -Note that the AST should contain position information (`position` option of |
29 |
| -`css-parse` set to `true`). |
| 32 | +result.code // string with CSS |
| 33 | +result.map // source map |
| 34 | +``` |
30 | 35 |
|
31 | 36 | ## Performance
|
32 | 37 |
|
|
0 commit comments