Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

CSSselect

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

CSSselect

a CSS selector compiler/engine

  • 0.4.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
49K
increased by12.52%
Maintainers
1
Weekly downloads
 
Created
Source

#CSSselect Build Status

a CSS selector compiler/engine

##What?

CSSselect turns CSS selectors into functions that tests if elements match them. When searching for elements, testing is executed "from the top", similar to how browsers execute CSS selectors.

In its default configuration, CSSselect queries the DOM structure of the domhandler module.

##API

var CSSselect = require("CSSselect");

####CSSselect(query, elems)

  • query can be either a function or a string. If it's a string, the string is compiled as a CSS selector.
  • elems can be either an array of elements, or a single element. If it is an element, its children will be used (so we're working with an array again).

Queries elems, returns an array containing all matches.

Aliases: CSSselect.selectAll(query, elems), CSSselect.iterate(query, elems).

####CSSselect.compile(query)

Compiles the query, returns the function.

####CSSselect.is(elem, query)

Tests whether or not an element is matched by query. query can be either a CSS selector or a function.

####CSSselect.selectOne(query, elems)

Arguments are the same as for CSSselect(query, elems). Only returns the first match, or null if there was no match.

##Why?

The common approach of executing CSS selectors (used eg. by Sizzle, nwmatcher and qwery) is to execute every component of the selector in order, from left to right. The selector a b for example will first look for a elements, then search these for b elements.

While this works, it has some downsides: Children of as will be checked multiple times, first, to check if they are also as, then, for every superior a once, if they are bs. Using Big O notation, that would be O(n^2).

The far more efficient approach is to first look for b elements, then check if they have superior a elements: Using big O notation again, that would be O(n).

And that's exactly what CSSselect does.

##How?

By stacking functions!

//TODO: Better explanation. For now, if you're interested, have a look at the source code.


License: BSD-like

Keywords

FAQs

Package last updated on 14 Feb 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc