# core/converters/surface.converter.ts

> 28 lines of code and 9 definitions.

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

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

## Definitions

- `LINE_BREAK` (lexical_declaration, line 3)
- `lineEdit` (lexical_declaration, line 5, exported)
- `shorter` (lexical_declaration, line 6, exported)
- `prefix` (lexical_declaration, line 7, exported)
- `suffix` (lexical_declaration, line 11, exported)
- `indentOf` (lexical_declaration, line 22, exported)
- `outputRest` (lexical_declaration, line 26, exported)
- `outputLines` (lexical_declaration, line 30, exported)
- `lines` (lexical_declaration, line 31, exported)

## Source

```typescript
import type { LineEdit, SurfaceLine } from "#types/surface.types";

const LINE_BREAK = "\n";

export const lineEdit = function lineEdit(before: readonly string[], after: readonly SurfaceLine[]): LineEdit {
    const shorter = Math.min(before.length, after.length);
    let prefix = 0;
    while (prefix < shorter && before[prefix] === after[prefix]?.text) {
        prefix += 1;
    }
    let suffix = 0;
    while (suffix < shorter - prefix && before[before.length - 1 - suffix] === after[after.length - 1 - suffix]?.text) {
        suffix += 1;
    }
    return {
        at: prefix,
        inserted: after.slice(prefix, after.length - suffix),
        removed: before.length - suffix - prefix,
    };
};

export const indentOf = function indentOf(text: string): number {
    return text.length - text.trimStart().length;
};

export const outputRest = function outputRest(shown: string | undefined, output: string): string | null {
    return shown !== undefined && shown !== "" && output.startsWith(shown) ? output.slice(shown.length) : null;
};

export const outputLines = function outputLines(output: string): string[] {
    const lines = output.split(LINE_BREAK);
    return lines.at(-1) === "" ? lines.slice(0, -1) : lines;
};
```
