Cyclomatic complexity calculator for JavaScript projects
npm install @gramex/escomplexity@gramex/escomplexity measures the cyclomatic complexity of your JavaScript / TypeScript code.
In a shell, run:
``sh`
npx @gramex/escomplexity
To use in your JS code as an API:
`js`
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 the path 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 fileserror
- : the error object when parsing the file. Only if type is "estimate".
To run automated tests and validate the library:
`sh`
npm install
npm test
To publish, run:
`sh`
npm publish
Create a tests/js- folder. Add files to test there. Add a tests/js- that has the expected output of the test. Run npm test` to validate the test.