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

> 27 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-literal-predicate-ts
Source text: https://banes-lab.com/assets/sources/source.846f52abffc4fb8e6dfa46a90584e824033d03814e06d3acc3e8ef87551adf97.generated.txt

## Definitions

- `stringLiterals` (lexical_declaration, line 14, exported)
- `newlinesIn` (lexical_declaration, line 10)
- `Literal` (interface_declaration, line 3, exported)
- `QUOTES` (lexical_declaration, line 8)
- `out` (lexical_declaration, line 15, exported)
- `cursor` (lexical_declaration, line 16, exported)
- `line` (lexical_declaration, line 17, exported)
- `char` (lexical_declaration, line 20, exported)
- `end` (lexical_declaration, line 22, exported)

## Used by

- [tools/core/resolvers/dependency.resolver.ts](https://banes-lab.com/source/coordination/tools/core/resolvers/dependency.resolver.ts.md)
- [tools/core/validators/verdict.validator.ts](https://banes-lab.com/source/coordination/tools/core/validators/verdict.validator.ts.md)
- [tools/rules/entrypoint.rule.ts](https://banes-lab.com/source/coordination/tools/rules/entrypoint.rule.ts.md)
- [tools/rules/verdict.rule.ts](https://banes-lab.com/source/coordination/tools/rules/verdict.rule.ts.md)

## Source

```typescript
import { at, endOfQuoted } from "./comment.predicate.ts";

export interface Literal {
    readonly value: string;
    readonly line: number;
}

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

const newlinesIn = function newlinesIn(text: string): number {
    return text.split("\n").length - 1;
};

export const stringLiterals = function stringLiterals(source: string): Literal[] {
    const out: Literal[] = [];
    let cursor = 0;
    let line = 1;

    while (cursor < source.length) {
        const char = at(source, cursor);
        if (QUOTES.has(char)) {
            const end = endOfQuoted(source, cursor + 1, char);
            out.push({ line, value: source.slice(cursor + 1, Math.max(cursor + 1, end - 1)) });
            line += newlinesIn(source.slice(cursor, end));
            cursor = end;
        } else {
            line += char === "\n" ? 1 : 0;
            cursor += 1;
        }
    }

    return out;
};
```
