Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/klzns/parse-es6-imports
Parse ES6 imports from a string
https://github.com/klzns/parse-es6-imports
import imports javascript parser
Last synced: 3 months ago
JSON representation
Parse ES6 imports from a string
- Host: GitHub
- URL: https://github.com/klzns/parse-es6-imports
- Owner: klzns
- Created: 2017-03-13T01:07:43.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-06-13T22:50:46.000Z (over 5 years ago)
- Last Synced: 2024-10-29T08:30:03.934Z (3 months ago)
- Topics: import, imports, javascript, parser
- Language: JavaScript
- Size: 5.86 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# parse-es6-imports [![Build Status](https://travis-ci.org/brenoc/parse-es6-imports.svg?branch=master)](https://travis-ci.org/brenoc/parse-es6-imports)
> Parse ES6 imports from a string
## Install
```sh
$ npm install parse-es6-imports --save
```### Usage
```js
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