estree-halstead

Halstead complexity measures for ESTree

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
estree-halstead
830.4.0a month ago2 years agoMinified + gzip package size for estree-halstead in KB

Readme

estree-halstead
Halstead complexity measures for ESTree.
Calculate complexity using Halstead complexity measures from an ESTree-compliant AST.
NPM license NPM version NPM downloads NPM downloads NPM downloads NPM downloads NPM downloads Build Status

💿 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.