Set operations for CSS selectors
npm install --save csset
Although this lib has been tested using the node's test runner it should work in all node and browser environments that support Set
and template literals
.
import { Csset } from 'csset';
// Create your sets
const set1 = new Csset('div > p');
const set2 = new Csset('div');
const set3 = new Csset('p');
// Make set operations
// supersetOf
console.assert(set1.supersetOf(set2) === false);
console.assert(set2.supersetOf(set1) === false);
console.assert(set3.supersetOf(set1) === true);
// subsetOf
console.assert(set1.subsetOf(set3) === true);
console.assert(set1.subsetOf(set2) === false);
// union
console.assert(set1.union(set3).toString() === 'p');
console.assert(set1.union(set2).toString() === 'div > p, div');
// intersection
console.assert(set1.intersection(set3).toString() === 'div > p');
console.assert(set1.intersection(set2) === undefined); // void means empty set
- As for now pseudo selectors are not supported
- Support for pseudo-classes
- consider other set operations (diff, complementary, ...)
- BREAKING CHANGE: the package has been migrated from TypeScript to
JavaScript + JsDocs for types. In this migration I've decided to make the
package ESM only so
require
would fail to load the lib. The new flag--experimental-require-module
can be used to load the lib if your app is incommonjs
format. Checkout the docs. - Embed the parser into the lib
- Add
intersection
API - Add
empty
properti to set class - Update demos
- Use
parsel-ts
to tokenize selectors
- Added build for ESM modules