# ast-module-types

> Collection of useful helper functions when trying to determine module type (CommonJS or AMD) properties of an AST node.

Latest version **7.0.0** (published 2026-05-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install ast-module-types
pnpm add ast-module-types
yarn add ast-module-types
bun add ast-module-types
```

## Health

**Score 55/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 7.0.0 |
| Published | 2026-05-19 |
| First published | 2014-03-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | >=20.19.0 \|\| >=22.12.0 |
| Dependencies | 0 |
| Unpacked size | 11.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Joel Kemp |
| Maintainers | pahen, mrjoelkemp, xhmikosr |
| Keywords | esprima, module, type, define, require, factory |

## Links

- npm: https://www.npmjs.com/package/ast-module-types
- Repository: https://github.com/dependents/node-ast-module-types
- Issues: https://github.com/dependents/node-ast-module-types/issues
- npm.io page: https://npm.io/package/ast-module-types

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 7.0.0 (latest) — 2026-05-19
- 6.0.2 — 2026-05-09
- 6.0.1 — 2025-02-01
- 6.0.0 — 2024-04-09
- 5.0.0 — 2023-05-04
- 4.0.0 — 2023-03-19
- 3.0.0 — 2022-02-22
- 2.7.1 — 2020-11-01
- 2.7.0 — 2020-10-26
- 2.6.0 — 2019-11-23
- 2.5.0 — 2019-02-04
- 2.4.0 — 2018-09-25
- 2.3.2 — 2016-06-16
- 2.3.1 — 2016-06-16
- 2.3.0 — 2015-07-04
- … 10 more at https://npm.io/package/ast-module-types/versions

## README

# ast-module-types

[![CI](https://img.shields.io/github/actions/workflow/status/dependents/node-ast-module-types/ci.yml?branch=main&label=CI&logo=github)](https://github.com/dependents/node-ast-module-types/actions/workflows/ci.yml?query=branch%3Amain)
[![npm version](https://img.shields.io/npm/v/ast-module-types?logo=npm&logoColor=fff)](https://www.npmjs.com/package/ast-module-types)
[![npm downloads](https://img.shields.io/npm/dm/ast-module-types)](https://www.npmjs.com/package/ast-module-types)

Collection of useful helper functions when trying to determine module type (CommonJS or AMD) properties of an AST node.

**AST checks are based on the Esprima (Spidermonkey) format**

```sh
npm install ast-module-types
```

## API

Each of these takes in a single AST node argument and returns a boolean.

* `isDefineAMD`: if node matches any form of an AMD `define` function call
* `isRequire`: if node matches a `require` function call (declaring a dependency)
* `isTopLevelRequire`: if node matches a `require` at the very top of the file.
* `isAMDDriverScriptRequire`: if node matches an AMD driver script's require call `require([deps], function)`
* `isExports`: if the node matches CommonJS `module.exports` or `exports` (defining a module)

Detecting the various forms of defining an AMD module

* `isNamedForm`: if the node is a define call of the form: `define('name', [deps], func)`
* `isDependencyForm`: if the node is a define call of the form: `define([deps], func)`
* `isFactoryForm`: if the node is a define call of the form: `define(func(require))`
* `isNoDependencyForm`: if the node is a define call of the form: `define({})`
* `isREMForm`: if the node matches the form: `define(function(require, exports, module){});`

ES6 Types

*All types abide by the [EStree spec](https://github.com/estree/estree/blob/master/es2015.md)*

* `isES6Import`: if the node is any of the es6 import forms
* `isES6Export`: if the node is of any es6 export forms
* `isDynamicImport`: if the node is a dynamic `import()` call

## Usage

### ESM

```js
import { isDefineAMD } from 'ast-module-types';

// Assume node is some node of an AST that you parsed using esprima or esprima-fb
// ...

console.log(isDefineAMD(node));
```

### CommonJS

```js
const { isDefineAMD } = require('ast-module-types');

// Assume node is some node of an AST that you parsed using esprima or esprima-fb
// ...

console.log(isDefineAMD(node));
```

## License

[MIT](LICENSE)

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