Skip to content

suchipi/sputter

 
 

Repository files navigation

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 } ]

About

CSS-like AST query library.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%