Skip to content

A small helper to calculcate the cyclomatic complexity of CSS selectors

License

Notifications You must be signed in to change notification settings

rasshofer/cssplexity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSSplexity

A small helper to calculcate the cyclomatic complexity of CSS selectors

Build Status Coverage Status Dependency Status Dependency Status

Installation

npm install cssplexity --save-dev

Examples

Calculcate selector complexity

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

Parse CSS file and calculcate selector complexities

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
Licensed under the MIT license.

See LICENSE for more info.

About

A small helper to calculcate the cyclomatic complexity of CSS selectors

Resources

License

Stars

Watchers

Forks

Packages

No packages published