estree-halstead
v0.4.0
Published
Halstead complexity measures for ESTree
Downloads
52
Readme
estree-halstead
Halstead complexity measures for ESTree.
Calculate complexity using Halstead complexity measures from an ESTree-compliant AST.
💿 Installation
npm install estree-halstead
📖 Usage
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.