# ascjs

> ES2015 to CommonJS import/export transformer

Latest version **6.0.3** (published 2023-10-23) · ISC license · 0 weekly downloads

## Install

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

Provides the command `ascjs`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score; declining downloads.

## Facts

| | |
|---|---|
| Version | 6.0.3 |
| Published | 2023-10-23 |
| First published | 2017-10-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 15.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 59 |
| Author | Andrea Giammarchi |
| Maintainers | webreflection |
| Keywords | cjs, esm, transpile, convert, safe, module |

## Links

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

## Dependencies (1)

- [@babel/parser](https://npm.io/package/@babel/parser.md) ^7.12.5

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

- 6.0.3 (latest) — 2023-10-23
- 6.0.2 — 2023-06-30
- 6.0.1 — 2023-06-30
- 6.0.0 — 2023-06-30
- 5.0.1 — 2021-02-12
- 5.0.0 — 2021-01-26
- 4.0.3 — 2020-11-04
- 4.0.2 — 2020-11-04
- 4.0.1 — 2020-05-12
- 4.0.0 — 2020-04-16
- 3.1.2 — 2019-11-23
- 3.1.1 — 2019-11-23
- 3.1.0 — 2019-10-25
- 3.0.1 — 2019-04-16
- 3.0.0 — 2019-01-11
- … 25 more at https://npm.io/package/ascjs/versions

## README

# ascjs

[![License: ISC](https://img.shields.io/badge/License-ISC-yellow.svg)](https://opensource.org/licenses/ISC) [![Build Status](https://travis-ci.org/WebReflection/ascjs.svg?branch=master)](https://travis-ci.org/WebReflection/ascjs) [![Coverage Status](https://coveralls.io/repos/github/WebReflection/ascjs/badge.svg?branch=master)](https://coveralls.io/github/WebReflection/ascjs?branch=master) [![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000&style=flat)](https://github.com/WebReflection/donate) [![Greenkeeper badge](https://badges.greenkeeper.io/WebReflection/ascjs.svg)](https://greenkeeper.io/)

ES2015 to CommonJS import/export transformer

- - -

### Looking for a CommonJS minimalistic bundler ?

Fully based on _ascjs_, **[asbundle](https://github.com/WebReflection/asbundle)** is a no-brainer to create out of the box browser compatible bundles. Don't miss it out!

- - -

This module does one thing only:
it loosely transpiles **ES2015** [import](https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/import)/[export](https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export) statements **into** valid **CommonJS** in order to fix the only part of Node that's incompatible with modern JS.

## How to

You can use _ascjs_ as binary utility or as module.

```sh
npm install -g ascjs

# to see what you can do
ascjs --help

```

As executable, you can use _ascjs_ to output, or save, some code content.
```sh
ascjs code
ascjs --ignore=a.js,b.js sourceFile
ascjs --no-default
ascjs sourceFile
ascjs sourceFile destFile

# folders are recursively parsed
# destFolder is mandatory
ascjs sourceFolder destFolder
```

You can also use it via pipe operator.
```sh
echo code | ascjs
cat source.js | ascjs | uglifyjs -o dest.js
```

As module, you can require it and use it to convert ESM to CJS.
```js
const ascjs = require('ascjs');

ascjs('import "test";');
// require("test");
```

### Features

  * extremely lightweight, based on [babylon](https://github.com/babel/babylon) for performance and reliability, it transforms only imports/exports ignoring everything else
  * produces modern JavaScript, you are in charge of extra transformations if needed
  * indentation, spaces, semi or no-semi are preserved: beautiful source code remains beautiful
  * uses same [Babel](http://babeljs.io) convention, resolving `export default ...` intent as `exports.default`
  * you can finally write `.js` code and transform it for Node only before publishing on _npm_
  * you could write `.mjs` modules and transform them into CommonJS for [Browserify](http://browserify.org) or other bundlers as target

### Constrains

  * live bindings for exported values are not preserved. You need to delegate in scope eventual changes
  * dynamic `import(...)` is untouched. If you write that, let [Webpack](https://webpack.js.org) handle it for you later on
  * there is no magic whatsoever in module names resolution, what you write in ESM is what you get as CJS

### Flags

  * `--ignore=...` a comma separated paths to ignore parsing
  * `--no-default` remove the `__esModule` flag and export default via `module.exports = `

### Example
This module can transform the following ES2015+ code
```js
import func, {a, b} from './module.js';
import * as tmp from 'other';

const val = 123;

export default function test() {
  console.log('ascjs');
};

export {func, val};
```
into the following one:
```js
'use strict';
const func = (m => m.__esModule ? m.default : m)(require('./module.js'));
const {a, b} = require('./module.js');
const tmp = require('other');

const val = 123;

function test() {
  console.log('ascjs');
}
Object.defineProperty(exports, '__esModule', {value: true}).default = test;

exports.func = func;
exports.val = val;
```

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