Skip to content

Latest commit

 

History

History
65 lines (53 loc) · 2.41 KB

README.md

File metadata and controls

65 lines (53 loc) · 2.41 KB

Sputter

Sputter is a CSS-like selector library that lets you query an arbitrary AST.

Sputter is a fork of ESQuery.

The following selectors are supported:

Usage

const ast = {
  type: "Foo",
  children: [
    {
      type: "Bar",
      value: 5,
    },
  ],
};

const sputter = require("sputter");

sputter.query(ast, "Foo > Bar[value=5]"); // [ { type: "Bar", value: 5 } ]

If your ast uses a key other than type to identify the type of a node, use .configure:

const ast = {
  kind: "Foo",
  children: [
    {
      kind: "Bar",
      value: 5,
    },
  ],
};

const sputter = require("sputter").configure({
  identifierKey: "kind",
});

sputter.query(ast, "Foo > Bar[value=5]"); // [ { kind: "Bar", value: 5 } ]