# tools/core/resolvers/corpus.resolver.ts

> 59 lines of code and 11 definitions.

Tree: Coordination tree
Language: typescript
Layer: infrastructure
Canonical: https://banes-lab.com/anatomy/coordination#file-coordination-tools-core-resolvers-corpus-resolver-ts
Source text: https://banes-lab.com/assets/sources/source.519bbd284781050f66b103e78414396df600cfda8ca71d3d5115670bff2af092.generated.txt

## Definitions

- `nameParts` (lexical_declaration, line 6, exported)
- `keyFromSymbol` (lexical_declaration, line 59, exported)
- `SEPARATOR` (lexical_declaration, line 4)
- `parts` (lexical_declaration, line 7, exported)
- `held` (lexical_declaration, line 8, exported)
- `rawFacetOf` (lexical_declaration, line 24, exported)
- `symbolOf` (lexical_declaration, line 44, exported)
- `value` (lexical_declaration, line 50, exported)
- `key` (lexical_declaration, line 60, exported)
- `index` (lexical_declaration, line 62, exported)
- `character` (lexical_declaration, line 63, exported)

## Used by

- [tools/core/entrypoints/corpus.entrypoint.ts](https://banes-lab.com/source/coordination/tools/core/entrypoints/corpus.entrypoint.ts.md)

## Source

```typescript
import type { CorpusRootData } from "../types/taxonomy.types.ts";
import type { Document } from "../types/segment.types.ts";

const SEPARATOR = ".";

export const nameParts = function nameParts(name: string): string[] {
    const parts: string[] = [];
    let held = "";

    for (let index = 0; index < name.length; index += 1) {
        const character = name.charAt(index);
        if (character === SEPARATOR) {
            parts.push(held);
            held = "";
            continue;
        }
        held += character;
    }
    parts.push(held);

    return parts;
};

export const rawFacetOf = function rawFacetOf(document: Document, config: CorpusRootData): string | null {
    for (const field of config.facetFields) {
        for (const segment of document.segments) {
            if (segment.kind !== "frontmatter-field") {
                continue;
            }
            if (segment.key !== field) {
                continue;
            }

            const value = segment.value ?? "";
            if (value.length > 0) {
                return value;
            }
        }
    }

    return null;
};

export const symbolOf = function symbolOf(document: Document): string | null {
    for (const segment of document.segments) {
        if (segment.kind !== "heading") {
            continue;
        }

        const value = (segment.key ?? segment.value ?? "").trim();
        if (value.length > 0) {
            return value;
        }
    }

    return null;
};

export const keyFromSymbol = function keyFromSymbol(symbol: string): string {
    let key = "";

    for (let index = 0; index < symbol.length; index += 1) {
        const character = symbol.charAt(index);
        if (character === "_") {
            key += "-";
            continue;
        }
        key += character.toLowerCase();
    }

    return key;
};
```
