npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

slick

v1.12.2

Published

Standalone CSS Selector Finder and Parser.

Downloads

4,586,303

Readme

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 }] }]
]