detective-module

Get the dependencies specifier of an es6 module


Keywords
detective, es6, es2015, dependencies, module, ast, import
License
MIT
Install
npm install detective-module@2.2.0

Documentation

detective-module npm npm

Get the dependencies specifier of an ES6 module

npm install detective-module

Usage

var detective = require('detective-module');

var mySourceCode = fs.readFileSync('myfile.js', 'utf8');

// Pass in a file's content or an AST
var dependencies = detective(mySourceCode);

// input:
import Abc, * as BBBBBB from "mylib";

// output
[{
  "name": "mylib",
  "default": "Abc",
  "star": true,
  "alias": "BBBBBB"
}]

Example

// input:
import {foo as Foo, bar} from "mylib";

// output
[{
  "name": "mylib",
  "members": [{
    "name": "foo",
    "alias": "Foo"
  }, {
    "name": "bar",
    "alias": "bar"
  }]
}]

License

MIT