module-analyzr is a simple CLI and toolbox to analyze the usage of certain npm package.
Let's say you have code like this:
// index.js
import defaultExport from "test-module";
import * as name from "test-module";
import { export as alias } from "test-module";
import { export1, export2 } from "test-module";
import { export1 } from "test-module";
...
And you can analyze the usage of "test-module"
module-analyzr test-module index.js
=> {
importedModules: [
{ moduleName: 'export', usageAmount: 1 },
{ moduleName: 'export1', usageAmount: 2 },
{ moduleName: 'export2', usageAmount: 1 }
],
importedDefault: 1,
importedWithNameSpace: 1
}
npm install -g module-analyzr
After installing, you can use module-analyzr
command in any directory in your system:
Usage: module-analyzr <moduleName> <path> [options]
moduleName A name of module.
path File path or directory path or glob pattern
Options:
-i File path or directory path or glob pattern to ignore. Default: [node_modules]
--type=typescript passes typescript plugin to the parser
--type=flow passes flow plugin to the parser
# example and output
module-analyzr react src/**/*.js
{ importedModules:
[ { moduleName: 'Component', usageAmount: 10 },
{ moduleName: 'Node', usageAmount: 2 },
{ moduleName: 'Fragment', usageAmount: 1 } ],
importedDefault: 20,
importedWithNameSpace: 23 }
const analyzr = require('module-analyzr')
const usageInfo = analyzr('react', 'src/**/*.js')
Parameter | Description |
---|---|
importModules | Array of {moduleName: <string>, usageAmount: <number>} which shows usage count of named export. |
importedDefault | Number of usage count of default exports |
importedWithNameSpace | Number of usage count of named export, but all of exports with * (eg. import * as Module from 'module' ). |
module-analyzr
is simple tool to analyze usage of a module in a file or directory(likely project). It is helpful for module's maintainer to grasp how their module used in projects. Also, it is helpful for application engineer when upgrade the module or remove the module.
In my case, as a creator of UI Library, it was nervous to add a breaking change. That is why I created module-analyzr
.
MIT