# ast-test

> Test ast node on some condition

Latest version **1.1.1** (published 2015-02-19) · Unlicensed license · 0 weekly downloads

## Install

```sh
npm install ast-test
pnpm add ast-test
yarn add ast-test
bun add ast-test
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2015-02-19 |
| First published | 2015-02-19 |
| Weekly downloads | 0 |
| License | Unlicensed |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Deema Ywanov |
| Maintainers | dfcreative |
| Keywords | ast, test, esprima, estools |

## Links

- npm: https://www.npmjs.com/package/ast-test
- Repository: https://github.com/dfcreative/ast-test
- Issues: https://github.com/dfcreative/ast-test/issues
- npm.io page: https://npm.io/package/ast-test

## Dependencies (1)

- [ast-types](https://npm.io/package/ast-types.md) ^0.6.14

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2015-02-19
- 1.1.0 — 2015-02-19
- 1.0.0 — 2015-02-19

## README

# ast-test [![Build Status](https://travis-ci.org/dfcreative/ast-test.svg?branch=master)](https://travis-ci.org/dfcreative/ast-test) [![unstable](http://badges.github.io/stability-badges/dist/unstable.svg)](http://github.com/badges/stability-badges)

Test source tree on passing some condition.


## Use

`$ npm install --save ast-test`

```js
var parse = require('esprima').parse;
var test = require('ast-test');

//catch all `foo` assignments
var rule = {
	AssignmentExpression: function (node) {
		if (node.operator !== '=') return false;
		return node.left.name === 'foo';
	}
};

test(parse('foo = 1;').body[0], rule) //true
test(parse('var foo = 1;').body[0], rule) //false
```


## API

### test(Node, testRules) → Boolean

Test whether node passes test rules passed. `testRules` is an object containing node types as keys and testing functions as values. Matched nodes are tested with according testing functions, and if matched none — test returns false. You can declare node supertypes to match, in that case they will be checked beforehead.

```js
var rule = {
	Expression: function (node) {
		return true;
	},
	AssignmentExpression: function (node) {
		if (node.operator !== '=') return false;
		return node.left.name === 'foo';
	}
};

test(parse('foo = 1;').body[0].expression, rule); //true
test(parse('bar = 1;').body[0].expression, rule); //false
test(parse('var foo = 1;').body[0], rule); //false
```


[![NPM](https://nodei.co/npm/ast-test.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/ast-test/)

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