# core/validators/exemplar.validator.ts

> 24 lines of code and 5 definitions.

Tree: GovLab Context
Language: typescript
Layer: processing
Canonical: https://banes-lab.com/anatomy/context#file-context-core-validators-exemplar-validator-ts
Source text: https://banes-lab.com/source/context/core/validators/exemplar.validator.ts.txt

Listed in [core/validators](https://banes-lab.com/api/source/context/core/validators.md), after [core/validators/document.validator.ts](https://banes-lab.com/source/context/core/validators/document.validator.ts.md) and before [core/validators/field.validator.ts](https://banes-lab.com/source/context/core/validators/field.validator.ts.md).

## Definitions

- `exemplarGapsOf` (lexical_declaration, line 22, exported)
- `exemplarGap` (lexical_declaration, line 8)
- `CODE_SYNTAX` (lexical_declaration, line 5)
- `CODE_MEDIUM` (lexical_declaration, line 6)
- `{ exemplar }` (lexical_declaration, line 9)

## Contained in

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

## Used by

- [core/validators/ontology.validator.ts](https://banes-lab.com/source/context/core/validators/ontology.validator.ts.md)

## Linked from

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

## Source

```typescript
import type { AlgoGrammar, Contract } from "#types/algorithm.types";
import { CODELESS_EXEMPLAR, IDENTICAL_EXEMPLAR, MISSING_EXEMPLAR } from "#configuration/strings/validation.strings";
import type { ExemplarGap } from "#types/validation.types";

const CODE_SYNTAX = ["(", ")", "{", "}", ";", "="];
const CODE_MEDIUM = "code";

const exemplarGap = function exemplarGap(contract: Contract): ExemplarGap | null {
    const { exemplar } = contract;
    if (!exemplar || exemplar.before.trim() === "" || exemplar.after.trim() === "") {
        return { id: contract.id, reason: MISSING_EXEMPLAR };
    }
    if (exemplar.before.trim() === exemplar.after.trim()) {
        return { id: contract.id, reason: IDENTICAL_EXEMPLAR };
    }
    if (exemplar.medium === CODE_MEDIUM && !CODE_SYNTAX.some((token) => exemplar.after.includes(token))) {
        return { id: contract.id, reason: CODELESS_EXEMPLAR };
    }
    return null;
};

export const exemplarGapsOf = function exemplarGapsOf(algo: AlgoGrammar): ExemplarGap[] {
    return algo
        .all()
        .filter((entry) => entry.meta !== true)
        .flatMap((contract) => exemplarGap(contract) ?? []);
};
```
