# core/loaders/representation.loader.ts

> 19 lines of code and 5 definitions.

Tree: GovLab Patterns
Language: typescript
Layer: infrastructure
Canonical: https://banes-lab.com/anatomy/patterns#file-patterns-core-loaders-representation-loader-ts
Source text: https://banes-lab.com/source/patterns/core/loaders/representation.loader.ts.txt

Listed in [core/loaders](https://banes-lab.com/api/source/patterns/core/loaders.md), after [core/loaders/record.loader.ts](https://banes-lab.com/source/patterns/core/loaders/record.loader.ts.md) and before [core/loaders/source.loader.ts](https://banes-lab.com/source/patterns/core/loaders/source.loader.ts.md).

## Definitions

- `loadPlugins` (lexical_declaration, line 9, exported)
- `PLUGIN_SUFFIXES` (lexical_declaration, line 7)
- `before` (lexical_declaration, line 10, exported)
- `files` (lexical_declaration, line 11, exported)
- `BUILTIN_REPRESENTATIONS` (lexical_declaration, line 22, exported)

## Contained in

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

## Uses

- [core/registries/representation.registry.ts](https://banes-lab.com/source/patterns/core/registries/representation.registry.ts.md)

## Linked from

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

## Source

```typescript
import { absolutePath } from "@ssot/paths";
import { definedRepresentations } from "#core/registries/representation.registry";
import { join } from "node:path";
import { pathToFileURL } from "node:url";
import { readdirSync } from "node:fs";

const PLUGIN_SUFFIXES: readonly string[] = [".ts", ".tsx", ".mts", ".cts"];

export const loadPlugins = async function loadPlugins(dir: string): Promise<string[]> {
    const before = new Set(definedRepresentations());
    const files = readdirSync(dir)
        .filter((name) => PLUGIN_SUFFIXES.some((suffix) => name.endsWith(suffix)))
        .toSorted((a, b) => a.localeCompare(b));
    await Promise.all(
        files.map(async (name): Promise<void> => {
            await import(pathToFileURL(join(dir, name)).href);
        }),
    );
    return definedRepresentations().filter((name) => !before.has(name));
};

export const BUILTIN_REPRESENTATIONS: readonly string[] = await loadPlugins(absolutePath("govlab.patterns.plugins"));
```
