Options
All
  • Public
  • Public/Protected
  • All
Menu

Jennie's ast lab

es-stats

Find out import, exports and root declarations' dependency relationships of an ES module file.

Quick start

Intalling via npm:

npm i es-stats

Extract imports, exports, and root declarations' relationship with default settings:

const esStats = require('es-stats');
const fs = require('fs');

const { imports, exports, relations } = esStats(
  fs.readFileSync('myfile.js', 'utf-8')
);
console.log('Imports:', imports);
console.log('Exports:', exports);
console.log('Relations:', relations);

To support things like JSX, flow, dynamic imports, etc.. You will need to enable @babel/parser plugins:

const { imports, exports, relations } = esStats(
  fs.readFileSync('myfile.js', 'utf-8'),
  {
    plugins: ['jsx', 'dynamicImport'],
  }
);

Following plugins are enabled on .js|.jsx|.ts|.tsx files by default:

  • dynamicImport
  • classProperties
  • flowComments
  • objectRestSpread
  • functionBind
  • jsx
  • flow (.js and .jsx only)
  • typescript (.ts and .tsx only)

All the options in the 2nd parameter will be passed to @babel/parser directly. @babel/parser options can be found here.

Generated using TypeDoc