@blocz/detect-imports
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

TL;DR

The goal of this library is to detect, in a JS code, the import statements, and parse them.

This is supposed to be used with MDX 1, so TypeScript is not supposed to be parsed (so syntaxes like import type or import { type A } won't be supported).

How to use:

Signature

detectImports(code: string): Promise<ImportDeclaration[]>

Example

import { detectImports } from "@blocz/detect-imports";

const string = `
import { a, A as As } from './a';
import { B,
    b } from 'b'

const nonImport = 'nonImport';
`;

await detectImports(string);
// This will return:
// [
//     {
//         imports: [
//             {
//                 imported: "a",
//                 local: "a",
//             },
//             {
//                 imported: "A",
//                 local: "As",
//             },
//         ],
//         module: "./a",
//     },
//     {
//         imports: [
//             {
//                 imported: "B",
//                 local: "B",
//             },
//             {
//                 imported: "b",
//                 local: "b",
//             },
//         ],
//         module: "b",
//     },
// ];

Readme

Keywords

none

Package Sidebar

Install

npm i @blocz/detect-imports

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

12.2 kB

Total Files

12

Last publish

Collaborators

  • ayc0