# css-tokenize

> Transform stream that tokenizes CSS

Latest version **1.0.1** (published 2014-12-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install css-tokenize
pnpm add css-tokenize
yarn add css-tokenize
bun add css-tokenize
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2014-12-21 |
| First published | 2014-12-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Anand Thakker |
| Maintainers | anandthakker |
| Keywords | css, tokenize, parse, stream, streaming |

## Links

- npm: https://www.npmjs.com/package/css-tokenize
- Repository: https://github.com/anandthakker/css-tokenize
- Issues: https://github.com/anandthakker/css-tokenize/issues
- npm.io page: https://npm.io/package/css-tokenize

## Dependencies (2)

- [inherits](https://npm.io/package/inherits.md) ^2.0.1
- [readable-stream](https://npm.io/package/readable-stream.md) ^1.0.33

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2014-12-21
- 1.0.0 — 2014-12-21

## README

css-tokenize
============

Coarsely tokenize a stream of CSS, largely modeled after 
[substack/html-tokenize](/substack/html-tokenize).

```javascript
var tokenize = require('css-tokenize'),
through = require('through2');

process.stdin
.pipe(tokenize())
.pipe(through.obj(function(token, enc, next) {
  token[1] = token[1].toString(); // it's a buffer slice
  console.log('TOKEN', token);
  next();
}))
```

Input:
```css

div {
  background: red;
}

.cls {
  color: green;
}

#id {
  font-size: 10px;
}

/* comment */

@media screen and (min-width: 1000px) {
  a {
    text-decoration: underline;
  }
}

a:hover {
  font-weight: bold;  
}

section 


{
  margin: 0;
  /* comment wthin a rule */
  padding: 5px;
}


body > * {
  
}
```

Output:
```
TOKEN [ 'root', '\n' ]
TOKEN [ 'rule_start', 'div {' ]
TOKEN [ 'rule', '\n  background: red;\n' ]
TOKEN [ 'rule_end', '}' ]
TOKEN [ 'root', '\n\n' ]
TOKEN [ 'rule_start', '.cls {' ]
TOKEN [ 'rule', '\n  color: green;\n' ]
TOKEN [ 'rule_end', '}' ]
TOKEN [ 'root', '\n\n' ]
TOKEN [ 'rule_start', '#id {' ]
TOKEN [ 'rule', '\n  font-size: 10px;\n' ]
TOKEN [ 'rule_end', '}' ]
TOKEN [ 'comment', '\n\n/* comment */' ]
TOKEN [ 'space', '\n\n' ]
TOKEN [ 'atrule_start', '@media screen and (min-width: 1000px) {' ]
TOKEN [ 'atrule', '\n  ' ]
TOKEN [ 'rule_start', 'a {' ]
TOKEN [ 'rule', '\n    text-decoration: underline;\n  ' ]
TOKEN [ 'rule_end', '}' ]
TOKEN [ 'atrule', '\n' ]
TOKEN [ 'atrule_end', '}' ]
TOKEN [ 'root', '\n\n' ]
TOKEN [ 'rule_start', 'a:hover {' ]
TOKEN [ 'rule', '\n  font-weight: bold;  \n' ]
TOKEN [ 'rule_end', '}' ]
TOKEN [ 'root', '\n\n' ]
TOKEN [ 'rule_start', 'section \n\n\n{' ]
TOKEN [ 'rule', '\n  margin: 0;\n  ' ]
TOKEN [ 'comment', '/* comment wthin a rule */' ]
TOKEN [ 'rule', '\n  padding: 5px;\n' ]
TOKEN [ 'rule_end', '}' ]
TOKEN [ 'root', '\n\n\n' ]
TOKEN [ 'rule_start', 'body > * {' ]
TOKEN [ 'rule', '\n  \n' ]
TOKEN [ 'rule_end', '}' ]
TOKEN [ 'root', '\n' ]
```

---
_Source: https://npm.io/package/css-tokenize · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
