0.1.0 • Published 1 year ago
csset v0.1.0
csset
Set operations for CSS selectors
Install
npm install --save cssetRequirements
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.
Usage
Basic
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 setKnown issues & limitations
- As for now pseudo selectors are not supported
Roadmap
- Support for pseudo-classes
- consider other set operations (diff, complementary, ...)
Release notes
0.1.0
- 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
requirewould fail to load the lib. The new flag--experimental-require-modulecan be used to load the lib if your app is incommonjsformat. Checkout the docs. - Embed the parser into the lib
- Add
intersectionAPI - Add
emptyproperti to set class - Update demos
0.0.10
- Use
parsel-tsto tokenize selectors
0.0.9
- Added build for ESM modules