# tools/core/normalizers/document.normalizer.ts

> 28 lines of code and 10 definitions.

Tree: Coordination tree
Language: typescript
Layer: processing
Canonical: https://banes-lab.com/anatomy/coordination#file-coordination-tools-core-normalizers-document-normalizer-ts
Source text: https://banes-lab.com/assets/sources/source.d01c82d6731dc6276152d36f163eae0246f87422f5a023163535313ad07cd393.generated.txt

## Definitions

- `sameRow` (lexical_declaration, line 18, exported)
- `cellsOf` (lexical_declaration, line 10)
- `canonicalLine` (lexical_declaration, line 14)
- `ROW_MARKER` (lexical_declaration, line 1)
- `DIVIDER_CELL` (lexical_declaration, line 3)
- `canonicalCell` (lexical_declaration, line 5)
- `trimmed` (lexical_declaration, line 6)
- `sameDocument` (lexical_declaration, line 24, exported)
- `left` (lexical_declaration, line 25, exported)
- `right` (lexical_declaration, line 29, exported)

## Used by

- [tools/core/runners/agenda.runner.ts](https://banes-lab.com/source/coordination/tools/core/runners/agenda.runner.ts.md)

## Source

```typescript
const ROW_MARKER = "|";

const DIVIDER_CELL = "---";

const canonicalCell = function canonicalCell(cell: string): string {
    const trimmed = cell.trim();
    return trimmed.length > 0 && trimmed.replaceAll("-", "").length === 0 ? DIVIDER_CELL : trimmed;
};

const cellsOf = function cellsOf(line: string): string[] {
    return line.trim().split(ROW_MARKER).map(canonicalCell);
};

const canonicalLine = function canonicalLine(line: string): string {
    return line.trim().startsWith(ROW_MARKER) ? cellsOf(line).join(ROW_MARKER) : line.trimEnd();
};

export const sameRow = function sameRow(held: string, rendered: string): boolean {
    const left = cellsOf(held);
    const right = cellsOf(rendered);
    return left.length === right.length && left.every((cell, index) => cell === right[index]);
};

export const sameDocument = function sameDocument(held: string, rendered: string): boolean {
    const left = held
        .split("\n")
        .map(canonicalLine)
        .filter((line) => line.length > 0);
    const right = rendered
        .split("\n")
        .map(canonicalLine)
        .filter((line) => line.length > 0);
    return left.length === right.length && left.every((line, index) => line === right[index]);
};
```
