bo-selector: CSS Selector Parser

0.0.10 · abandoned · verified Tue Apr 21

The `bo-selector` package provides a CSS selector parser capable of generating an Abstract Syntax Tree (AST) from a CSS selector string. It is built using `jison`, a parser generator, which is a development dependency, meaning the runtime package has no external dependencies. The package is currently at version 0.0.10 and has not seen updates since its last publish in October 2013, indicating it is an abandoned project. Its primary utility is to parse CSS selectors like `'p:has(.foo), b'` into a structured JavaScript object that represents the selector's components and relationships. It exclusively uses the CommonJS module system. Given its age and lack of maintenance, it is highly unlikely to support modern CSS selector features introduced after 2013, nor does it provide an ECMAScript Module (ESM) entry point, making integration into contemporary JavaScript projects challenging.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates parsing a CSS selector string into an Abstract Syntax Tree (AST) and inspecting its structure.

const parser = require('bo-selector').parser;
const util = require('util');

// Example CSS selector string
const cssSelector = 'p:has(.foo), b.bar[data-attr="value"]';

// Parse the CSS selector into an Abstract Syntax Tree (AST)
const ast = parser.parse(cssSelector);

// Log the generated AST in a human-readable format
console.log('Parsed AST:');
console.log(util.inspect(ast, { depth: null, colors: true }));

// Demonstrate accessing parts of the AST (simplified)
if (ast.type === 'selector_list' && ast.selectors.length > 0) {
  const firstSelectorElement = ast.selectors[0].element;
  console.log('\nFirst selector element name:', firstSelectorElement.name);
  if (firstSelectorElement.constraints && firstSelectorElement.constraints.length > 0) {
    console.log('First selector element constraints:', firstSelectorElement.constraints.map(c => c.type));
  }
}

view raw JSON →