# domain/converters/source.converter.ts

> 71 lines of code and 16 definitions.

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

## Definitions

- `fileId` (lexical_declaration, line 28, exported)
- `nodeHref` (lexical_declaration, line 32, exported)
- `folderId` (lexical_declaration, line 37, exported)
- `definitionHref` (lexical_declaration, line 72, exported)
- `languageOf` (lexical_declaration, line 80, exported)
- `folderHref` (lexical_declaration, line 41, exported)
- `pathLabel` (lexical_declaration, line 67, exported)
- `treeLabelOf` (lexical_declaration, line 63, exported)
- `definitionTree` (lexical_declaration, line 49)
- `definitionFragment` (lexical_declaration, line 45, exported)
- `sourceLink` (lexical_declaration, line 76, exported)
- `suffix` (lexical_declaration, line 33, exported)
- `cited` (lexical_declaration, line 53)
- `TREE_LABELS` (lexical_declaration, line 57)
- `tree` (lexical_declaration, line 68, exported)
- `extension` (lexical_declaration, line 81, exported)

## Uses

- [core/assets/link.assets.ts](https://banes-lab.com/source/tree/core/assets/link.assets.ts.md)
- [core/converters/folder.converter.ts](https://banes-lab.com/source/tree/core/converters/folder.converter.ts.md)
- [domain/converters/ontology.converter.ts](https://banes-lab.com/source/tree/domain/converters/ontology.converter.ts.md)

## Used by

- [domain/converters/anatomy.converter.ts](https://banes-lab.com/source/tree/domain/converters/anatomy.converter.ts.md)
- [domain/converters/search.converter.ts](https://banes-lab.com/source/tree/domain/converters/search.converter.ts.md)
- [domain/loaders/anatomy.loader.ts](https://banes-lab.com/source/tree/domain/loaders/anatomy.loader.ts.md)
- [domain/loaders/evidence.loader.ts](https://banes-lab.com/source/tree/domain/loaders/evidence.loader.ts.md)
- [presentation/components/source.component.ts](https://banes-lab.com/source/tree/presentation/components/source.component.ts.md)
- [presentation/components/walk.component.ts](https://banes-lab.com/source/tree/presentation/components/walk.component.ts.md)
- [presentation/renderers/definition.renderer.ts](https://banes-lab.com/source/tree/presentation/renderers/definition.renderer.ts.md)

## Source

```typescript
import {
    BUILD_TAB,
    COORDINATION_TAB,
    DEFINITION_ANCHOR,
    FILE_ANCHOR,
    FOLDER_ANCHOR,
    TREE_TAB,
} from "#core/ids/anatomy.ids";
import {
    BUILD_TREE_LABEL,
    COORDINATION_TREE_LABEL,
    ROOT_LABEL,
    TREE_LABEL,
} from "#configuration/strings/folder.strings";
import {
    EXTENSION_SEPARATOR,
    FALLBACK_LANGUAGE,
    LANGUAGE_BY_EXTENSION,
    LINE_INFIX,
} from "#configuration/constants/anatomy.constants";
import { localPath, treeOf } from "#core/converters/folder.converter";
import { ANATOMY_PAGE } from "#core/ids/page.ids";
import { TITLE_SEPARATOR } from "#configuration/strings/page.strings";
import { citedDefinition } from "#core/loaders/definition.loader";
import { slugOf } from "#domain/converters/ontology.converter";
import { tabLink } from "#assets/link.assets";

export const fileId = function fileId(path: string): string {
    return FILE_ANCHOR + slugOf(path);
};

export const nodeHref = function nodeHref(file: string, line: number | null): string {
    const suffix = line === null ? "" : LINE_INFIX + String(line);
    return tabLink(ANATOMY_PAGE, treeOf(file), fileId(file) + suffix);
};

export const folderId = function folderId(path: string): string {
    return FOLDER_ANCHOR + slugOf(path === "" ? ROOT_LABEL : path);
};

export const folderHref = function folderHref(path: string): string {
    return tabLink(ANATOMY_PAGE, treeOf(path), folderId(path));
};

export const definitionFragment = function definitionFragment(name: string, file: string | null = null): string {
    return DEFINITION_ANCHOR + name + (file === null ? "" : LINE_INFIX + file);
};

const definitionTree = function definitionTree(name: string, file: string | null): string {
    if (file !== null) {
        return treeOf(file);
    }
    const cited = citedDefinition(name);
    return cited === null ? TREE_TAB : treeOf(cited.file);
};

const TREE_LABELS: ReadonlyMap<string, string> = new Map([
    [TREE_TAB, TREE_LABEL],
    [BUILD_TAB, BUILD_TREE_LABEL],
    [COORDINATION_TAB, COORDINATION_TREE_LABEL],
]);

export const treeLabelOf = function treeLabelOf(tab: string): string {
    return TREE_LABELS.get(tab) ?? tab;
};

export const pathLabel = function pathLabel(path: string): string {
    const tree = treeOf(path);
    return tree === TREE_TAB ? path : treeLabelOf(tree) + TITLE_SEPARATOR + localPath(path);
};

export const definitionHref = function definitionHref(name: string, file: string | null = null): string {
    return tabLink(ANATOMY_PAGE, definitionTree(name, file), definitionFragment(name, file));
};

export const sourceLink = function sourceLink(name: string, label: string = name, file: string | null = null): string {
    return `<a href="${definitionHref(name, file)}">${label}</a>`;
};

export const languageOf = function languageOf(name: string): string {
    const extension = name.slice(name.lastIndexOf(EXTENSION_SEPARATOR) + 1);
    return LANGUAGE_BY_EXTENSION.get(extension) ?? FALLBACK_LANGUAGE;
};
```
