# core/predicates/character.predicate.ts

> 39 lines of code and 13 definitions.

Tree: GovLab Constants
Language: typescript
Layer: infrastructure
Canonical: https://banes-lab.com/anatomy/constants#file-constants-core-predicates-character-predicate-ts
Source text: https://banes-lab.com/source/constants/core/predicates/character.predicate.ts.txt

Listed in [core/predicates](https://banes-lab.com/api/source/constants/core/predicates.md).

## Definitions

- `isDigit` (lexical_declaration, line 28, exported)
- `UPPER_SET` (lexical_declaration, line 9)
- `LOWER_SET` (lexical_declaration, line 10)
- `ALPHA_SET` (lexical_declaration, line 11)
- `DIGIT_SET` (lexical_declaration, line 12)
- `WHITESPACE_SET` (lexical_declaration, line 13)
- `IDENTIFIER_SET` (lexical_declaration, line 14)
- `isUpperAlpha` (lexical_declaration, line 16, exported)
- `isLowerAlpha` (lexical_declaration, line 20, exported)
- `isAlpha` (lexical_declaration, line 24, exported)
- `isWhitespace` (lexical_declaration, line 32, exported)
- `isIdentifierChar` (lexical_declaration, line 36, exported)
- `everyChar` (lexical_declaration, line 40, exported)

## Contained in

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

## Used by

- [core/lexers/identifier.lexer.ts](https://banes-lab.com/source/constants/core/lexers/identifier.lexer.ts.md)

## Linked from

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

## Source

```typescript
import {
    DIGITS,
    IDENTIFIER_JOINER,
    LOWER_ALPHA,
    UPPER_ALPHA,
    WHITESPACE,
} from "#configuration/constants/character.constants";

const UPPER_SET = new Set<string>(UPPER_ALPHA);
const LOWER_SET = new Set<string>(LOWER_ALPHA);
const ALPHA_SET = new Set<string>([...UPPER_ALPHA, ...LOWER_ALPHA]);
const DIGIT_SET = new Set<string>(DIGITS);
const WHITESPACE_SET = new Set<string>(WHITESPACE);
const IDENTIFIER_SET = new Set<string>([...UPPER_ALPHA, ...LOWER_ALPHA, ...DIGITS, IDENTIFIER_JOINER]);

export const isUpperAlpha = function isUpperAlpha(char: string): boolean {
    return UPPER_SET.has(char);
};

export const isLowerAlpha = function isLowerAlpha(char: string): boolean {
    return LOWER_SET.has(char);
};

export const isAlpha = function isAlpha(char: string): boolean {
    return ALPHA_SET.has(char);
};

export const isDigit = function isDigit(char: string): boolean {
    return DIGIT_SET.has(char);
};

export const isWhitespace = function isWhitespace(char: string): boolean {
    return WHITESPACE_SET.has(char);
};

export const isIdentifierChar = function isIdentifierChar(char: string): boolean {
    return IDENTIFIER_SET.has(char);
};

export const everyChar = function everyChar(text: string, test: (char: string) => boolean): boolean {
    for (const char of text) {
        if (!test(char)) {
            return false;
        }
    }
    return true;
};
```
