# core/converters/location.converter.ts

> 30 lines of code and 7 definitions.

Tree: GovLab Paths
Language: typescript
Layer: processing
Canonical: https://banes-lab.com/anatomy/paths#file-paths-core-converters-location-converter-ts
Source text: https://banes-lab.com/source/paths/core/converters/location.converter.ts.txt

Listed in [core/converters](https://banes-lab.com/api/source/paths/core/converters.md).

## Definitions

- `absolutize` (lexical_declaration, line 9)
- `buildPaths` (lexical_declaration, line 25)
- `own` (lexical_declaration, line 16)
- `childPrefix` (lexical_declaration, line 17)
- `out` (lexical_declaration, line 18)
- `built` (lexical_declaration, line 26)
- `paths` (lexical_declaration, line 33, exported)

## Contained in

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

## Uses

- [core/predicates/location.predicate.ts](https://banes-lab.com/source/paths/core/predicates/location.predicate.ts.md)

## Linked from

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

## Source

```typescript
import { SEGMENT_SEPARATOR, SELF_KEY } from "#configuration/constants/location.constants";
import { isPathTree, isRecord } from "#core/predicates/location.predicate";
import { INVALID_ABSOLUTE_TREE } from "#configuration/strings/location.strings";
import { LOCATION_TREE } from "#core/loaders/location.loader";
import type { PathTree } from "#types/location.types";
import { ROOT } from "#core/resolvers/location.root.resolver";
import { join } from "node:path";

const absolutize = function absolutize(node: unknown, prefix: readonly string[]): unknown {
    if (typeof node === "string") {
        return join(ROOT, ...prefix, ...node.split(SEGMENT_SEPARATOR));
    }
    if (!isRecord(node)) {
        return node;
    }
    const own = typeof node[SELF_KEY] === "string" ? node[SELF_KEY] : "";
    const childPrefix = own.length > 0 ? [...prefix, ...own.split(SEGMENT_SEPARATOR)] : [...prefix];
    const out: Record<string, unknown> = {};
    for (const [key, value] of Object.entries(node)) {
        out[key] = key === SELF_KEY ? join(ROOT, ...childPrefix) : absolutize(value, childPrefix);
    }
    return Object.freeze(out);
};

const buildPaths = function buildPaths(): Readonly<PathTree> {
    const built = absolutize(LOCATION_TREE, []);
    if (!isPathTree(built)) {
        throw new Error(INVALID_ABSOLUTE_TREE);
    }
    return built;
};

export const paths: Readonly<PathTree> = buildPaths();
```
