GithubHelp home page GithubHelp logo

hoffi / css-statistics Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cssstats/core

0.0 2.0 0.0 927 KB

Node module to parse a stylesheet and return an object with stats

Home Page: https://www.npmjs.com/package/cssstats

JavaScript 100.00%

css-statistics's Introduction

CSS Statistics

Parses stylesheets and returns an object with statistics

Used in http://cssstats.com

Installation

npm install --save cssstats

Usage

var fs = require('fs');
var cssstats = require('csstats');

var css = fs.readFileSync('./styles.css', 'utf8');
var obj = cssstats(css);

Instead of a CSS string, you can also pass the PostCSS AST:

var fs = require('fs');
var postcss = require('postcss');
var cssstats = require('csstats');

var css = fs.readFileSync('./styles.css', 'utf8');
var ast = postcss.parse(css);
var obj = cssstats(ast);

Using the CLI

npm i -g cssstats
cssstats file path/to/file.css > results.json

You can also pipe CSS to cssstats:

cat some-css-file.css | cssstats
getcss google.com | cssstats

Returned Object

size: The size of the file in bytes

gzipSize: The size of the stylesheet gzipped in bytes

selectors: An array of selectors sorted by source order with the selector string, specificity score, and parts array

declarations: An object of declarations.

  • declarations.all: An array of declaration objects from PostCSS.
  • declarations.byProperty: An object with keys for each property found in the stylesheet.
  • declarations.unique: An object with keys for each unique property/value found in the stylesheet.
  • declarations.byMedia: An object with keys for each media query found in the stylesheet.
  • declarations.propertyResetDeclarations: An object with keys for each property with a value of 0 found in the stylesheet. (Actually only margins and paddings are counted)
  • declarations.importantCount: The number of declarations with values that contain !important
  • declarations.vendorPrefixCount: The number of declaration properties that have vendor prefixes.
  • declarations.displayNoneCount: The number of display: none; declarations.
  • declarations.uniqueDeclarationsCount: The number of unique declarations.

rules: Flattened array of rules from PostCSS.

aggregates: Aggregate data for the entire stylesheet.

  • selectors - total number of selectors
  • declarations - total number of declarations
  • properties - an array of properties used in the stylesheet
  • mediaQueries - an array of media query strings used in the stylesheet
  • idSelectors - total number of selectors containing an id
  • classSelectors - total number of selectors containing a class
  • pseudoElementSelectors - total number of selectors containing an pseudo element
  • pseudoClassSelectors - total number of selectors containing a pseudo class
  • repeatedSelectors - array of selectors that were declared more than once

For every unique property found in the stylesheet, aggregates also includes these values:

  • [property].total - total number of [property] declarations
  • [property].unique - number of unique [property] declarations

See the /test/results folder for example JSON results.

css-statistics's People

Contributors

hoffi avatar johno avatar jxnblk avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.