Package Exports
- stylestats
- stylestats/lib/format
- stylestats/lib/prettify
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (stylestats) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
StyleStats

StyleStats is a Node.js library to collect CSS statistics.
Installation
StyleStats works on Node.js 0.10.x
$ npm install -g stylestatsUsage
$ stylestats path/to/stylesheet.css
StyleStats!
┌─────────────────────────────────┬────────────────┐
│ Style Sheets │ 1 │
├─────────────────────────────────┼────────────────┤
│ Size │ 240B │
├─────────────────────────────────┼────────────────┤
│ Data URI Size │ 0 │
├─────────────────────────────────┼────────────────┤
│ Gzipped Size │ 158B │
├─────────────────────────────────┼────────────────┤
│ Rules │ 7 │
├─────────────────────────────────┼────────────────┤
│ Selectors │ 12 │
├─────────────────────────────────┼────────────────┤
│ Simplicity │ 58.3% │
├─────────────────────────────────┼────────────────┤
│ Most Identifier │ 3 │
├─────────────────────────────────┼────────────────┤
│ Most Identifier Selector │ .foo .bar .baz │
├─────────────────────────────────┼────────────────┤
│ Lowest Cohesion │ 2 │
├─────────────────────────────────┼────────────────┤
│ Lowest Cohesion Selector │ .foo │
├─────────────────────────────────┼────────────────┤
│ Total Unique Font Sizes │ 2 │
├─────────────────────────────────┼────────────────┤
│ Unique Font Sizes │ 12px │
│ │ 16px │
├─────────────────────────────────┼────────────────┤
│ Total Unique Font Families │ 0 │
├─────────────────────────────────┼────────────────┤
│ Unique Font Families │ N/A │
├─────────────────────────────────┼────────────────┤
│ Total Unique Colors │ 3 │
├─────────────────────────────────┼────────────────┤
│ Unique Colors │ #333333 │
│ │ #CCCCCC │
│ │ RED │
├─────────────────────────────────┼────────────────┤
│ ID Selectors │ 1 │
├─────────────────────────────────┼────────────────┤
│ Universal Selectors │ 1 │
├─────────────────────────────────┼────────────────┤
│ Unqualified Attribute Selectors │ 1 │
├─────────────────────────────────┼────────────────┤
│ JavaScript Specific Selectors │ 0 │
├─────────────────────────────────┼────────────────┤
│ Important Keywords │ 1 │
├─────────────────────────────────┼────────────────┤
│ Float Properties │ 1 │
├─────────────────────────────────┼────────────────┤
│ Properties Count │ color: 4 │
│ │ font-size: 3 │
│ │ margin: 2 │
│ │ float: 1 │
├─────────────────────────────────┼────────────────┤
│ Media Queries │ 0 │
└─────────────────────────────────┴────────────────┘Specified css file will be analyzed.
# Providing multiple input is also supported.
$ stylestats foo.css bar.css baz.cssCSS files in specified directory will be analyzed.
$ stylestats path/to/dirGlob input is supported (quotes are required).
$ stylestats 'path/**/*.css'You can specify a remote CSS file.
$ stylestats http://t32k.me/wisteria/css/wisteria.cssIf you specify an HTML page, StyleStats will analyze stylesheets and style elements.
$ stylestats http://t32k.me/--format option outputs JSON, HTML, Markdown and CSV.
$ stylestats foo.css -f <json|html|md|csv>If you have gist installed, you can upload StyleStats data to GitHub Gist with a one-liner command.
$ stylestats http://t32k.me/ -f md > stats.md && gist stats.md
https://gist.github.com/9725673Other tools
Metrics

Simplicity
The Simplicity is measured as Rules divided by Selectors.
Lowest Cohesion
The Lowest Cohesion metric is the number of selector declarations.
Unqualified Attribute Selectors
The Unqualified Attribute Selectors metrics is the number of unqualified attribute selectors.
The following patterns will be counted:
[type=text] {
color: red;
}
.selected [type=text] {
color: red;
}The following patterns are considered to be okay and will not be counted:
/* unqualified attribute selector is not key */
.selected [type=text] a {
color: red;
}See also:
JavaScript Specific Selectors
The JavaScript Specific Selectors metrics is the number of JavaScript-specific selectors, such as js-*. The selectors are only for JavaScript hooks; you should not to hang any presentation off them.
See also:
User Specified Selectors
The User Specified Selectors metrics is the number of user-specified selectors. Default is false. For instance, you can count the number of components if you specify "\\.component\\-" using reqular expression in .stylestatsrc .
Properties Count
The Properties Count is the number of property declarations. The default is to display the top 10 properties.
Configuration
You can configure StyleStats.
CLI:
$ stylestats -c path/to/.stylestatsrcAPI:
var StyleStats = require('stylestats');
var stats = new StyleStats('path/to/stylesheet.css', 'path/to/.stylestatsrc');Default configuration is here.
Here is an example JSON to enable display gzipped size:
{
"gzippedSize": false
}gzippedSize attribute is true by default.
CLI Reference
Help:
$ stylestats --help
Usage: stylestats [options] <file ...>
Options:
-h, --help output usage information
-V, --version output the version number
-c, --config [path] set configurations
-f, --format [format] set the output format <json|html|md|csv>
-t, --template [path] set the template path for output formant
-s, --specs [path] run test with your test specs file
-n, --number show only numeral metrics
-m, --mobile set the mobile user agentExample:
$ stylestats path/to/stylesheet.css -c path/to/.stylestatsrc
StyleStats!
┌────────────────────────────┬────────┐
│ Style Sheets │ 1 │
├────────────────────────────┼────────┤
│ Size │ 19.0KB │
├────────────────────────────┼────────┤
│ Gzipped Size │ 3.7KB │
├────────────────────────────┼────────┤
│ Total Unique Font Families │ 3 │
└────────────────────────────┴────────┘Integration
API Reference
new StyleStats(stylesheet, config)
stylesheetRequiredString|ArrayStylesheet file path or its array.configOptionalString|ObjectConfiguration JSON file path or object.
StyleStats.parse(fn)
var StyleStats = require('stylestats');
var stats = new StyleStats('path/to/stylesheet.css');
stats.parse(function (error, result) {
console.log(JSON.stringify(result, null, 2));
});Example
CSS example:
* { float: left; }
body { color: #333; }
h1, h2, h3, h4, h5, h6 { margin: 0; }
a[src] { color: red !important; }
.foo { color: #ccc; font-size: 12px; }
.foo .bar .baz { color: #ccc; font-size: 12px; }
#bar { margin: 10px; font-size: 16px; }Statistics tree of above css:
{
"published": "2014-06-14T10:10:40.825Z",
"paths": [ "test/fixture/example.css" ],
"stylesheets": 1,
"size": 240,
"dataUriSize": 0,
"gzippedSize": 158,
"rules": 7,
"selectors": 12,
"simplicity": 0.5833333333333334,
"mostIdentifers": 3,
"mostIdentifersSelector": ".foo .bar .baz",
"lowestCohesion": 2,
"lowestCohesionSelector": [ ".foo" ],
"totalUniqueFontSizes": 2,
"uniqueFontSizes": [ "12px", "16px" ],
"totalUniqueFontFamilies": 0,
"uniqueFontFamilies": [],
"totalUniqueColors": 3,
"uniqueColors": [ "#333333", "#CCCCCC", "RED" ],
"idSelectors": 1,
"universalSelectors": 1,
"unqualifiedAttributeSelectors": 1,
"javascriptSpecificSelectors": 0,
"importantKeywords": 1,
"floatProperties": 1,
"mediaQueries": 0,
"propertiesCount": [
{ "property": "color", "count": 4 },
{ "property": "font-size", "count": 3 },
{ "property": "margin", "count": 2 },
{ "property": "float", "count": 1 }
]
}License
Code is released under the MIT license.