# cssplexity

> A small helper to calculcate the cyclomatic complexity of CSS selectors

Latest version **0.4.0** (published 2016-10-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install cssplexity
pnpm add cssplexity
yarn add cssplexity
bun add cssplexity
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2016-10-25 |
| First published | 2016-09-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Thomas Rasshofer |
| Maintainers | rasshofer |
| Keywords | cssplexity, css, complexity |

## Links

- npm: https://www.npmjs.com/package/cssplexity
- Repository: https://github.com/rasshofer/cssplexity
- Homepage: https://github.com/rasshofer/cssplexity#readme
- Issues: https://github.com/rasshofer/cssplexity/issues
- npm.io page: https://npm.io/package/cssplexity

## Dependencies (2)

- [css](https://npm.io/package/css.md) ^2.2.1
- [css-selector-tree](https://npm.io/package/css-selector-tree.md) 0.0.2

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 0.4.0 (latest) — 2016-10-25
- 0.3.0 — 2016-10-17
- 0.2.0 — 2016-09-11
- 0.1.0 — 2016-09-09
- 0.0.2 — 2016-09-09
- 0.0.1 — 2016-09-09

## README

# CSSplexity

> A small helper to calculcate the cyclomatic complexity of CSS selectors

[![Build Status](https://travis-ci.org/rasshofer/cssplexity.svg)](https://travis-ci.org/rasshofer/cssplexity)
[![Coverage Status](https://coveralls.io/repos/github/rasshofer/cssplexity/badge.svg)](https://coveralls.io/github/rasshofer/cssplexity)
[![Dependency Status](https://david-dm.org/rasshofer/cssplexity/status.svg)](https://david-dm.org/rasshofer/cssplexity)
[![Dependency Status](https://david-dm.org/rasshofer/cssplexity/dev-status.svg)](https://david-dm.org/rasshofer/cssplexity)

## Installation

```shell
npm install cssplexity --save-dev
```

## Examples

### Calculcate selector complexity

```js
var cssplexity = require('cssplexity');
var result = cssplexity.selector('.teaser .article-title .headline');
console.log('Complexity: ' + result);
```

### Parse CSS file and calculcate selector complexities

```js
var cssplexity = require('cssplexity');
var results = cssplexity.parse('.teaser .article-title .headline { color: red } body { background: red }');
console.log(JSON.stringify(results, null, 2));
```

## API

### cssplexity.selector(selector)

Accepts a CSS selector and returns its complexity.

In case no valid CSS selector is provided, `false` is returned.

### cssplexity.parse(code)

Accepts CSS code and returns an object containing the complexity per selector, ordered decreasingly by complexity.

In case no valid CSS selector is found within the provided CSS code, `false` is returned.

## Changelog

* 0.4.0
  * Remove CSS selector tree methods in favor of its own npm module
  * Update outdated dependencies
* 0.3.0
  * Fix parser for selector-less input (e.g. comments)
* 0.2.0
  * Fix complexity calculation to include the subject as well
* 0.1.0
  * Fix complexity calculation to include child selectors as well
* 0.0.2
  * Update outdated dependencies
* 0.0.1
  * Initial version

## License

Copyright (c) 2016 [Thomas Rasshofer](http://thomasrasshofer.com/)  
Licensed under the MIT license.

See LICENSE for more info.

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