Giter Site home page Giter Site logo

slick's Introduction

๐Ÿšจ๐Ÿšจ๐Ÿšจ

This fork exists solely to prevent the parser from infinitely looping when an invalid expression is parsed such as:

slick.parse('()')

๐Ÿšจ๐Ÿšจ๐Ÿšจ

Slick

Slick is a standalone selector engine that is totally slick. Slick is split in 2 components: the Finder and the Parser. The Finder's job is to find nodes on a webpage, the Parser's job is to create a javascript object representation of any css selector.

Slick allows you to:

  • Create your own custom pseudo-classes
  • Use the Parser by itself.
  • Find nodes in XML documents.

The Finder

Find nodes in the DOM

search context for selector

Search this context for any nodes that match this selector.

Expects:

  • selector: String or SelectorObject
  • (optional) context: document or node or array of documents or nodes
  • (optional) append: Array or Object with a push method

Returns: append argument or Array of 0 or more nodes

slick.search("#foo > bar.baz") โ†’ [<bar>, <bar>, <bar>]
slick.search("li > a", [<ol>, <ul>]) โ†’ [<a>, <a>, <a>]
slick.search("#foo > bar.baz", document, []) โ†’ [<bar>, <bar>, <bar>]

find first in context with selector or null

Find the first node in document that matches selector or null if none are found.

Expects:

  • selector: String or SelectorObject
  • (optional) context: document or node or array of documents or nodes

Returns: Element or null

slick.find("#foo > bar.baz") โ†’ <bar>
slick.find("#does-not-exist", node) โ†’ null

node matches selector?

Does this node match this selector?

Expects:

  • node
  • node, String or SelectorObject

Returns: true or false

slick.matches(<div class=rocks>, "div.rocks") โ†’ true
slick.matches(<div class=lame>, "div.rocks") โ†’ false
slick.matches(<div class=lame>, <div class=rocks>) โ†’ false

context contains node?

Does this context contain this node? Is the context a parent of this node?

Expects:

  • context: document or node
  • node: node

Returns: true or false

slick.contains(<ul>, <li>) โ†’ true
slick.contains(<body>, <html>) โ†’ false

The Parser

Parse a CSS selector string into a JavaScript object

parse selector into object

Parse a CSS Selector String into a Selector Object.

Expects: String

Returns: SelectorObject

slick.parse("#foo > bar.baz") โ†’ SelectorObject

format

#foo > bar.baz

[[
	{ "combinator":" ", "tag":"*", "id":"foo" },
	{ "combinator":">", "tag":"bar", "classList": ["baz"], "classes": [{"value":"baz", "match": RegExp }]}
]]

h1, h2, ul > li, .things

[
	[{ "combinator":" ", "tag": "h1" }],
	[{ "combinator":" ", "tag": "h2" }],
	[{ "combinator":" ", "tag": "ul" }, { "combinator": ">", "tag": "li" }],
	[{ "combinator":" ", "tag": "*", "classList": ["things"], "classes": [{"value": "things", "match": RegExp }] }]
]

slick's People

Contributors

appden avatar arian avatar chalkers avatar chuyeow avatar cpojer avatar fabiomcosta avatar gpbmike avatar ibolmotest avatar jeresig avatar kamicane avatar kassens avatar kentaromiura avatar kevinsawicki avatar koggdal avatar lostfx avatar martnu avatar n3o77 avatar sebmarkbage avatar subtlegradient avatar

Watchers

 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.