1.0.10 • Published 4 years ago
@rexlabs-spicerhaart/css-selector-eval v1.0.10
css-selector-eval
Partial implementation of the CSS Selector syntax.
Given a tree of nodes, with names & children, this can evaluate the best node-path from a selector.
It's main purpose is to evaluate if a given path of nodes will ever meet the conditions of a selector.
Example
import cssSelectorEval from '@rexlabs/css-selector-eval';
cssSelectorEval('Foo > Bar', {
{
name: 'Foo',
children: [
{ name: 'Bar' },
{ name: 'Baz' }
]
}
})
// { name: 'Foo', child: { name: 'Bar' } }
Syntax Support
- Element Type
- Child
- Descendant
- Class
- ID
- Attribute
- Adjacent Sibling
- Universal
- Pseudo Classes
- Pseudo Elements
- Multiple Selectors
Caveats
Currently, there is no support for evaluating against model's that nest a Selector's root Type.
eg. If you have a Selector "Foo > Bar
", then the model needs to start like { children: [ { name: 'Foo', children: [...] } ] }
.
Development
Install dependencies
$ yarn
Available Commands
$ yarn test # runs all units tests
$ yarn test:watch # runs unit tests when files change
$ yarn build # bundles the package for production
Legal
Forked from loklaan/css-selector-eval.
Copyright (c) 2017 Lochlan Bunn & Rex Software All Rights Reserved.
1.0.10
4 years ago