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/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" }, 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