# core/converters/principle.converter.ts

> 54 lines of code and 11 definitions.

Tree: Build tree
Language: typescript
Layer: processing
Canonical: https://banes-lab.com/anatomy/build#file-build-core-converters-principle-converter-ts
Source text: https://banes-lab.com/assets/sources/source.e0a5cb886bef8b2fe949e4bc94eb14e251407894ecfd5723cd362e2fca8bbb37.generated.txt

## Definitions

- `profilePrinciples` (lexical_declaration, line 24, exported)
- `profileSeeds` (lexical_declaration, line 43, exported)
- `SOURCE` (lexical_declaration, line 11)
- `SECTION_MARK` (lexical_declaration, line 12)
- `sectionBody` (lexical_declaration, line 14)
- `start` (lexical_declaration, line 15)
- `afterHeading` (lexical_declaration, line 19)
- `next` (lexical_declaration, line 20)
- `body` (lexical_declaration, line 25, exported)
- `collected` (lexical_declaration, line 29, exported)
- `last` (lexical_declaration, line 35, exported)

## Source

```typescript
import { HEADING_MARK, LINE_END } from "#configuration/constants/inventory.constants";
import type { LessonSeed, ProfilePrinciple } from "#types/lesson.types";
import {
    PROFILE_PRINCIPLE_MARK,
    PROFILE_SECTION_HEADING,
    SEED_ID_SEPARATOR,
    SEED_LEVELS,
} from "#configuration/constants/seed.constants";
import { slugify } from "@govlab/context/algo";

const SOURCE = "profile";
const SECTION_MARK = `${HEADING_MARK} `;

const sectionBody = function sectionBody(text: string): string | null {
    const start = text.indexOf(PROFILE_SECTION_HEADING);
    if (start === -1) {
        return null;
    }
    const afterHeading = start + PROFILE_SECTION_HEADING.length;
    const next = text.indexOf(LINE_END + SECTION_MARK, afterHeading);
    return text.slice(afterHeading, next === -1 ? text.length : next);
};

export const profilePrinciples = function profilePrinciples(text: string): ProfilePrinciple[] {
    const body = sectionBody(text);
    if (body === null) {
        return [];
    }
    const collected: { heading: string; lines: string[] }[] = [];
    for (const line of body.split(LINE_END)) {
        if (line.startsWith(PROFILE_PRINCIPLE_MARK)) {
            collected.push({ heading: line.slice(PROFILE_PRINCIPLE_MARK.length).trim(), lines: [] });
            continue;
        }
        const last = collected.at(-1);
        if (last !== undefined && line.trim().length > 0) {
            last.lines.push(line.trim());
        }
    }
    return collected.map((entry) => ({ body: entry.lines.join(" "), heading: entry.heading }));
};

export const profileSeeds = function profileSeeds(text: string): LessonSeed[] {
    return profilePrinciples(text).map((principle) => ({
        application: [],
        boundary: null,
        cause: [],
        decision: principle.heading,
        domain: SOURCE,
        failureMode: null,
        id: SOURCE + SEED_ID_SEPARATOR + slugify(principle.heading),
        level: SEED_LEVELS[SOURCE],
        principle: principle.body,
        problem: null,
        source: SOURCE,
        validation: null,
    }));
};
```
