0.0.3 • Published 1 year ago

@gramex/escomplexity v0.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

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 the path argument
  • complexity: the cyclomatic complexity of the file
  • type: 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 if type 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.