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

> 30 lines of code and 9 definitions.

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

## Definitions

- `splitWords` (lexical_declaration, line 13, exported)
- `contains` (lexical_declaration, line 5, exported)
- `flushed` (lexical_declaration, line 9)
- `QUOTE_MARKS` (lexical_declaration, line 1)
- `WORD_BREAKS` (lexical_declaration, line 3)
- `words` (lexical_declaration, line 14, exported)
- `current` (lexical_declaration, line 15, exported)
- `quote` (lexical_declaration, line 16, exported)
- `hasPrefix` (lexical_declaration, line 35, exported)

## Used by

- [tools/core/inspectors/manifest.inspector.ts](https://banes-lab.com/source/coordination/tools/core/inspectors/manifest.inspector.ts.md)
- [tools/core/matchers/segment.matcher.ts](https://banes-lab.com/source/coordination/tools/core/matchers/segment.matcher.ts.md)
- [tools/core/resolvers/dependency.resolver.ts](https://banes-lab.com/source/coordination/tools/core/resolvers/dependency.resolver.ts.md)
- [tools/rules/governance.rule.ts](https://banes-lab.com/source/coordination/tools/rules/governance.rule.ts.md)

## Source

```typescript
const QUOTE_MARKS = new Set(['"', "'"]);

const WORD_BREAKS = new Set([" ", "\t"]);

export const contains = function contains(haystack: string, needle: string): boolean {
    return haystack.includes(needle);
};

const flushed = function flushed(words: readonly string[], current: string): string[] {
    return current.length > 0 ? [...words, current] : [...words];
};

export const splitWords = function splitWords(text: string): string[] {
    let words: string[] = [];
    let current = "";
    let quote = "";

    for (const char of text) {
        if (quote !== "") {
            quote = char === quote ? "" : quote;
            current += quote === "" ? "" : char;
        } else if (QUOTE_MARKS.has(char)) {
            quote = char;
        } else if (WORD_BREAKS.has(char)) {
            words = flushed(words, current);
            current = "";
        } else {
            current += char;
        }
    }

    return flushed(words, current);
};

export const hasPrefix = function hasPrefix(text: string, prefix: string): boolean {
    return text.startsWith(prefix);
};
```
