Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: DX improvements for programmable API #57

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ Note: `code-complexity` currently measures complexity using either:
$ npx code-complexity <path-to-git-directory or URL> [options]
```

or

```javascript
// CommonJS
const complexity = require("code-complexity")
const results = await complexity.compute({
target: "some/file/path"
})
```

```typescript
// ES Modules
import { analyze } from "code-complexity";

const results = await analyze({
target: "some/file/path"
})
```

## Help

```text
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"email": "[email protected]"
},
"main": "dist/src/lib",
"types": "dist/src/lib/types.d.ts",
"types": "dist/src/lib/index.d.ts",
"bin": {
"code-complexity": "dist/bin/code-complexity.js"
},
Expand Down
18 changes: 18 additions & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
import Statistics from "./statistics/statistics";
import Churns from "./churn/churns";
import Complexities from "./complexity/complexities";

// Expose shared type interfaces
export * from "./types";

// For CommonJS support: require("code-complexity")
export default Statistics;

// For ESM functional-style support: import { analyze } from "code-complexity";
export const analyze = Statistics.compute;
export const analyse = Statistics.compute;

// For ESM object-style: `import { Statistics } from "code-complexity"`
export {
Statistics,
// Expose these as they are dependencies for Statistics
Churns,
Complexities,
};
File renamed without changes.