• Stars
    star
    1,835
  • Rank 25,121 (Top 0.5 %)
  • Language
    CSS
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

StyleStats is a library to collect CSS statistics.

StyleStats Build Status Dependency Status Coverage Status XO code style

Installation

StyleStats works on Node.js >=6.x.

$ npm install -g stylestats

Usage

$ 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

Metrics

Metrics

Simplicity

The Simplicity is measured as Rules divided by Selectors.

Average of Identifier

The Average of Identifier is measured as Total Identifiers divided by Selectors.

Average of Cohesion

The Average of Cohesion is measured as Total declarations divided by Rules.

Lowest Cohesion

The Lowest Cohesion metric is the number of selector declarations.

See also:

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/.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
}

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|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      │
└────────────────────────────┴────────┘

Integration

API Reference

new StyleStats(stylesheet, [config])

  1. stylesheet Required String|Array Stylesheet's file path or its array.
  2. config Optional String|Object Configuration JSON file path or object.

config

Config list is show to default.json

StyleStats#parse()

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));

StyleStats#prettify(result)

  1. result Required Object Result StyleStats parsed.
stats.parse()
  .then((result) => stats.prettify(result));

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": "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
}

More Repositories

1

material-design-color-palette

Sketch app plugin for displaying 2014 Material Design color palettes
JavaScript
559
star
2

maple

A better front-end boilerplate.
CSS
168
star
3

grunt-csso

Minify CSS files with CSSO.
JavaScript
163
star
4

wisteria

The best HTML-driven prototyping tool for designing in browser.
CSS
52
star
5

webpagetest-doc-ja

WebPagetest Documentation in Japanese.
38
star
6

speed

Make the Web Faster!
CSS
36
star
7

licecap-icon

A better icon for LICEcap.
24
star
8

gaer

A CLI for Google Analytics Event Tracking Report.
JavaScript
22
star
9

Nyars

Appcelerator Titanium Mobile Project.
JavaScript
17
star
10

sublime-text-icon

A replacement icon for Sublime Text 2 and Sublime Text 3
10
star
11

jsoff

A chrome extension to disable JavaScript with one click.
JavaScript
8
star
12

mol

More or Less.
HTML
8
star
13

Coda-Completion-for-jQuery-Mobile

7
star
14

generator-maple

A generator for Maple project
JavaScript
6
star
15

grunt-scandium

This is a half-baked grunt plugin for titanium command line.
JavaScript
6
star
16

dotfiles

わい、黒い画面の向こうに行ってみたいねんっ!
Vim Script
4
star
17

gFaceee

A Chrome Extension for better GitHub UI.
JavaScript
3
star
18

ATND-Manager

Enhance atnd.org.
JavaScript
3
star
19

gulp-define-golang-template

Gulp extension to define a golang template.
JavaScript
2
star
20

grunt-init-maple

Create a basic maple project with grunt-init.
JavaScript
2
star
21

test

Don't Guess it, Test it!
CSS
2
star
22

packs

2
star
23

sample-qiita-material-design

HTML
2
star
24

tumblrtouch

JavaScript
1
star
25

static

Hosted static resource.
HTML
1
star
26

t32k

Config files for my GitHub profile.
1
star
27

slides

HTML
1
star
28

kanazawajs

My first memorial community.
1
star
29

hello-ecmascript

You might not need CoffeeScript and Lodash :)
JavaScript
1
star
30

sample_spriting_with_compass

Ruby
1
star
31

t32k.github.io

HTML
1
star
32

octocat-clerk

1
star
33

Meta-Checker

Display title element, meta elements(description, keywords), and count characters.
JavaScript
1
star