# core/registries/card.registry.ts

> 19 lines of code and 6 definitions.

Tree: Bane's Lab Social Share
Language: typescript
Layer: infrastructure
Canonical: https://banes-lab.com/anatomy/social-share#file-social-share-core-registries-card-registry-ts
Source text: https://banes-lab.com/source/social-share/core/registries/card.registry.ts.txt

Listed in [core/registries](https://banes-lab.com/api/source/social-share/core/registries.md).

## Definitions

- `listCards` (lexical_declaration, line 18, exported)
- `repeatedCards` (lexical_declaration, line 22, exported)
- `cards` (lexical_declaration, line 4)
- `repeated` (lexical_declaration, line 5)
- `registerCard` (lexical_declaration, line 7, exported)
- `getCard` (lexical_declaration, line 14, exported)

## Contained in

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

## Used by

- [core/loaders/card.loader.ts](https://banes-lab.com/source/social-share/core/loaders/card.loader.ts.md)

## Linked from

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

## Source

```typescript
import type { CardSpec, RegisteredCard } from "#types/card.types";
import { createRegistry } from "@banes-lab/web/domain/registries/base.registry.ts";

const cards = createRegistry<RegisteredCard>();
const repeated = new Set<string>();

export const registerCard = function registerCard(spec: CardSpec, origin: string): void {
    if (cards.byId(spec.id) !== undefined) {
        repeated.add(spec.id);
    }
    cards.register({ id: spec.id, origin, spec });
};

export const getCard = function getCard(id: string): RegisteredCard | undefined {
    return cards.byId(id);
};

export const listCards = function listCards(): readonly RegisteredCard[] {
    return cards.all().toSorted((a, b) => a.id.localeCompare(b.id));
};

export const repeatedCards = function repeatedCards(): readonly string[] {
    return [...repeated];
};
```
