npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

everycss-parser

v0.1.0

Published

Liberal CSS parser

Downloads

2

Readme

Introduction

Everycss-parser is a liberal CSS parser written in javascript. It follows the css syntaxe but takes some liberties allowing:

  • nested rules and/or at-rules
  • declarations out of rules
  • nonexistent properties, selectors, at-rules,…
  • unexpected characters, when possible

Features

  • turns "css" into standard javascript object descriptor
  • different level of precision for values
  • different level of precision for selectors

Getting started

Installation

Globally:

$ npm install everycss-parser -g

In your project:

$ npm install everycss-parser --save

In your package.json:

dependencies: {
  "everycss-parser": "*"
}

Usage

var
  fs      = require('fs'),
  Parser  = require('everycss-parser');

  fs.readFile('some.css', 'utf-8', function (error, data) {
    if (error) {
      return console.log(error);
    }

    // return object representation of `some.css`
    (new Parser()).parse(data);
  });

Documentation

Everycss outputs a plain object representing your css. This object is the root of your css and contains all top level elements. The elements are:

Blocks: root, rule and at-rule

Root, rules and at-rules share the same object structure:

| attribute | value | Description | |---------------|-----------------------------|------------------------------------------------------------| | type | 'root', 'rule' or 'at-rule' | type of the block | | selector | selector or null | selectors of the block | | atKeyword | string or null | at-rule keyword without leading '@' | | opened | bool | if the block has brackets (eg: @import 'some.css'; is not) | | content | array | content of the block |

Declaration

| attribute | value | Description | |---------------|-----------------------------|-----------------------------------------| | type | 'declaration' | | | property | string | type of the block | | value | value | values for the property |

Collections: value, selector, parenthesis

Values, selectors and parenthesis share the same object structure:

| attribute | value | Description | |---------------|--------------------------------------|--------------------------| | type | 'value', 'selector' or 'parenthesis' | type of the block | | content | string or array | content of the selection |

Collections content could be represented in four ways according to a given precision. Values and parenthesis use the valuePrecision attribute and selectors use the selectorPrecision one.

parser = new Parser();
parser.valuePrecision     = 1;
parser.selectorPrecision  = 1;

Precision: 0 (default)

Collection content is represented as a string like:

'foo 1px+2px, bar 3px'

Precision: 1

Each comma separated values is represented as an element of the collection's content array:

[
  'foo 1px+2px',
  'bar 3px'
]

Precision: 2

Like for precision 1 but each comma separated values is represented as an array of space separated values:

[
  ['foo', '1px+2px'],
  ['bar', '3px']
]

Precision: 3

Like for precision 2 but each space separated values is represented as an array of tokens:

[
  [
    [
      {
      "type": "identifier",
      "value": "foo"
      }
    ],
    [
      {
      "type": "number",
      "unit": "px",
      "value": 1
      },
      {
      "type": "operator",
      "value": "+"
      },
      {
      "type": "number",
      "unit": "px",
      "value": 2
      }
    ]
  ],
  [
    [
      {
      "type": "identifier",
      "value": "bar"
      }
    ],
    [
      {
      "type": "number",
      "unit": "px",
      "value": 3
      }
    ]
  ]
]

Function

| attribute | value | Description | |---------------|-----------------------------|--------------------------------------------------| | type | 'function' | | | keyword | string | function name | | arguments | value | arguments passed to the function |

Number

| attribute | value | Description | |---------------|-----------------------------|---------------------| | type | 'number' | | | unit | string or null | unit of the number | | value | float | value of the number |

String

| attribute | value | Description | |---------------|-----------------------------|---------------------| | type | 'identifier' | | | quote | ''' or '"' | the quote used | | value | string | the unquoted string |

Color

3 or 6 chars Hex colors

| attribute | value | Description | |---------------|-----------------------------|--------------------------------------------| | type | 'color' | | | value | string | 3 or 6 chars hex value without leading '#' |

Identifier

Identifiers are unquoted words like center or auto.

| attribute | value | Description | |---------------|-----------------------------|----------------| | type | 'identifier' | | | value | string | the identifier |

Comment

Everycss parses comment and inline comment. Inline comments are not allowed in CSS but are oftenly used by processors.

| attribute | value | Description | |---------------|-----------|--------------------------------------------------| | type | 'comment' | | | inline | bool | If the comment is inline (//) or not (/* */) | | value | string | the comment (/*, */ and // are preserved) |

Operator

Are operators are charIdentifiers are unquoted words like center or auto.

| attribute | value | Description | |---------------|-----------------------------|----------------| | type | 'identifier' | | | value | string | the identifier |