0.0.0 • Published 8 years ago

runegrid.css-query-object v0.0.0

Weekly downloads
2
License
ISC
Repository
-
Last release
8 years ago

css-query-object

Query plain objects with CSS selectors.

Install

npm install runegrid.css-query-object

Usage

var CQO = require('runegrid.css-query-object');

// A nested object representing a document tree
var hello = {
    tagName: 'foo',
    attrs: {
        id: 'bar'
    },
    children: [
        { name: 'baz' }
    ]
};

// Tells the searcher which properties to check. The key
// is what the library calls the property, the value is
// whatever name your object uses for the equivalent.
var PROP_MAP = {
    name: 'tagName',
    attributes: 'attrs',
    children: 'children'
};

var elements = CSQ({}, hello, '#bar', PROP_MAP);

Features

The library currently supports querying by...

  • Tag name, e.g. div
  • Class name, e.g. .my_class
  • Id, e.g. #my-id

You can also pass a comma-separated list of these.

Other more advanced selectors aren't available (yet).

0.0.0

8 years ago