StyleStats works on Node.js >=6.x
.
$ npm install -g stylestats
$ stylestats path/to/stylesheet.css
StyleStats!
βββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββ
β Published β June 14, 2017 10:35 AM β
βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββ€
β Paths β path/to/stylesheet.css β
βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββ€
β Style Sheets β 1 β
βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββ€
β Style Elements β 0 β
βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββ€
β Size β 240.0B β
βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββ€
β Data URI Size β 0 β
βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββ€
β Ratio of Data URI Size β 0 β
βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββ€
β Gzipped Size β 158.0B β
βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββ€
β Rules β 7 β
βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββ€
β Selectors β 12 β
βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββ€
β Simplicity β 58.3% β
βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββ€
β Average of Identifier β 1.250 β
βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββ€
β Most Identifier β 3 β
βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββ€
β Most Identifier Selector β .foo .bar .baz β
βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββ€
β Average of Cohesion β 1.429 β
βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββ€
β 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 β
βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββ€
β Total Unique Background Images β 0 β
βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββ€
β Unique Background Images β N/A β
βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββ€
β 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.css
CSS files in specified directory will be analyzed.
$ stylestats path/to/dir
Glob input is supported (quotes are required).
$ stylestats 'path/**/*.css'
You can specify a remote CSS file.
$ stylestats https://t32k.me/wisteria/css/wisteria.css
If you specify an HTML page, StyleStats will analyze stylesheets and style
elements.
$ stylestats https://t32k.me/
--format
option outputs JSON and CSV.
$ stylestats foo.css -f <json|csv>
If you have gist installed, you can upload StyleStats data to GitHub Gist with a one-liner command.
$ stylestats https://t32k.me/ > stats.txt && gist stats.txt
>> https://gist.github.com/anonymous/d6259fce3d80d2c71ebc7edc71c06088
The Simplicity is measured as Rules divided by Selectors.
The Average of Identifier is measured as Total Identifiers divided by Selectors.
The Average of Cohesion is measured as Total declarations divided by Rules.
The Lowest Cohesion metric is the number of selector declarations.
See also:
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:
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:
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
.
The Properties Count is the number of property declarations. The default is to display the top 10
properties.
You can configure StyleStats.
CLI:
$ stylestats -c path/to/.stylestatsrc
API:
const StyleStats = require('stylestats');
const stats = new StyleStats('path/to/stylesheet.css', 'path/to/.stylestatsrc');
Default configuration is here.
Here is an example JSON to disable display gzipped size:
{
"gzippedSize": false
}
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|csv>
-p, --prettify prettify raw data
-n, --number show only numeral metrics
-m, --mobile set the mobile user agent
Example:
$ stylestats path/to/stylesheet.css -c .stylestatsrc
StyleStats!
ββββββββββββββββββββββββββββββ¬βββββββββ
β Style Sheets β 1 β
ββββββββββββββββββββββββββββββΌβββββββββ€
β Size β 19.0KB β
ββββββββββββββββββββββββββββββΌβββββββββ€
β Gzipped Size β 3.7KB β
ββββββββββββββββββββββββββββββΌβββββββββ€
β Total Unique Font Families β 3 β
ββββββββββββββββββββββββββββββ΄βββββββββ
stylesheet
RequiredString|Array
Stylesheet's file path or its array.config
OptionalString|Object
Configuration JSON file path or object.
Config list is show to default.json
const StyleStats = require('stylestats');
const stats = new StyleStats('path/to/stylesheet.css');
stats.parse()
.then((result) => console.log(JSON.stringify(result, null, 2)))
.catch((err) => console.log(error));
result
RequiredObject
Result StyleStats parsed.
stats.parse()
.then((result) => stats.prettify(result));
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": "2017-06-14T10:24:30.124Z",
"paths": [ "test/fixture/example.css" ],
"stylesheets": 1,
"styleElements": 0,
"size": 240,
"dataUriSize": 0,
"ratioOfDataUriSize": 0,
"gzippedSize": 158,
"rules": 7,
"selectors": 12,
"simplicity": 0.5833333333333334,
"averageOfIdentifier": 1.25,
"mostIdentifier": 3,
"mostIdentifierSelector": ".foo .bar .baz",
"averageOfCohesion": 1.4285714285714286,
"lowestCohesion": 2,
"lowestCohesionSelector": [ ".foo" ],
"totalUniqueFontSizes": 2,
"uniqueFontSizes": [ "12px", "16px" ],
"totalUniqueFontFamilies": 0,
"uniqueFontFamilies": [],
"totalUniqueColors": 3,
"uniqueColors": [ "#333333", "#CCCCCC", "RED" ],
"totalUniqueBackgroundImages": 0,
"uniqueBackgroundImages": [],
"idSelectors": 1,
"universalSelectors": 1,
"unqualifiedAttributeSelectors": 1,
"javascriptSpecificSelectors": 0,
"importantKeywords": 1,
"floatProperties": 1,
"propertiesCount": [
{ "property": "color", "count": 4 },
{ "property": "font-size", "count": 3 },
{ "property": "margin", "count": 2 },
{ "property": "float", "count": 1 }
],
"mediaQueries": 0
}