# core/analyzers/text.analyzer.ts

> 30 lines of code and 9 definitions.

Tree: GovLab Docs
Language: typescript
Layer: processing
Canonical: https://banes-lab.com/anatomy/docs#file-docs-core-analyzers-text-analyzer-ts
Source text: https://banes-lab.com/source/docs/core/analyzers/text.analyzer.ts.txt

Listed in [core/analyzers](https://banes-lab.com/api/source/docs/core/analyzers.md), after [core/analyzers/surface.analyzer.ts](https://banes-lab.com/source/docs/core/analyzers/surface.analyzer.ts.md) and before [core/analyzers/vocabulary.analyzer.ts](https://banes-lab.com/source/docs/core/analyzers/vocabulary.analyzer.ts.md).

## Definitions

- `hardcodedCounts` (lexical_declaration, line 26, exported)
- `isThousandsComma` (lexical_declaration, line 6)
- `countStart` (lexical_declaration, line 18)
- `COUNT_DIGITS` (lexical_declaration, line 3)
- `THOUSANDS_SEPARATOR` (lexical_declaration, line 4)
- `offset` (lexical_declaration, line 10)
- `start` (lexical_declaration, line 19)
- `hits` (lexical_declaration, line 27, exported)
- `at` (lexical_declaration, line 28, exported)

## Contained in

- [core/analyzers](https://banes-lab.com/anatomy/docs/folder-docs-core-analyzers.md)

## Used by

- [core/validators/manifest.prose.validator.ts](https://banes-lab.com/source/docs/core/validators/manifest.prose.validator.ts.md)

## Linked from

- [core/analyzers](https://banes-lab.com/anatomy/docs/folder-docs-core-analyzers.md)
- [core/validators](https://banes-lab.com/anatomy/docs/folder-docs-core-validators.md)

## Source

```typescript
import { isDigit } from "@govlab/constants";

const COUNT_DIGITS = 3;
const THOUSANDS_SEPARATOR = ",";

const isThousandsComma = function isThousandsComma(text: string, at: number): boolean {
    if (text.charAt(at) !== THOUSANDS_SEPARATOR || !isDigit(text.charAt(at - 1))) {
        return false;
    }
    for (let offset = 1; offset <= COUNT_DIGITS; offset += 1) {
        if (!isDigit(text.charAt(at + offset))) {
            return false;
        }
    }
    return true;
};

const countStart = function countStart(text: string, comma: number): number {
    let start = comma - 1;
    while (start > 0 && isDigit(text.charAt(start - 1))) {
        start -= 1;
    }
    return start;
};

export const hardcodedCounts = function hardcodedCounts(text: string): string[] {
    const hits = new Set<string>();
    for (let at = 1; at + COUNT_DIGITS < text.length; at += 1) {
        if (isThousandsComma(text, at)) {
            hits.add(text.slice(countStart(text, at), at + COUNT_DIGITS + 1));
        }
    }
    return [...hits];
};
```
