• Stars
    star
    113
  • Rank 310,115 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 12 years ago
  • Updated almost 6 years ago

Reviews

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

Repository Details

create matching selectors from css for your very own nested object hierarchy

cssauron

build a matching function in CSS for any nested object structure!

var language = require('cssauron')({
    tag: 'tagName'
  , contents: 'innerText'
  , id: 'id'
  , class: 'className'
  , parent: 'parentNode'
  , children: 'childNodes'
  , attr: 'getAttribute(attr)'
})

var selector = language('body > #header .logo')
  , element = document.getElementsByClassName('logo')[0]

if(selector(element)) {
  // element matches selector
} else {
  // element does not match selector
}

It's easy to use with your favorite nested tree structures! Delicious with HTML! Digestable with JSON!

HTML JSON GLSL AST JS AST (Esprima)
cssauron-html cssauron-json cssauron-glsl cssauron-falafel

API

require('cssauron')(options) -> selector factory

Import cssauron and configure it for the nested object structure you'll want to match against.

options

options are an object hash of lookup type to string attribute or function(node) lookups for queried nodes. You only need to provide the configuration necessary for the selectors you're planning on creating. (If you're not going to use #id lookups, there's no need to provide the id lookup in your options.)

  • tag: Extract tag information from a node for div style selectors.
  • contents: Extract text information from a node, for :contains(xxx) selectors.
  • id: Extract id for #my_sweet_id selectors.
  • class: .class_name
  • parent: Used to traverse up from the current node, for composite selectors body #wrapper, body > #wrapper.
  • children: Used to traverse from a parent to its children for sibling selectors div + span, a ~ p.
  • attr: Used to extract attribute information, for [attr=thing] style selectors.

selector_factory('some selector') -> match function

Compiles a matching function.

match(node) -> false | node | [subjects, ...]

Returns false if the provided node does not match the selector. Returns truthy if the provided node does match. Exact return value is determined by the selector, based on the CSS4 subject selector spec: if only a single node is matched, only that node is returned. If multiple subjects are matched, a deduplicated array of those subjects are returned.

For example, given the following HTML (and cssauron-html):

<div id="gary-busey">
    <p>
        <span class="jake-busey">
        </span>
    </p>
</div>

Checking the following selectors against the span.jake-busey element yields:

  • #gary-busey: false, no match.
  • #gary-busey *: span.jake-busey, a single match.
  • !#gary-busey *: div#gary-busey, a single match using the ! subject selector.
  • #gary-busey *, p span: span.jake-busey, a single match, though both selectors match.
  • #gary-busey !* !*, !p > !span: [p, span.jake-busey], two matches.

Supported pseudoclasses

  • :first-child
  • :last-child
  • :nth-child
  • :empty
  • :root
  • :contains(text)
  • :any(selector, selector, selector)

Supported attribute lookups

  • [attr=value]: Exact match
  • [attr]: Attribute exists and is not false-y.
  • [attr$=value]: Attribute ends with value
  • [attr^=value]: Attribute starts with value
  • [attr*=value]: Attribute contains value
  • [attr~=value]: Attribute, split by whitespace, contains value.
  • [attr|=value]: Attribute, split by -, contains value.

More Repositories

1

git-rs

git, implemented in rust, for fun and education 🦀
Rust
1,335
star
2

beefy

local development server that aims to make using browserify fast and fun
JavaScript
801
star
3

raf

requestAnimationFrame polyfill library
JavaScript
740
star
4

plate

a javascript template library, aimed at being compatible with django's template language.
JavaScript
183
star
5

ormnomnom

an orm that does 80% of the work and gets out of the way for the remaining 20%
JavaScript
169
star
6

bops

buffer operations
JavaScript
100
star
7

wilson

a node.js framework that glues together routes, views, orms, and things. designed to help tim allen navigate his day.
JavaScript
95
star
8

varint

use msb to create integer values of varying sizes
JavaScript
90
star
9

vkey

map ev.keyCode to human names
JavaScript
81
star
10

nojs

☁️☁️ nothing to see, a PLAN, and the ability to load lodash ☁️☁️
Python
73
star
11

node-python

a binding between node.js (really, the V8 engine) and python. super beta super buggy super great
C++
67
star
12

sse-stream

expose html5 server sent events (sse) as a writable stream
JavaScript
57
star
13

clawbang

#!/usr/bin/env 🦀
Rust
52
star
14

glslmin

CLI tool to minify and bundle glsl programs
C
37
star
15

fullscreen

fullscreen polyfill api that presents an event emitter
JavaScript
36
star
16

reverse

💞 An HTTP router that provides reversing capabilities.
JavaScript
33
star
17

inflate

pure javascript inflate implemented as a through stream
JavaScript
33
star
18

provenance

visualize dependencies between functions in your JS
JavaScript
32
star
19

spatial-events

3d spatially aware event emitter
JavaScript
30
star
20

digraph-tag

ES6 string template tag for quickly generating directed graph data
JavaScript
30
star
21

browservefy

simplehttpserver / webrick replacement that automatically responds to a given entry point path with the results of browserify <that path>
JavaScript
28
star
22

python-javascript

A pure python implementation of JavaScript, just because.
Python
25
star
23

tide-http-auth

HTTP auth for tide! Pretty Basic, if you'll Bearer with me
Rust
25
star
24

jik

use css selectors to grep your JS codebase
JavaScript
24
star
25

node-runforcover

A require hook for node-bunker to emit coverage data.
JavaScript
24
star
26

rewrite-js

CLI tool to transform javascript programs using falafel
JavaScript
24
star
27

aabb-2d

2d axis aligned bounding boxes
JavaScript
20
star
28

setup-yq

JavaScript
20
star
29

aabb-3d

3d axis aligned bounding boxes
JavaScript
20
star
30

tracejs

Expand Node.js Error.stack traces into usable objects providing context and highlighting
JavaScript
20
star
31

kb-controls

present a polling interface for keyboard state given a binding object
JavaScript
19
star
32

asm-tag

compile x64 assembly into a callable function
JavaScript
19
star
33

escontrol

JavaScript
18
star
34

add-event-listener

add event listeners in IE and ... everywhere else
JavaScript
17
star
35

voxel-physical

create objects that have aabbs and respond to accel and vel updates
JavaScript
16
star
36

drag-stream

streamable mouse drag data
JavaScript
16
star
37

jabbascript

lightweight syntax additions to javascript, from a curmudgeon who loves javascript just the way it is
JavaScript
16
star
38

node-piano

A node.js require-hook for instrumenting your javascript code
JavaScript
15
star
39

mdn-cli

a CLI for accessing mozilla dev network docs in your terminal
Rust
14
star
40

cssauron-falafel

falafel bindings for cssauron
JavaScript
14
star
41

platoon

a javascript testing framework whose goals are to work gracefully with callbacks, both in node.js and the browser
JavaScript
14
star
42

essim

JavaScript
14
star
43

json-parse-stream

streaming json parser
JavaScript
14
star
44

stream-exhaust

Ensure that a stream is flowing data without mutating it
JavaScript
13
star
45

domnode-dom

DOMNode streams for HTMLElements
JavaScript
13
star
46

redispump

pipe stdout to a redis pubsub channel
JavaScript
13
star
47

jsl

a modular js linter
JavaScript
12
star
48

interact

a readable stream of mouse view events, wrapping up pointer-lock and drag-stream
JavaScript
12
star
49

simplee

A simple EventEmitter utility library for client-side use. Mimics Node.js's EventEmitter object.
JavaScript
12
star
50

yrc

you're real cool - a javascript parser written in c
C
12
star
51

tempisfugit

a node.js async binding to git. holy crap.
JavaScript
12
star
52

django-butter

Butter forms for Django (wokka-wokka-wokka)
Python
12
star
53

djamocha

Django and Mocha unit tests (with a CLI test runner)
JavaScript
11
star
54

npm-get-dependents

get all dependents of an npm package
JavaScript
11
star
55

tinybabygame

a little baby game i wrote in javascript using canvas.
JavaScript
10
star
56

voxel-control

manipulate voxel-physical objects using FPS-style controls
JavaScript
10
star
57

utensil

CLI tool to fork, run, and monitor node.js servers
JavaScript
10
star
58

worker.js

A semi-polyfill api for web workers. Aimed at making the experience fun (and not at all painful!)
JavaScript
9
star
59

git-to-js

translate git raw objects into javascript objects
JavaScript
9
star
60

narrativ

kind of a rip-off of docco, looking to make generating complex trees of literate-programming documentation easier.
JavaScript
9
star
61

directed-graph-to-dag

given a directed graph, return a set of edges to reverse to remove any cycles
JavaScript
9
star
62

waiter

a domain specific language/api for RESTful interfaces, inspired by Dolt
Python
9
star
63

normalize-css

normalize.css (from http://necolas.github.com/normalize.css/)
CSS
9
star
64

simplify-dag

given a directed acyclic graph, contract straight-line runs to single vertices
JavaScript
8
star
65

w3c-blob

w3c dom blob api in node and browser
JavaScript
8
star
66

phone-sensor

turn your phone into a sensor for great justice.
JavaScript
8
star
67

pointer-lock

pointer lock polyfill that presents an eventemitter / stream api
JavaScript
8
star
68

gsv

github search vehicle
JavaScript
8
star
69

postpie

a backend and transport for pieshop that uses ry's node_postgres binding!
JavaScript
8
star
70

tag_utils

a utility library that aims to alleviate some of the pain of writing django template tags using surlex.
Python
8
star
71

a-wild-version-appears

sometimes versions happen and you want to alert your users
JavaScript
8
star
72

django-bluebird

A Twitter OAuth multi-site authentication backend for Django, and so much more
Python
8
star
73

git-transport-protocol

a r/w stream that wraps a r/w stream and formats the data according to the git transfer protocol
JavaScript
7
star
74

nappingcat

a single-user ssh framework inspired by django
Python
7
star
75

git-the-latest

JavaScript
7
star
76

zigzag

zigzag signed integer encoding and decoding
JavaScript
7
star
77

reverse.js

reverse match your urls in clientside javascript (and node).
JavaScript
7
star
78

dom-event-stream

create a readable stream of dom events given an element
JavaScript
7
star
79

hq

aw heq – a jq-like CLI tool for modifying HTML trees based on CSS selectors
Rust
7
star
80

ls-stream

readable stream of file paths + stat objects
JavaScript
7
star
81

bfy-worker

web workers for browserify made fast, fun, and easy
JavaScript
7
star
82

keyframely

A JQuery-less rewrite of https://github.com/KuraFire/runloop -- usable in Node or in-browser.
JavaScript
7
star
83

git-fetch-pack

git's smart fetch-pack protocol
JavaScript
7
star
84

gl-triangle-strip-indexer

create element indices for triangle strip meshes
JavaScript
6
star
85

texture.js

browserify-compatible webgl 2D texture lib.
JavaScript
6
star
86

dst.js

Date.prototype.isDST() // true or false
JavaScript
6
star
87

tz.js

timezone sniffer in javascript.
JavaScript
6
star
88

git-packidx-parser

git pack index file parser
JavaScript
6
star
89

tar-parse

streaming tar parser
JavaScript
6
star
90

fpsjs

An in-browser multiplayer FPS using WebGL, pointer lock, WebSockets, and WebWorkers (oh my!)
JavaScript
6
star
91

scoped

command line tool exposing lexical-scope
JavaScript
6
star
92

dag-to-layers

assign each vertex of a dag to a layer, inserting dummy vertices
JavaScript
6
star
93

wilson-example

an example project using the wilson node.js framework
JavaScript
6
star
94

clone-packages

clone packages from one registry to another
JavaScript
6
star
95

pacman.js

A bitstream packer targeting canvas elements.
JavaScript
6
star
96

count-docula

An mdast-based tool for generating and testing documentation
JavaScript
6
star
97

cascadiajs-2013

my little parser talk abstract, transcript, demos for cascadiaJS 2013
JavaScript
6
star
98

spatial-trigger

enter/exit events for bounding boxes based on events from spatial-events
JavaScript
5
star
99

discard-stream

a transform stream that buffers up to N items, discarding on further writes
JavaScript
5
star
100

flows

a prototype streams implementation
JavaScript
5
star