• This repository has been archived on 09/Nov/2017
  • Stars
    star
    1,069
  • Rank 43,023 (Top 0.9 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 12 years ago
  • Updated about 9 years ago

Reviews

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

Repository Details

SQL EXPLAIN for CSS selectors

CSS EXPLAIN

Think of it like SQL EXPLAIN, but for CSS selectors.

Usage

cssExplain("li .item")
{
  "selector": "li .item",
  "parts": ["li", ".item"],
  "specificity": [0, 1, 1],
  "category": "class",
  "key": "item",
  "score": 6
}

Results

selector

The String selector input.

parts

Parsed Array of selector components.

specificity

Computed Array of specificy values.

See W3C calcuating selector specificity.

category

Category index key selector falls under. Either 'id', 'class', 'tag' or 'universal'.

Modeled after WebKit's rule set grouping optimizations. CSS rules in WebKit are indexed and grouped in a hash table to avoid having to do a full test on the element being matched. So its better to have selectors fall under unique id or class indexes rather than under more broad indexes like tags. Selectors in the universal category will always have to be tested against every element.

{
  "id": {
    "about": ["#about"]
  },
  "class": {
    "item": ["li .item"],
    "menu": ["ul.menu"],
    "minibutton": [".minibutton"]
  },
  "tag": {
    "a": ["ul.menu a", ".message a"],
    "span": [".nav > span"]
  },
  "universal": ["*", "[input=text]"]
}

To match against <a class="minibutton">, the rule set would include class -> minibutton, tag -> a and universal which is [".minibutton", "ul.menu a", ".message a", "*", "[input=text]"].

See RuleSet::addRule for reference.

key

Hash used for indexing under the category.

score

1-10 rating. 1 being the most efficient and 10 being the least.

NOTE: Don't take this value so seriously

messages

Array of infomational reasons for why the score was computed.

Contributing

$ git clone https://github.com/josh/css-explain.git
$ cd css-explain/

Run tests

$ make test

More Repositories

1

selector-set

JavaScript
279
star
2

rails-behaviors

Rails UJS Behaviors for jQuery and Zepto
CoffeeScript
271
star
3

selector-observer

Allows you to monitor DOM elements that match a CSS selector
JavaScript
217
star
4

jquery-selector-set

JavaScript
215
star
5

overcast-sonos

Listen to your Overcast podcasts on Sonos.
PHP
183
star
6

nack

Node powered Rack server
CoffeeScript
172
star
7

Aware

A simple menubar app for OSX and macOS that tracks how long you've been actively using your computer
Swift
143
star
8

launchdns

A launchd friendly development DNS server
Shell
75
star
9

dotfiles

My $HOME
Shell
63
star
10

imdb-trakt-sync-broken

Sync IMDb to Trakt
Shell
53
star
11

scroll-anchoring

Preserves the user's scroll position while DOM mutations change the page.
HTML
50
star
12

tickerd

A Docker process scheduler
Go
12
star
13

swift-har

A Swift library for encoding, decoding, recording and testing using the HTTP Archive format.
Swift
10
star
14

icloud-backup-utils

Scripts creating backups of iCloud data.
Shell
8
star
15

google-domains-ddns

Dockerfile
7
star
16

workflows

Reusable workflows for GitHub Actions
6
star
17

smtp2webhook

SMTP to Webhook Relay
Go
6
star
18

csv2json

A humble CSV tool, friend of jq
Swift
6
star
19

displayrcd

Run a script when your Mac changes displays
Swift
5
star
20

offlineimap-gmail

Dockerfile
3
star
21

trakt-plex-sync

Sync Trakt history to Plex library
Python
3
star
22

homeassistant-healthchecks

Home Assistant custom component for Healthchecks.io
Python
3
star
23

josh

My GitHub profile
2
star
24

wikidatabots

Wikidata bots running under Josh404Bot
Python
2
star
25

docker-ondemand

Lazily start and automatically stop Docker for Mac
Shell
2
star
26

ConsoleKit

An embeddable SwiftUI OSLog view
Swift
2
star
27

homebrew-tap

Homebrew custom formulas for @josh repositories.
Ruby
2
star
28

mixnmatch-catalogs

Python
2
star
29

itunes-library-export

A command line tool to export iTunes Library XML files.
Swift
2
star
30

wikidata-api-schemas

Wikidata JSON Schemas
Shell
1
star
31

joshpeek.com

Just a bunch of redirects
Dockerfile
1
star
32

smtp2workflow

SMTP to GitHub Actions workflow Relay
Go
1
star
33

us-state-travel-advisories-feeds

JSON feeds for U.S. Department of State Travel Advisories
Python
1
star
34

alamo-drafthouse-feeds

JSON feeds for Alamo Drafthouse showings
Python
1
star
35

overcast-data

Overcast podcast personal data scraper
Python
1
star
36

imdb-plex-sync

Sync IMDb watchlist to Plex watchlist
Python
1
star
37

imdb-data

IMDB personal lists and ratings data scaper
Python
1
star