# tools/core/predicates/fence.predicate.ts

> 32 lines of code and 10 definitions.

Tree: Coordination tree
Language: typescript
Layer: infrastructure
Canonical: https://banes-lab.com/anatomy/coordination#file-coordination-tools-core-predicates-fence-predicate-ts
Source text: https://banes-lab.com/assets/sources/source.bedb8175427dcf421aac6d3bb59074b96166fe8230564c479b1246a4e2c52b14.generated.txt

## Definitions

- `closesFence` (lexical_declaration, line 20)
- `isBlank` (lexical_declaration, line 16)
- `fencedFlags` (lexical_declaration, line 25, exported)
- `FENCE_MARK` (lexical_declaration, line 1)
- `FENCE_MINIMUM` (lexical_declaration, line 3)
- `fenceRun` (lexical_declaration, line 5)
- `text` (lexical_declaration, line 6)
- `flags` (lexical_declaration, line 26, exported)
- `opened` (lexical_declaration, line 27, exported)
- `run` (lexical_declaration, line 31, exported)

## Source

```typescript
const FENCE_MARK = "`";

const FENCE_MINIMUM = 3;

const fenceRun = function fenceRun(line: string): number {
    const text = line.trimStart();

    let run = 0;
    while (run < text.length && text.charAt(run) === FENCE_MARK) {
        run += 1;
    }

    return run;
};

const isBlank = function isBlank(text: string): boolean {
    return text.replaceAll(" ", "").replaceAll("\t", "").length === 0;
};

const closesFence = function closesFence(line: string, opened: number): boolean {
    const run = fenceRun(line);
    return run >= opened && isBlank(line.trimStart().slice(run));
};

export const fencedFlags = function fencedFlags(source: string): boolean[] {
    const flags: boolean[] = [];
    let opened = 0;

    for (const line of source.split("\n")) {
        if (opened === 0) {
            const run = fenceRun(line);
            opened = run >= FENCE_MINIMUM ? run : 0;
            flags.push(opened > 0);
        } else {
            flags.push(true);
            opened = closesFence(line, opened) ? 0 : opened;
        }
    }

    return flags;
};
```
