# core/classifiers/package.classifier.ts

> 21 lines of code and 5 definitions.

Tree: GovLab Docs
Language: typescript
Layer: application
Canonical: https://banes-lab.com/anatomy/docs#file-docs-core-classifiers-package-classifier-ts
Source text: https://banes-lab.com/source/docs/core/classifiers/package.classifier.ts.txt

Listed in [core/classifiers](https://banes-lab.com/api/source/docs/core/classifiers.md).

## Definitions

- `keysOf` (lexical_declaration, line 11)
- `shapeOf` (lexical_declaration, line 15, exported)
- `exported` (lexical_declaration, line 16, exported)
- `inFullStack` (lexical_declaration, line 17, exported)
- `siblings` (lexical_declaration, line 21, exported)

## Contained in

- [core/classifiers](https://banes-lab.com/anatomy/docs/folder-docs-core-classifiers.md)

## Uses

- [core/predicates/record.predicate.ts](https://banes-lab.com/source/docs/core/predicates/record.predicate.ts.md)

## Linked from

- [core/predicates](https://banes-lab.com/anatomy/docs/folder-docs-core-predicates.md)

## Source

```typescript
import {
    FRAMEWORK_SIBLING_THRESHOLD,
    FULL_STACK_EXPORTS,
    FULL_STACK_SEGMENT,
} from "#configuration/constants/figure.constants";
import { normalize, sep } from "node:path";
import { PACKAGE_SCOPE } from "#configuration/constants/manifest.constants";
import type { PackageShape } from "#types/figure.types";
import { isPlainRecord } from "#core/predicates/record.predicate";

const keysOf = function keysOf(value: unknown): string[] {
    return isPlainRecord(value) ? Object.keys(value) : [];
};

export const shapeOf = function shapeOf(moduleDir: string, pkg: Record<string, unknown>): PackageShape {
    const exported = new Set(keysOf(pkg["exports"]));
    const inFullStack = normalize(moduleDir).split(sep).includes(FULL_STACK_SEGMENT);
    if (inFullStack || FULL_STACK_EXPORTS.every((key) => exported.has(key))) {
        return "full-stack";
    }
    const siblings = keysOf(pkg["dependencies"]).filter((dep) => dep.startsWith(PACKAGE_SCOPE));
    return siblings.length >= FRAMEWORK_SIBLING_THRESHOLD ? "framework" : "leaf";
};
```
