# esquery

> A query library for ECMAScript AST using a CSS selector like query language.

Latest version **1.7.0** (published 2025-12-31) · BSD-3-Clause license · 0 weekly downloads

## Install

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

## Health

**Score 58/100 (C)** — status: stable.

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.7.0 |
| Published | 2025-12-31 |
| First published | 2013-07-24 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | separate (@types/esquery) |
| Module format | ESM + CommonJS |
| Node | >=0.10 |
| Dependencies | 1 |
| Unpacked size | 1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 891 |
| Author | Joel Feenstra |
| Maintainers | jrfeenst, michaelficarra |
| Keywords | ast, ecmascript, javascript, query |

## Links

- npm: https://www.npmjs.com/package/esquery
- Repository: https://github.com/estools/esquery
- Homepage: https://github.com/estools/esquery/
- Issues: https://github.com/estools/esquery/issues
- npm.io page: https://npm.io/package/esquery

## Dependencies (1)

- [estraverse](https://npm.io/package/estraverse.md) ^5.1.0

## 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

- 1.7.0 (latest) — 2025-12-31
- 1.6.0 — 2024-07-08
- 1.5.0 — 2023-03-02
- 1.4.2 — 2023-02-16
- 1.4.1 — 2023-02-16
- 1.4.0 — 2021-02-05
- 1.3.1 — 2020-04-16
- 1.3.0 — 2020-04-15
- 1.2.1 — 2020-04-13
- 1.2.0 — 2020-03-23
- 1.1.0 — 2020-02-12
- 1.0.1 — 2018-04-02
- 1.0.0 — 2017-03-10
- 0.4.0 — 2015-05-05
- 0.3.0 — 2013-11-04
- … 3 more at https://npm.io/package/esquery/versions

## README

ESQuery is a library for querying the AST output by Esprima for patterns of syntax using a CSS style selector system. Check out the demo:

[demo](https://estools.github.io/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.*/]` or (with flags) `[attr=/foo.*/is]`
* attribute conditions: `[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)`
* [has](https://drafts.csswg.org/selectors-4/#has-pseudo): `:has(ForStatement)`, `:has(> ForStatement)`
* [matches-any](http://dev.w3.org/csswg/selectors4/#matches): `:is([attr] > :first-child, :last-child)`
* [subject indicator](http://dev.w3.org/csswg/selectors4/#subject): `!IfStatement > [name="foo"]`
* class of AST node: `:statement`, `:expression`, `:declaration`, `:function`, or `:pattern`

[![Build Status](https://travis-ci.org/estools/esquery.png?branch=master)](https://travis-ci.org/estools/esquery)

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