0.0.1 • Published 5 years ago

sputter v0.0.1

Weekly downloads
2
License
BSD-3-Clause
Repository
github
Last release
5 years ago

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

5 years ago