core/lexers/identifier.lexer.ts

core/lexers/identifier.lexer.ts is a file in GovLab Constants. 16 lines of code and 5 definitions.

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;
};