# core/lexers/identifier.lexer.ts

> 16 lines of code and 5 definitions.

Tree: GovLab Constants
Language: typescript
Layer: processing
Canonical: https://banes-lab.com/anatomy/constants#file-constants-core-lexers-identifier-lexer-ts
Source text: https://banes-lab.com/source/constants/core/lexers/identifier.lexer.ts.txt

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

## Definitions

- `identifierParts` (lexical_declaration, line 3, exported)
- `parts` (lexical_declaration, line 4, exported)
- `current` (lexical_declaration, line 5, exported)
- `previousLower` (lexical_declaration, line 6, exported)
- `upper` (lexical_declaration, line 8, exported)

## Contained in

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

## Uses

- [core/predicates/character.predicate.ts](https://banes-lab.com/source/constants/core/predicates/character.predicate.ts.md)

## Linked from

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

## Source

```typescript
import { isDigit } from "#core/predicates/character.predicate";

export const identifierParts = function identifierParts(token: string): readonly string[] {
    const parts: string[] = [];
    let current = "";
    let previousLower = false;
    for (const character of token) {
        const upper = character !== character.toLowerCase();
        if (upper && previousLower && current.length > 0) {
            parts.push(current);
            current = "";
        }
        current += character;
        previousLower = !upper && character === character.toLowerCase() && !isDigit(character);
    }
    return current.length > 0 ? [...parts, current] : parts;
};
```
