# es6-imports-renamer

> Renames paths from es6 import declarations.

Latest version **0.1.6** (published 2015-04-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install es6-imports-renamer
pnpm add es6-imports-renamer
yarn add es6-imports-renamer
bun add es6-imports-renamer
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2015-04-08 |
| First published | 2015-02-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.11.0 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Maira Bello |
| Maintainers | mairatma |
| Keywords | es6, import, module, rename |

## Links

- npm: https://www.npmjs.com/package/es6-imports-renamer
- Repository: https://github.com/mairatma/es6-imports-renamer
- Issues: https://github.com/mairatma/es6-imports-renamer/issues
- npm.io page: https://npm.io/package/es6-imports-renamer

## Dependencies (2)

- [recast](https://npm.io/package/recast.md) ^0.9.18
- [promise](https://npm.io/package/promise.md) ^6.1.0

## Recent versions

- 0.1.6 (latest) — 2015-04-08
- 0.1.5 — 2015-04-08
- 0.1.4 — 2015-04-08
- 0.1.3 — 2015-04-07
- 0.1.2 — 2015-04-07
- 0.1.1 — 2015-04-07
- 0.1.0 — 2015-02-16

## README

es6-imports-renamer
===================================

Renames paths from es6 import declarations.

## Usage

This tool can rename all sources from import declarations. This can be useful for mapping aliases to real file system paths.

To use it, just pass the asts of the files that should start the renaming process, and the rename function to be called on each import declaration. For example:

```javascript
var fs = require('fs');
var path = require('path');
var recast = require('recast');
var renamer = require('es6-imports-renamer');

function renameFn(originalPath, parentPath, callback) {
	callback(null, path.join(originalPath, 'index'));
}

var ast = recast.parse(fs.readFileSync('src/main'));
var options = {renameFn: renameFn, sources: [{ast: ast, path: 'src/main'}]};
renamer(options, function(error, resultAsts) {
	// Consume the renamed asts here.
});
```

The renamer will automatically load other needed dependencies and rename them as well.

## API

### config

- `basePath` **{string=}** Optional base path. If given, import sources will be renamed relative to it. Otherwise they will be renamed to absolute paths.
- `renameDependencies` **{boolean=}** Optional flag that indicates if dependencies declared on imports but not passed as sources should also be renamed. If so, the resulting asts for these dependencies will also be in the results array passed to `renameFn`.
- `renameFn` **{!function(Error, Array)}** The function to be used for renaming import sources. This function receives an error object as the first argument, or null if none was thrown. The second argument is an array with the resulting asts.
- `sources` **{!Array<{ast: !Object, path: string}>}** Contains the files that should start the renaming process. Each file should be represented as an object that points to that file's ast and its path.

### callback
Function to be called when the renaming is done.

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