# esm-ast-to-cjs

> Pure AST compiler for ESM to CJS

Latest version **0.0.2** (published 2020-08-14) · (Apache-2.0 AND MIT) license · 0 weekly downloads

## Install

```sh
npm install esm-ast-to-cjs
pnpm add esm-ast-to-cjs
yarn add esm-ast-to-cjs
bun add esm-ast-to-cjs
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2020-08-14 |
| First published | 2020-08-14 |
| Weekly downloads | 0 |
| License | (Apache-2.0 AND MIT) |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Mikeal Rogers |
| Maintainers | mikeal |

## Links

- npm: https://www.npmjs.com/package/esm-ast-to-cjs
- npm.io page: https://npm.io/package/esm-ast-to-cjs

## Recent versions

- 0.0.2 (latest) — 2020-08-14
- 0.0.1 — 2020-08-14
- 0.0.0 — 2020-08-14

## README

This library converts and the AST (Abstract Syntax Tree) of an
ESM program to CommonJS.

Note: Dynamic imports are not yet supported.

```js
import acorn from 'acorn'
import astring from 'astring'
import convert from 'esm-ast-to-cjs'

const script = `
import test from 'test'
export default test
`

const opts = { sourceType: 'module' }
const ast = acorn.parse(script, opts)
convert(ast)
const cjs = astring.generate(ast)
console.log(cjs)
// const test = require('test');\nmodule.exports = test'\n
```

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