import unicode from "unicode-properties";
import { allLowerWordStyle, allUpperWordStyle, combineWords, escapeNonPrintableMapper, firstUpperWordStyle, intToHex, isLetterOrUnderscore, isPrintable, legalizeCharacters, splitIntoWords, utf32ConcatMap, } from "../../support/Strings.js";
function unicodeEscape(codePoint) {
    return `\\u{${intToHex(codePoint, 0)}}`;
}
export function capitalizeFirstLetter(str) {
    return str.charAt(0).toUpperCase() + str.slice(1);
}
export const stringEscape = utf32ConcatMap(escapeNonPrintableMapper(isPrintable, unicodeEscape));
export function escapeDoubleQuotes(str) {
    return str.replace(/"/g, '\\"');
}
export function escapeNewLines(str) {
    return str.replace(/\n/g, "\\n");
}
const isStartCharacter = isLetterOrUnderscore;
function isPartCharacter(utf16Unit) {
    const category = unicode.getCategory(utf16Unit);
    return (["Nd", "Pc", "Mn", "Mc"].includes(category) ||
        isStartCharacter(utf16Unit));
}
const legalizeName = legalizeCharacters(isPartCharacter);
export function simpleNameStyle(original, uppercase) {
    if (/^[0-9]+$/.test(original)) {
        original = `${original}N`;
    }
    const words = splitIntoWords(original);
    return combineWords(words, legalizeName, uppercase ? firstUpperWordStyle : allLowerWordStyle, uppercase ? firstUpperWordStyle : allLowerWordStyle, allUpperWordStyle, allUpperWordStyle, "", isStartCharacter);
}
export function memberNameStyle(original) {
    const words = splitIntoWords(original);
    return combineWords(words, legalizeName, allLowerWordStyle, allLowerWordStyle, allLowerWordStyle, allLowerWordStyle, "_", isStartCharacter);
}
