# domain/converters/coverage.converter.ts

> 62 lines of code and 7 definitions.

Tree: Site tree
Language: typescript
Layer: processing
Canonical: https://banes-lab.com/anatomy/tree#file-domain-converters-coverage-converter-ts
Source text: https://banes-lab.com/source/tree/domain/converters/coverage.converter.ts.txt

Listed in [domain/converters](https://banes-lab.com/api/source/tree/domain/converters.md), after [domain/converters/contract.converter.ts](https://banes-lab.com/source/tree/domain/converters/contract.converter.ts.md) and before [domain/converters/document.converter.ts](https://banes-lab.com/source/tree/domain/converters/document.converter.ts.md).

## Definitions

- `labelOf` (lexical_declaration, line 50)
- `coverageRow` (lexical_declaration, line 58, exported)
- `COLLECTION_LABELS` (lexical_declaration, line 30)
- `QUESTION_LABELS` (lexical_declaration, line 38)
- `label` (lexical_declaration, line 51)
- `parts` (lexical_declaration, line 59, exported)
- `counted` (lexical_declaration, line 60, exported)

## Uses

- [configuration/strings/ontology.strings.ts](https://banes-lab.com/source/tree/configuration/strings/ontology.strings.ts.md)

## Source

```typescript
import {
    ALGORITHMS_LABEL,
    DECLARED_ABSENT_LABEL,
    FIELD_SEPARATOR,
    GRAMMAR_LABEL,
    LABEL_SEPARATOR,
    LEXICON_LABEL,
    LIST_SEPARATOR,
    OF_LABEL,
    PRINCIPLES_LABEL,
    REASONING_LABEL,
    unlabeledCoverage,
} from "#configuration/strings/ontology.strings";
import { ALGO_FACE, ARCH_FACE, LEX_FACE, PAG_FACE, REASON_FACE } from "@govlab/constants";
import {
    CHECK_AUTHORITY_LABEL,
    CHECK_BY_LABEL,
    CHECK_DEPENDS_ON_LABEL,
    CHECK_EVIDENCE_LABEL,
    CHECK_FRESHNESS_LABEL,
    CHECK_OBSERVATION_LABEL,
    CHECK_POPULATION_LABEL,
    CHECK_REFUSAL_LABEL,
    CHECK_SHAPE_LABEL,
} from "#configuration/strings/reference.strings";
import type { CoverageView } from "#types/coverage.types";
import type { GlossaryEntry } from "#types/block.types";
import { row } from "#domain/converters/ontology.converter";

const COLLECTION_LABELS: ReadonlyMap<string, string> = new Map([
    [ARCH_FACE, PRINCIPLES_LABEL],
    [LEX_FACE, LEXICON_LABEL],
    [ALGO_FACE, ALGORITHMS_LABEL],
    [REASON_FACE, REASONING_LABEL],
    [PAG_FACE, GRAMMAR_LABEL],
]);

const QUESTION_LABELS: ReadonlyMap<string, string> = new Map([
    ["by", CHECK_BY_LABEL],
    ["population", CHECK_POPULATION_LABEL],
    ["freshness", CHECK_FRESHNESS_LABEL],
    ["refusal", CHECK_REFUSAL_LABEL],
    ["observation", CHECK_OBSERVATION_LABEL],
    ["evidence", CHECK_EVIDENCE_LABEL],
    ["authority", CHECK_AUTHORITY_LABEL],
    ["shape", CHECK_SHAPE_LABEL],
    ["dependsOn", CHECK_DEPENDS_ON_LABEL],
]);

const labelOf = function labelOf(labels: ReadonlyMap<string, string>, id: string): string {
    const label = labels.get(id);
    if (label === undefined) {
        throw new Error(unlabeledCoverage(id));
    }
    return label;
};

export const coverageRow = function coverageRow(entry: CoverageView): GlossaryEntry {
    const parts = entry.questions.map((question) => {
        const counted = `${labelOf(QUESTION_LABELS, question.question).toLowerCase()}${LABEL_SEPARATOR}${String(question.answered)} ${OF_LABEL} ${String(entry.records)}`;
        return question.declaredAbsent === 0
            ? counted
            : `${counted}${LIST_SEPARATOR}${String(question.declaredAbsent)} ${DECLARED_ABSENT_LABEL}`;
    });
    return row(labelOf(COLLECTION_LABELS, entry.collection), parts.join(FIELD_SEPARATOR));
};
```
