# @xarc/resolve-alias

> set virtual module aliases for resolve and require

Latest version **1.0.0** (published 2020-05-15) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @xarc/resolve-alias
pnpm add @xarc/resolve-alias
yarn add @xarc/resolve-alias
bun add @xarc/resolve-alias
```

## 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.0.0 |
| Published | 2020-05-15 |
| First published | 2020-05-15 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Joel Chen |
| Maintainers | jchip |
| Keywords | virtual, module, modules, alias, aliases, require, resolve |

## Links

- npm: https://www.npmjs.com/package/@xarc/resolve-alias
- Repository: https://github.com/jchip/resolve-alias
- Homepage: https://github.com/jchip/resolve-alias#readme
- Issues: https://github.com/jchip/resolve-alias/issues
- npm.io page: https://npm.io/package/@xarc/resolve-alias

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2020-05-15

## README

# resolve alias

In some `lib/subdir1/subdir2/subdir3/foo.js` file:

Instead of:

```js
const blah = require("../../../bar.js");
```

you can do:

```js
const blah = require("$lib/bar.js");
```

By registering an alias `$lib` that points to the lib directory.

For example, you might do that in `lib/index.js`:

```js
const resolveAlias = require("@xarc/resolve-alias");
resolveAlias.add("$lib", __dirname); // make $lib an alias that point to the lib directory
```

- alias convention:

  1. cannot start with `.` or be an absolute path.
  2. cannot contain `/` except if it starts with `@`, then it can contain one `/` (ie: npm scope).
  3. cannot contain any space.

- default alias `_cwd` points to `process.cwd()`

- alias can provide a function:

```js
resolveAlias.add("_woo", (alias, requestPath, fullRequest) => {
  return "lib";
});
```

For example: `require("@alias/blah/lib/api.js")` would call the function with:

1. `alias`: `"@alias/blah"`
2. `requestPath`: `"lib/api.js"`
3. `fullRequest`: `"@alias/blah/lib/api.js"`

## enable/disable

```js
resolveAlias.enable = false;
```

## remove

```js
resolveAlias.remove("@foo");
```

# License

Licensed under the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0)

---

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