0.0.3 • Published 3 years ago
@gramex/escomplexity v0.0.3
ES Complexity
@gramex/escomplexity measures the cyclomatic complexity of your JavaScript / TypeScript code.
Usage
In a shell, run:
npx @gramex/escomplexityTo 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 thepathargumentcomplexity: 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 iftypeis"estimate".
Development
To run automated tests and validate the library:
npm install
npm testTo publish, run:
npm publishCreate 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.