# sputter

> A library for querying any AST using a CSS-selector-like query language.

Latest version **0.0.1** (published 2019-05-22) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install sputter
pnpm add sputter
yarn add sputter
bun add sputter
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2019-05-22 |
| First published | 2019-05-22 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 90.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Suchipi |
| Maintainers | suchipi |
| Keywords | ast, query, css |

## Links

- npm: https://www.npmjs.com/package/sputter
- Repository: https://github.com/suchipi/sputter
- Homepage: https://github.com/suchipi/sputter#readme
- Issues: https://github.com/suchipi/sputter/issues
- npm.io page: https://npm.io/package/sputter

## Dependencies (2)

- [lodash.get](https://npm.io/package/lodash.get.md) ^4.4.2
- [make-module-env](https://npm.io/package/make-module-env.md) ^1.0.1

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 0.0.1 (latest) — 2019-05-22

## README

# Sputter

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

Sputter is a fork of [ESQuery](https://github.com/estools/esquery).

The following selectors are supported:

- AST node type: `ForStatement`
- [wildcard](http://dev.w3.org/csswg/selectors4/#universal-selector): `*`
- [attribute existence](http://dev.w3.org/csswg/selectors4/#attribute-selectors): `[attr]`
- [attribute value](http://dev.w3.org/csswg/selectors4/#attribute-selectors): `[attr="foo"]` or `[attr=123]`
- attribute regex: `[attr=/foo.*/]`
- attribute conditons: `[attr!="foo"]`, `[attr>2]`, `[attr<3]`, `[attr>=2]`, or `[attr<=3]`
- nested attribute: `[attr.level2="foo"]`
- field: `FunctionDeclaration > Identifier.id`
- [First](http://dev.w3.org/csswg/selectors4/#the-first-child-pseudo) or [last](http://dev.w3.org/csswg/selectors4/#the-last-child-pseudo) child: `:first-child` or `:last-child`
- [nth-child](http://dev.w3.org/csswg/selectors4/#the-nth-child-pseudo) (no ax+b support): `:nth-child(2)`
- [nth-last-child](http://dev.w3.org/csswg/selectors4/#the-nth-last-child-pseudo) (no ax+b support): `:nth-last-child(1)`
- [descendant](http://dev.w3.org/csswg/selectors4/#descendant-combinators): `ancestor descendant`
- [child](http://dev.w3.org/csswg/selectors4/#child-combinators): `parent > child`
- [following sibling](http://dev.w3.org/csswg/selectors4/#general-sibling-combinators): `node ~ sibling`
- [adjacent sibling](http://dev.w3.org/csswg/selectors4/#adjacent-sibling-combinators): `node + adjacent`
- [negation](http://dev.w3.org/csswg/selectors4/#negation-pseudo): `:not(ForStatement)`
- [matches-any](http://dev.w3.org/csswg/selectors4/#matches): `:matches([attr] > :first-child, :last-child)`
- [subject indicator](http://dev.w3.org/csswg/selectors4/#subject): `!IfStatement > [name="foo"]`
- `eval` for complex queries: `:eval('node.type === "Foo"')`

## Usage

```js
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`:

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

---
_Source: https://npm.io/package/sputter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
