JSPM

  • Created
  • Published
  • Downloads 489
  • Score
    100M100P100Q112967F
  • License MIT

Stylestats is a efficient Node.js library for keeping stylesheet statistics.

Package Exports

  • stylestats
  • stylestats/lib/defaultOptions

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 efficient Node.js library for keeping stylesheet statistics.

Build Status NPM version Dependency Status devDependency Status

Installation

$ npm install -g stylestats

Usage

$ stylestats path/to/stylesheet.css
StyleStats!
┌───────────────────────────┬───────────────┐
│ Size                      │ 498.0B        │
├───────────────────────────┼───────────────┤
│ Rules                     │ 8             │
├───────────────────────────┼───────────────┤
│ Selectors                 │ 11            │
├───────────────────────────┼───────────────┤
│ Simplicity                │ 72.73%        │
├───────────────────────────┼───────────────┤
│ Lowest Cohesion           │ 6             │
├───────────────────────────┼───────────────┤
│ Lowest Cohesion Selecotor │ hr            │
├───────────────────────────┼───────────────┤
│ Total Unique Font Sizes   │ 5             │
├───────────────────────────┼───────────────┤
│ Unique Font Size          │ 10px          │
│                           │ 12px          │
│                           │ 14px          │
│                           │ 16px          │
│                           │ 18px          │
├───────────────────────────┼───────────────┤
│ Total Unique Colors       │ 2             │
├───────────────────────────┼───────────────┤
│ Unique Color              │ #333          │
│                           │ #CCC          │
├───────────────────────────┼───────────────┤
│ Id Selectors              │ 1             │
├───────────────────────────┼───────────────┤
│ Important Keywords        │ 1             │
├───────────────────────────┼───────────────┤
│ Media Queries             │ 1             │
├───────────────────────────┼───────────────┤
│ Properties Count          │ font-size: 5  │
│                           │ margin: 4     │
│                           │ padding: 3    │
│                           │ color: 2      │
│                           │ display: 1    │
│                           │ height: 1     │
│                           │ border: 1     │
│                           │ border-top: 1 │
└───────────────────────────┴───────────────┘

Metrics

Simplicity

The Simplicity is measured as Rules divided by Selectors.

Lowest Cohesion

The Lowest Cohesion metric is the count of the declarations of the most declared selector.

Properties Count

The Properties Count is ranking of declared properties. Default option is display the top 10.

Configuration

You must configure Stylestats before use.

CLI:

$ stylestats -c path/to/.stylestatsrc

API:

var StyleStats = require('stylestats');
var stats = new StyleStats('path/to/stylesheet.css', 'path/to/.stylestatsrc');

Default configuration is here.

Here is configuration's JSON example of enabling display gzipped size:

{
  "gzippedSize": true
}

gzippedSize is default false. because, pretty slow.

CLI Reference

$ stylestats -h

  Usage: stylestats [options] <file ...>

  Options:

    -h, --help                output usage information
    -V, --version             output the version number
    -c, --config [path]       Path and name of the incoming JSON file.
    -e, --extension [format]  Specify the format to convert. <json|csv>
    -s, --simple              Show compact style's log.
$ stylestats path/to/stylesheet.css -s -c path/to/.stylestatsrc
StyleStats!
┌───────────────────────────┬───────────────┐
│ Rules                     │ 8             │
│ Selectors                 │ 11            │
│ Lowest Cohesion           │ 6             │
│ Total Unique Font Sizes   │ 5             │
│ Total Unique Colors       │ 2             │
│ Id Selectors              │ 1             │
│ Important Keywords        │ 1             │
│ Media Queries             │ 1             │
└───────────────────────────┴───────────────┘

API Reference

StyleStats(stylesheet, config)

stylesheet

Required Type: String

Stylesheet file path.

config

Optional Type: String

Configuration's JSON file path.

var StyleStats = require('stylestats');
var stats = new StyleStats('path/to/stylesheet.css');

console.log(JSON.stringify(stats.parse(), null, 2));

Example

body {
  color: #333;
  font-size: 14px;
}
h1, h2, h3, h4, h5, h6 {
  margin: 0;
  padding: 0;
  font-size: 18px;
}
section {
  margin: 10px;
  padding: 10px;
  font-size: 10px;
}
.foo .bar .baz .qux .quux {
  color: #ccc;
  font-size: 12px;
}
#foo {
  margin: 10px;
  font-size: 16px;
}
/* Lowest Cohesion Selecotor */
hr {
  display: block;
  margin: 10px 0;
  padding: 0 !important;
  height: 1px;
  border: 0;
  border-top: 1px solid red;
}
@media (max-width: 600px) {
  .media-queries {
    display: none;
  }
}

Above the stylesheet's stats tree:

{
  "size": 498,
  "rules": 8,
  "selectors": 11,
  "simplicity": 0.7272727272727273,
  "lowestCohesion": 6,
  "lowestCohesionSelecotor": [ "hr" ],
  "totalUniqueFontSizes": 5,
  "uniqueFontSize": [ "10px","12px","14px","16px","18px" ],
  "totalUniqueColors": 2,
  "uniqueColor": [ "#333", "#CCC" ],
  "idSelectors": 1,
  "importantKeywords": 1,
  "mediaQueries": 1,
  "propertiesCount": [
        { "property": "font-size", "count": 5},
        { "property": "margin", "count": 4},
        { "property": "padding", "count": 3},
        { "property": "color", "count": 2},
        { "property": "display", "count": 1},
        { "property": "height", "count": 1},
        { "property": "border", "count": 1},
        { "property": "border-top", "count": 1}
  ]
}

Online Tool

(Coming soon)

License

Code is released under the MIT license.