From 007438e03ae05280d1da1179d6bbff48c239d887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Liszkai?= Date: Sun, 18 Feb 2024 02:29:24 +0000 Subject: [PATCH 1/2] fix: declare existing types output --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3ed0681..d495abf 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "email": "contact@simonrenoult.me" }, "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" }, From be7836c44314d4f3da9711fba3949bf6ced6fee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Liszkai?= Date: Sun, 18 Feb 2024 02:29:41 +0000 Subject: [PATCH 2/2] feat: add named exports Exposing the various types and classes for programatical usage with a shortcut for the complexity calculation. This should give a decent support for functional or object-oriented support while keeping the changes low. refs: #8 --- README.md | 19 +++++++++++++++++++ src/lib/index.ts | 18 ++++++++++++++++++ src/lib/{types.d.ts => types.ts} | 0 3 files changed, 37 insertions(+) rename src/lib/{types.d.ts => types.ts} (100%) diff --git a/README.md b/README.md index 505f630..2c2be53 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,25 @@ Note: `code-complexity` currently measures complexity using either: $ npx code-complexity [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 diff --git a/src/lib/index.ts b/src/lib/index.ts index 9965d47..7790d9a 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -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, +}; diff --git a/src/lib/types.d.ts b/src/lib/types.ts similarity index 100% rename from src/lib/types.d.ts rename to src/lib/types.ts