Halstead complexity measures for ESTree.
Calculate complexity using Halstead complexity measures from an ESTree-compliant AST.
npm install estree-halstead
import { analyze } from 'estree-halstead'
import acorn from 'acorn'
const ast = acorn.parse(sourceCode, options); // https://github.com/acornjs/acorn
const result /* : Result */ = analyze(ast)
console.log(result)
// declare type Result = {
// vocabulary: number;
// length: number;
// volume: number;
// difficulty: number;
// effort: number;
// time: number;
// deliveredBugs: number;
// };
Note:
The calculation uses the AST, so tokens not included in the AST, such as semicolons and unwanted parenthesis tokens, are ignored.
This means that the calculation result is format independent.