code-complexity icon indicating copy to clipboard operation
code-complexity copied to clipboard

Support a programmable API

Open simonrenoult opened this issue 5 years ago • 1 comments

What problem are you trying to solve?

Since v4.0.0, if one wants to integrate code-complexity with another program, the recommended solution is to use the json flag, example:

const { execSync } = require("fs");
const raw = execSync("npx code-complexity ../foo/bar --format=json");
const result = JSON.parse(raw);

Which is not ideal since it feels a bit hacky and the datastructure is unknown from a user point of view.

Describe the feature

A cool way to do things would be to be able to import code-complexity as a dependency, example:

const codeComplexity = require('code-complexity');
const options = { directory: '../foo/bar' };
const result = await codeComplexity.compute(options);

I initially planned that feature for v4.0.0 but struggled with the TypeScript module system. Help definitely wanted :)

simonrenoult avatar May 03 '20 10:05 simonrenoult

I made a little improvement on the current export, mainly solving issues on using the package as a dependency in typescript. Adding documentation with JSDoc would likely be something to look at as well. Overall, the code is nicely readable, so for most people who want to use it programmatically, #57 should suffice.

adaliszk avatar Feb 18 '24 02:02 adaliszk