@gramex/escomplexity
v0.0.3
Published
Cyclomatic complexity calculator for JavaScript projects
Downloads
5
Maintainers
Readme
ES Complexity
@gramex/escomplexity
measures the cyclomatic complexity of your JavaScript / TypeScript code.
Usage
In a shell, run:
npx @gramex/escomplexity
To use in your JS code as an API:
import { esComplexity } from "@gramex/escomplexity";
for await (const result of esComplexity(path)) {
// process result for each file under path
}
esComplexity() returns an async iterator that yields results for each file under path
. Each result is an object with the following keys:
path
: the path of the file relative to thepath
argumentcomplexity
: the cyclomatic complexity of the filetype
: this can be"complexity"
if the complexity is calculated"estimate"
if the file could not be processed, and the complexity is estimated based on lines of code"total"
if it's the total entry summing up all files
error
: the error object when parsing the file. Only iftype
is"estimate"
.
Development
To run automated tests and validate the library:
npm install
npm test
To publish, run:
npm publish
Create a tests/js-<anything>
folder. Add files to test there. Add a tests/js-<anything>/expected.json
that has the expected output of the test. Run npm test
to validate the test.