This package has been deprecated

Author message:

It is merged into dom-lite. Use require('dom-lite/selector')

selector-lite

23.1.0 • Public • Published

Selector lite – Coverage Size Buy Me A Tea

DEPRECATED! It is merged into dom-lite. Use require('dom-lite/selector')

A small pure-JavaScript CSS selector engine.

  • no library dependencies
  • CSS 3 Selector support
  • only 2KB minified and 1KB gzipped

Examples

var selector = require("selector-lite")

// Can be used to implement browser built-in functions.

function getElementById(id) {
    return selector.find(this, "#" + id, true)
}
function getElementsByTagName(tag) {
    return selector.find(this, tag)
}
function getElementsByClassName(sel) {
    return selector.find(this, "." + sel.replace(/\s+/g, "."))
}
function querySelector(sel) {
    return selector.find(this, sel, true)
}
function querySelectorAll(sel) {
    return selector.find(this, sel)
}

Methods

  • selector.find(node, selector, returnFirstMatch) - Find matching elements like querySelector.
  • selector.matches(node, selector) - Returns a Boolean indicating whether or not the element would be selected by the specified selector string.
  • selector.closest(selector) - Returns the Element, descendant of this element (or this element itself), that is the closest ancestor of the elements selected by the selectors given in parameter.
  • selector.next(selector) - Retrieves the next sibling that matches selector.
  • selector.prev(selector) - Retrieves the preceding sibling that matches selector.

Custom selectors

Custom selector can be added to selector.selectorMap, where method shortcuts are available (m->matches, c->closest, n->next, p->prev).

  • _ - node.
  • v - part between () in :nth-child(2n+1).
  • a and b can be used as temp variables.
// Add `:input` selector
selector.selectorMap.input = "_.tagName=='INPUT'"

// Add `:val()` selector
selector.selectorMap.val = "_.value==v"

Contributing

Follow Coding Style Guidelines

Run tests

npm install
npm test

External links

GitHub repo | npm package | DOM spec | Selectors Level 3 | Coveralls coverage
Buy Me A Tea

Licence

Copyright (c) 2015-2021 Lauri Rooden <lauri@rooden.ee>
The MIT License

Dependencies (1)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i selector-lite

    Weekly Downloads

    29

    Version

    23.1.0

    License

    MIT

    Unpacked Size

    3.48 kB

    Total Files

    3

    Last publish

    Collaborators

    • lauriro