<commit_before># css [![Build Status](https://travis-ci.org/reworkcss/css.svg?branch=master)](https://travis-ci.org/reworkcss/css)

  CSS parser / stringifier.

## Installation

    $ npm install css

## Usage

```javascript
var css = require('css')
var obj = css.parse('body { font-size: 12px; }', options)
css.stringify(obj, options);
```

## API

### css.parse(css, [options])

Accepts a CSS string and returns an AST `object`.

`options`:

- `silent` - silently fail on parse errors.
- `source` - the path to the file containing `css`. Makes errors and source
  maps more helpful, by letting them know where code comes from.

### css.stringify(object, [options])

Accepts an AST `object` (as `css.parse` produces) and returns a CSS string.

`options`:

- `compress` - omit comments and extraneous whitespace.
- `sourcemap` - return a sourcemap along with the CSS output. Using the `source`
  option of `css.parse` is strongly recommended when creating a source map.

```js
var ast = css.parse('body { font-size: 12px; }', { position: true, source: 'source.css' });

var css = css.stringify(ast);

var result = css.stringify(ast, { sourcemap: true });
result.code // string with CSS
result.map // source map object
```

### Errors

Errors will have `error.position`, with the following properties:

- `start` - start line and column numbers.
- `end` - end line and column numbers.
- `source` - `options.source` if passed to `css.parse`.

If you create any errors in plugins such as in
[rework](https://github.com/reworkcss/rework), you __must__ set the `position`
as well for consistency.

## Examples

CSS:

```css
body {
  background: #eee;
  color: #888;
}
```

Parse tree:

```json
{
  "type": "stylesheet",
  "stylesheet": {
    "rules": [
      {
        "type": "rule",
        "selectors": [
          "body"
        ],
        "declarations": [
          {
            "type": "declaration",
            "property": "background",
            "value": "#eee",
            "position": {
              "start": {
                "line": 3,
                "column": 3
              },
              "end": {
                "line": 3,
                "column": 19
              }
            }
          },
          {
            "type": "declaration",
            "property": "color",
            "value": "#888",
            "position": {
              "start": {
                "line": 4,
                "column": 3
              },
              "end": {
                "line": 4,
                "column": 14
              }
            }
          }
        ],
        "position": {
          "start": {
            "line": 2,
            "column": 1
          },
          "end": {
            "line": 5,
            "column": 2
          }
        }
      }
    ]
  }
}
```

`node.position.content` is set on each node to the full source string. If you
also pass in `source: 'path/to/source.css'` to `css.parse`, that will be set on
`node.position.source`.

## License

MIT
<commit_msg>Fix #11: Update example parse tree<commit_after># css [![Build Status](https://travis-ci.org/reworkcss/css.svg?branch=master)](https://travis-ci.org/reworkcss/css)

  CSS parser / stringifier.

## Installation

    $ npm install css

## Usage

```javascript
var css = require('css')
var obj = css.parse('body { font-size: 12px; }', options)
css.stringify(obj, options);
```

## API

### css.parse(css, [options])

Accepts a CSS string and returns an AST `object`.

`options`:

- `silent` - silently fail on parse errors.
- `source` - the path to the file containing `css`. Makes errors and source
  maps more helpful, by letting them know where code comes from.

### css.stringify(object, [options])

Accepts an AST `object` (as `css.parse` produces) and returns a CSS string.

`options`:

- `compress` - omit comments and extraneous whitespace.
- `sourcemap` - return a sourcemap along with the CSS output. Using the `source`
  option of `css.parse` is strongly recommended when creating a source map.

```js
var ast = css.parse('body { font-size: 12px; }', { position: true, source: 'source.css' });

var css = css.stringify(ast);

var result = css.stringify(ast, { sourcemap: true });
result.code // string with CSS
result.map // source map object
```

### Errors

Errors will have `error.position`, with the following properties:

- `start` - start line and column numbers.
- `end` - end line and column numbers.
- `source` - `options.source` if passed to `css.parse`.

If you create any errors in plugins such as in
[rework](https://github.com/reworkcss/rework), you __must__ set the `position`
as well for consistency.

## Examples

CSS:

```css
body {
  background: #eee;
  color: #888;
}
```

Parse tree:

```json
{
  "type": "stylesheet",
  "stylesheet": {
    "rules": [
      {
        "type": "rule",
        "selectors": [
          "body"
        ],
        "declarations": [
          {
            "type": "declaration",
            "property": "background",
            "value": "#eee",
            "position": {
              "start": {
                "line": 2,
                "column": 3
              },
              "end": {
                "line": 2,
                "column": 19
              }
            }
          },
          {
            "type": "declaration",
            "property": "color",
            "value": "#888",
            "position": {
              "start": {
                "line": 3,
                "column": 3
              },
              "end": {
                "line": 3,
                "column": 14
              }
            }
          }
        ],
        "position": {
          "start": {
            "line": 1,
            "column": 1
          },
          "end": {
            "line": 4,
            "column": 2
          }
        }
      }
    ]
  }
}
```

`node.position.content` is set on each node to the full source string. If you
also pass in `source: 'path/to/source.css'` to `css.parse`, that will be set on
`node.position.source`.

## License

MIT

{'fraction_non_alphanumeric': 0.1471416735708368, 'fraction_numerical': 0.008285004142502071, 'mean_word_length': 1.8525519848771266, 'pattern_counts': {'":': 66, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3647124', 'n_tokens_mistral': 1889, 'n_tokens_neox': 1793, 'n_words': 557}