import unicode from "unicode-properties";
import { allLowerWordStyle, allUpperWordStyle, combineWords, escapeNonPrintableMapper, firstUpperWordStyle, intToHex, isLetterOrUnderscore, isPrintable, legalizeCharacters, splitIntoWords, utf32ConcatMap, } from "../../support/Strings.js";
import * as keywords from "./constants.js";
export var Strictness;
(function (Strictness) {
    Strictness["Strict"] = "Strict::";
    Strictness["Coercible"] = "Coercible::";
    Strictness["None"] = "Types::";
})(Strictness || (Strictness = {}));
export const forbiddenForObjectProperties = Array.from(new Set([...keywords.keywords, ...keywords.reservedProperties]));
function unicodeEscape(codePoint) {
    return "\\u{" + intToHex(codePoint, 0) + "}";
}
export const stringEscape = utf32ConcatMap(escapeNonPrintableMapper(isPrintable, unicodeEscape));
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);
}
