import { PROJECT_LANG_NAMESPACE, PROJECT_NAMESPACE, PROJECT_NAMESPACE_COLLISION_RESISTANT } from "./FSConstants";
export default class FSUtil {
    static uuid() {
        return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
            var r = (Math.random() * 16) | 0;
            var v = c === "x" ? r : (r & 0x3) | 0x8;
            return v.toString(16);
        });
    }
    static shortId(length = 16) {
        var result = "";
        var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        var charactersLength = characters.length;
        for (var i = 0; i < length; i++) {
            result += characters.charAt(Math.floor(Math.random() * charactersLength));
        }
        return result;
    }
    static random(min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }
    static rand(min, max) {
        return FSUtil.random(min, max);
    }
    static hash(input, bitSize = 32, allowNegative = false) {
        let hashValue = 5381;
        let inputLength = input.length;
        bitSize = bitSize && -1 >>> (32 - bitSize);
        const midRange = (bitSize - 1) / 2;
        while (inputLength > 0) {
            hashValue = (33 * hashValue) ^ input.charCodeAt(--inputLength);
        }
        let result = (hashValue >>> 0) & bitSize;
        if (allowNegative && result > midRange) {
            result = -bitSize + result - 1;
        }
        return result.toString();
    }
    static namespacedString(value, separator = ":") {
        value = value.replace(`${PROJECT_NAMESPACE}:`, "");
        value = value.replace(`${PROJECT_NAMESPACE}_`, "");
        value = value.replace(`${PROJECT_NAMESPACE}${separator}`, "");
        return `${PROJECT_NAMESPACE}${separator}${value}`;
    }
    static namespacedStringCr(value, separator = ":") {
        value = value.replace(`${PROJECT_NAMESPACE}:`, "");
        value = value.replace(`${PROJECT_NAMESPACE}_`, "");
        value = value.replace(`${PROJECT_NAMESPACE}${separator}`, "");
        value = value.replace(`${PROJECT_NAMESPACE_COLLISION_RESISTANT}:`, "");
        value = value.replace(`${PROJECT_NAMESPACE_COLLISION_RESISTANT}_`, "");
        value = value.replace(`${PROJECT_NAMESPACE_COLLISION_RESISTANT}${separator}`, "");
        return `${PROJECT_NAMESPACE_COLLISION_RESISTANT}${separator}${value}`;
    }
    static _langNamespacedString(value, separator = ":") {
        value = value.replace(`${PROJECT_LANG_NAMESPACE}:`, "");
        value = value.replace(`${PROJECT_LANG_NAMESPACE}_`, "");
        value = value.replace(`${PROJECT_LANG_NAMESPACE}${separator}`, "");
        return `${PROJECT_LANG_NAMESPACE}${separator}${value}`;
    }
    static sentenceCase(str) {
        if (str === null || str === undefined) {
            return "";
        }
        else {
            return str.replace(/\w\S*/g, txt => {
                return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
            });
        }
    }
    static stripFormatting(str) {
        return str
            .replace(/§[0-9a-fklmnor]/g, "")
            .replace(/"/g, "")
            .replace(/{/g, "")
            .replace(/}/g, "")
            .trim();
    }
    static entityTypeToName(entity, sentenceCase = false) {
        if (entity.typeId.indexOf(":") === -1) {
            return entity.typeId;
        }
        let entityType = entity.typeId.split(":")[1];
        entityType = entityType.replace(/_/g, " ");
        if (sentenceCase) {
            entityType = entityType.replace(/\w\S*/g, txt => {
                return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
            });
        }
        return entityType;
    }
    static entityName(entity, sentenceCase = false) {
        var name = entity.getDynamicProperty(FSUtil.namespacedString("custom_name")) || "";
        if (name.length >= 1) {
            name = FSUtil.stripFormatting(name);
        }
        else {
            if (entity.typeId.indexOf(":") !== -1) {
                let entityType = entity.typeId.split(":")[1];
                name = entityType.replace(/_/g, " ");
            }
            else {
                name = entity.typeId;
            }
            if (entity.typeId === "57d_sbunk:security_dog") {
                name = "Guard Dog";
            }
        }
        if (sentenceCase) {
            name = this.sentenceCase(name);
        }
        return name;
    }
    static truncateString(str, length, ending = "") {
        if (str.length > length) {
            return str.substring(0, length - ending.length) + ending;
        }
        else {
            return str;
        }
    }
    static getShortDateTime(shortest = false) {
        const now = new Date();
        const year = now.getFullYear();
        const month = String(now.getMonth() + 1).padStart(2, '0'); 
        const day = String(now.getDate()).padStart(2, '0');
        const hours = String(now.getHours()).padStart(2, '0');
        const minutes = String(now.getMinutes()).padStart(2, '0');
        const seconds = String(now.getSeconds()).padStart(2, '0');
        if (shortest) {
            return `${year}${month}${day}${hours}${minutes}${seconds}`;
        }
        else {
            return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
        }
    }
}

//# sourceMappingURL=../../../../_SBUNK_BPDebug/fs_sbunk/fs/FSUtil.js.map
