# @tokey/imports-parser

> parser for esm like imports

Latest version **2.0.0** (published 2025-11-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @tokey/imports-parser
pnpm add @tokey/imports-parser
yarn add @tokey/imports-parser
bun add @tokey/imports-parser
```

## Health

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

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

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2025-11-04 |
| First published | 2021-07-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 1 |
| Unpacked size | 25.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Dazl |
| Maintainers | tomrav, idoros, cijoe, avi.vahl |
| Keywords | parser, esm, imports |

## Links

- npm: https://www.npmjs.com/package/@tokey/imports-parser
- Repository: https://github.com/dazl-dev/tokey
- Homepage: https://github.com/dazl-dev/tokey#readme
- Issues: https://github.com/dazl-dev/tokey/issues
- npm.io page: https://npm.io/package/@tokey/imports-parser

## Dependencies (1)

- [@tokey/core](https://npm.io/package/@tokey/core.md) ^2.0.0

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2025-11-04
- 1.0.2 — 2025-11-04
- 1.0.1 — 2025-10-30
- 1.0.0 — 2022-12-19
- 0.1.2 — 2022-12-14
- 0.1.1 — 2022-12-14
- 0.1.0 — 2022-03-08
- 0.0.2 — 2021-08-16
- 0.0.1 — 2021-07-22

## README

# @tokey/imports-parser


Parser for `esm` like import syntax with support for "functional" tagged imports

```ts
import Name1, { Name2, Name3 as Name4, Tag(Name5) } from "request";
```

The output of parsing an import is represented with the following type:

```ts
interface ImportValue {
  star: boolean;
  defaultName: string | undefined;
  named: Record<string, string> | undefined;
  tagged: Record<string, Record<string, string>> | undefined;
  from: string | undefined;
  errors: string[];
  start: number;
  end: number;
}
```

 > Notice that this parser can parse broken/incomplete syntax and all the errors will be available in the "error" field.

 > The parser parses multiple imports and the result is an `ImportValue[]`


## API

```ts
import { parseImports, ImportValue } from "@tokey/imports-parser";

const code = `
    import { a } from "request/a";
    import "request/b";
`;
const startNamedBlock = '{'; // default
const endNamedBlock = '}'; // default
const shouldParseTags = false // default

const results: ImportValue[] = parseImports(code, startNamedBlock, endNamedBlock, shouldParseTags);

const firstImport = results[0];
firstImport.from === 'request/a'; // true
firstImport.named['a'] === 'a'; // true

```

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