typhonjs-escomplex
raw JSON → 0.1.0 verified Sat Apr 25 auth: no javascript
Next generation JavaScript and TypeScript complexity reporting module powered by the Babel parser. Version 0.1.0 is current, but this project appears to be in an early/alpha state with active development. It computes cyclomatic complexity, Halstead metrics, maintainability index, and dependency analysis. Unlike older complexity tools (e.g., escomplex), this uses the full Babel parser with all plugins enabled, supporting modern JS and TS syntax out of the box. The library is designed as a modular shim; separate sub-packages handle AST processing independently. Note that breaking report format changes occurred in 0.1.0.
Common errors
error TypeError: escomplex.analyzeModule is not a function ↓
cause Importing the module incorrectly (e.g., named import instead of default).
fix
Use
import escomplex from 'typhonjs-escomplex' or const escomplex = require('typhonjs-escomplex'). error SyntaxError: Unexpected token (1:1) while parsing ↓
cause Passing a file path string instead of source code content to analyzeModule.
fix
Read the file content first:
const source = fs.readFileSync(filePath, 'utf8'); then pass source. error Error: Could not find module: @babel/parser ↓
cause Missing @babel/parser peer dependency.
fix
Run
npm install @babel/parser (or yarn add) to install the peer dependency. Warnings
breaking Report format changed significantly in version 0.1.0. ↓
fix Review the 0.1.0 update guide at https://github.com/typhonjs-node-escomplex/typhonjs-escomplex/wiki/0.1.0-update-guide and adjust any consumers that parse the report structure.
deprecated This package is a shim over @babel/parser. For direct AST processing, use the individual sub-packages in the typhonjs-node-escomplex organization. ↓
fix If you need fine-grained control, use @babel/parser + typhonjs-escomplex-* modules directly.
gotcha The analyzeModule function expects source code as a string, not a file path. ↓
fix Use fs.readFileSync to read the file content before passing it.
gotcha Only CommonJS and ES module inputs are supported; no UMD or browser build provided. ↓
fix Use a bundler like webpack or rollup if you need to run in the browser.
Install
npm install typhonjs-escomplex yarn add typhonjs-escomplex pnpm add typhonjs-escomplex Imports
- escomplex wrong
import { escomplex } from 'typhonjs-escomplex';correctimport escomplex from 'typhonjs-escomplex'; - escomplex wrong
const { escomplex } = require('typhonjs-escomplex');correctconst escomplex = require('typhonjs-escomplex'); - analyzeModule wrong
escomplex.analyzeModule('source');correctescomplex.analyzeModule(source);
Quickstart
import escomplex from 'typhonjs-escomplex';
import { readFileSync } from 'fs';
const source = readFileSync('./example.js', 'utf8');
const report = escomplex.analyzeModule(source);
console.log(JSON.stringify(report, null, 2));