parse-es6-imports

1.0.1 • Public • Published

parse-es6-imports Build Status

Parse ES6 imports from a string

Install

$ npm install parse-es6-imports --save

Usage

const parseImports = require('parse-es6-imports')
 
const code = `
  import defaultA from './moduleA'
  import defaultB, { namedB } from './moduleB'
  import { namedC } from './moduleC'
  import { namedD as otherName } from './moduleD'
  import * as moduleE from './moduleE'
  import './moduleF'
`
 
const result = parseImports(code)
 
console.log(JSON.stringify(result, null, 2))
 
// [
//   {
//     "defaultImport": "defaultA",
//     "namedImports": [],
//     "starImport": null,
//     "fromModule": "./moduleA"
//   },
//   {
//     "defaultImport": "defaultB",
//     "namedImports": [
//       {
//         "name": "namedB",
//         "value": "namedB"
//       }
//     ],
//     "starImport": null,
//     "fromModule": "./moduleB"
//   },
//   {
//     "defaultImport": null,
//     "namedImports": [
//       {
//         "name": "namedC",
//         "value": "namedC"
//       }
//     ],
//     "starImport": null,
//     "fromModule": "./moduleC"
//   },
//   {
//     "defaultImport": null,
//     "namedImports": [
//       {
//         "name": "namedD",
//         "value": "otherName"
//       }
//     ],
//     "starImport": null,
//     "fromModule": "./moduleD"
//   },
//   {
//     "defaultImport": null,
//     "namedImports": [],
//     "starImport": "moduleE",
//     "fromModule": "./moduleE"
//   },
//   {
//     "defaultImport": null,
//     "namedImports": [],
//     "starImport": null,
//     "fromModule": "./moduleF"
//   }
// ]

License

MIT

Package Sidebar

Install

npm i parse-es6-imports

Weekly Downloads

6,088

Version

1.0.1

License

MIT

Last publish

Collaborators

  • breno