• Stars
    star
    217
  • Rank 182,446 (Top 4 %)
  • Language
    TypeScript
  • License
    BSD 2-Clause "Sim...
  • Created over 12 years ago
  • Updated 12 months ago

Reviews

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

Repository Details

a CSS selector parser

css-what

Node.js CI Coverage

A CSS selector parser.

Example

import * as CSSwhat from "css-what";

CSSwhat.parse("foo[bar]:baz")

~> [
    [
        { type: "tag", name: "foo" },
        {
            type: "attribute",
            name: "bar",
            action: "exists",
            value: "",
            ignoreCase: null
        },
        { type: "pseudo", name: "baz", data: null }
    ]
]

API

CSSwhat.parse(selector) - Parses selector.

The function returns a two-dimensional array. The first array represents selectors separated by commas (eg. sub1, sub2), the second contains the relevant tokens for that selector. Possible token types are:

name properties example output
tag name div { type: 'tag', name: 'div' }
universal - * { type: 'universal' }
pseudo name, data :name(data) { type: 'pseudo', name: 'name', data: 'data' }
pseudo name, data :name { type: 'pseudo', name: 'name', data: null }
pseudo-element name ::name { type: 'pseudo-element', name: 'name' }
attribute name, action, value, ignoreCase [attr] { type: 'attribute', name: 'attr', action: 'exists', value: '', ignoreCase: false }
attribute name, action, value, ignoreCase [attr=val] { type: 'attribute', name: 'attr', action: 'equals', value: 'val', ignoreCase: false }
attribute name, action, value, ignoreCase [attr^=val] { type: 'attribute', name: 'attr', action: 'start', value: 'val', ignoreCase: false }
attribute name, action, value, ignoreCase [attr$=val] { type: 'attribute', name: 'attr', action: 'end', value: 'val', ignoreCase: false }
child - > { type: 'child' }
parent - < { type: 'parent' }
sibling - ~ { type: 'sibling' }
adjacent - + { type: 'adjacent' }
descendant - { type: 'descendant' }
column-combinator - || { type: 'column-combinator' }

CSSwhat.stringify(selector) - Turns selector back into a string.


License: BSD-2-Clause

Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

css-what for enterprise

Available as part of the Tidelift Subscription

The maintainers of css-what and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

More Repositories

1

htmlparser2

The fast & forgiving HTML and XML parser
TypeScript
4,057
star
2

css-select

a CSS selector compiler & engine
TypeScript
548
star
3

domhandler

Handler for htmlparser2, to get a DOM
TypeScript
311
star
4

entities

Encode & decode HTML & XML entities with ease & speed
TypeScript
293
star
5

readabilitySAX

a fast and platform independent readability port (JS)
HTML
237
star
6

domutils

Utilities for working with htmlparser2's DOM
TypeScript
180
star
7

bitfield

A bitfield implementation using buffers, compliant with the BitTorrent spec.
TypeScript
80
star
8

nth-check

Parses and compiles CSS nth-checks to highly optimized functions.
TypeScript
52
star
9

cornet

transform streaming html using css selectors
JavaScript
44
star
10

domelementtype

all the types of nodes in htmlparser2's dom
TypeScript
27
star
11

high5

html 5 tokenizer
JavaScript
24
star
12

boolbase

two functions: one that returns true, one that returns false
JavaScript
14
star
13

inline

inline all images, stylesheets and scripts of a webpage
JavaScript
11
star
14

binopsy

Reimplementation of binary-parser supporting serialization and streaming
JavaScript
10
star
15

SimpleQueue

A simple FIFO queue
TypeScript
6
star
16

node-minreq

minimalistic request library for node
JavaScript
6
star
17

webshelf

my node knockout 2012 project
JavaScript
2
star
18

minschema

a (html form) schema builder & validator
JavaScript
1
star
19

node-fsi-dropbox

DEPRECATED
JavaScript
1
star
20

encoding-sniffer

HTML encoding sniffer, with stream support
TypeScript
1
star
21

fb55

Config files for my GitHub profile.
1
star
22

fb55.github.io

HTML
1
star
23

YQL-Tables-for-Google-Data-API

Tables to authenticate at and use the Google Data API
JavaScript
1
star
24

ReadableFeeds

runs readabilitySAX on feeds
JavaScript
1
star
25

level-insert

insert documents into a db with autoincrementing keys
JavaScript
1
star
26

funexp

UNFINISHED a functional regular expression library
JavaScript
1
star