# core/matchers/word.matcher.ts

> 20 lines of code and 7 definitions.

Tree: GovLab Quality
Language: typescript
Layer: processing
Canonical: https://banes-lab.com/anatomy/quality#file-quality-core-matchers-word-matcher-ts
Source text: https://banes-lab.com/source/quality/core/matchers/word.matcher.ts.txt

Listed in [core/matchers](https://banes-lab.com/api/source/quality/core/matchers.md), after [core/matchers/target.matcher.ts](https://banes-lab.com/source/quality/core/matchers/target.matcher.ts.md).

## Definitions

- `wordIncludes` (lexical_declaration, line 11, exported)
- `isWordBoundary` (lexical_declaration, line 7, exported)
- `isIdentChar` (lexical_declaration, line 3)
- `idx` (lexical_declaration, line 12, exported)
- `before` (lexical_declaration, line 14, exported)
- `afterAt` (lexical_declaration, line 15, exported)
- `after` (lexical_declaration, line 16, exported)

## Contained in

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

## Used by

- [core/resolvers/coverage.resolver.ts](https://banes-lab.com/source/quality/core/resolvers/coverage.resolver.ts.md)

## Linked from

- [core/matchers](https://banes-lab.com/anatomy/quality/folder-quality-core-matchers.md)
- [core/resolvers](https://banes-lab.com/anatomy/quality/folder-quality-core-resolvers.md)

## Source

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

const isIdentChar = function isIdentChar(ch: string): boolean {
    return isIdentifierChar(ch) || ch === "$";
};

export const isWordBoundary = function isWordBoundary(ch: string): boolean {
    return !isIdentChar(ch);
};

export const wordIncludes = function wordIncludes(text: string, name: string): boolean {
    let idx = text.indexOf(name);
    while (idx !== -1) {
        const before = idx === 0 ? "" : text.charAt(idx - 1);
        const afterAt = idx + name.length;
        const after = afterAt >= text.length ? "" : text.charAt(afterAt);
        if (isWordBoundary(before) && isWordBoundary(after)) {
            return true;
        }
        idx = text.indexOf(name, idx + 1);
    }
    return false;
};
```
