sputter

0.0.1 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i sputter

Weekly Downloads

0

Version

0.0.1

License

BSD-3-Clause

Unpacked Size

92.3 kB

Total Files

7

Last publish

Collaborators

  • suchipi