parse-imports-ts
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

Identifies the packages imported form a TypeScript file

Detects top level imports

import { parse } from "parse-imports-ts";

const input = `
    import "import _ from "lodash";"
    import 'core-js';
`;
const output = parse(input);
console.log(JSON.stringify(output));
//[
//  { name: "lodash", type: 0},
//  { name: "core-js", type: 0}
//]

Detects dynamic imports

import { parse } from "parse-imports-ts";

const input = `
    export function myFunction() {
        return import("my-package");
    }
`;
const output = parse(input);
console.log(JSON.stringify(output));
//[
//  { name: "my-package", type: 0}
//]

Detects type imports

import { parse } from "parse-imports-ts";

const input = `
    import type { MyType } from "my-pacakge";
`;
const output = parse(input);
console.log(JSON.stringify(output));
//[
//  { name: "my-package", type: 1}
//]

Readme

Keywords

none

Package Sidebar

Install

npm i parse-imports-ts

Weekly Downloads

440

Version

1.0.4

License

MIT

Unpacked Size

48.5 kB

Total Files

49

Last publish

Collaborators

  • ncochard