1.0.0-alpha.2 • Published 5 years ago
es-stats v1.0.0-alpha.2
es-stats
Find out import, exports and root declarations' dependency relationships of an ES module file.
Quick start
Intalling via npm:
npm i es-statsExtract 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:
dynamicImportclassPropertiesflowCommentsobjectRestSpreadfunctionBindjsxflow(.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.