//
// Types
//
/**
 * Makes every specified property of the specified object type mutable.
 *
 * @template ObjectValue - The object whose readonly properties to make mutable.
 * @template TargetKey - The property key(s) to make mutable.
 */ "use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: all[name]
    });
}
_export(exports, {
    JsonSize: function() {
        return JsonSize;
    },
    isNonEmptyArray: function() {
        return isNonEmptyArray;
    },
    isNullOrUndefined: function() {
        return isNullOrUndefined;
    },
    isObject: function() {
        return isObject;
    },
    hasProperty: function() {
        return hasProperty;
    },
    getKnownPropertyNames: function() {
        return getKnownPropertyNames;
    },
    ESCAPE_CHARACTERS_REGEXP: function() {
        return ESCAPE_CHARACTERS_REGEXP;
    },
    isPlainObject: function() {
        return isPlainObject;
    },
    isASCII: function() {
        return isASCII;
    },
    calculateStringSize: function() {
        return calculateStringSize;
    },
    calculateNumberSize: function() {
        return calculateNumberSize;
    }
});
function isNonEmptyArray(value) {
    return Array.isArray(value) && value.length > 0;
}
function isNullOrUndefined(value) {
    return value === null || value === undefined;
}
function isObject(value) {
    return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
}
const hasProperty = (objectToCheck, name)=>Object.hasOwnProperty.call(objectToCheck, name);
function getKnownPropertyNames(object) {
    return Object.getOwnPropertyNames(object);
}
var JsonSize;
(function(JsonSize) {
    JsonSize[JsonSize["Null"] = 4] = "Null";
    JsonSize[JsonSize["Comma"] = 1] = "Comma";
    JsonSize[JsonSize["Wrapper"] = 1] = "Wrapper";
    JsonSize[JsonSize["True"] = 4] = "True";
    JsonSize[JsonSize["False"] = 5] = "False";
    JsonSize[JsonSize["Quote"] = 1] = "Quote";
    JsonSize[JsonSize["Colon"] = 1] = "Colon";
    JsonSize[JsonSize[// eslint-disable-next-line @typescript-eslint/no-shadow
    "Date"] = 24] = "Date";
})(JsonSize || (JsonSize = {}));
const ESCAPE_CHARACTERS_REGEXP = /"|\\|\n|\r|\t/gu;
function isPlainObject(value) {
    if (typeof value !== 'object' || value === null) {
        return false;
    }
    try {
        let proto = value;
        while(Object.getPrototypeOf(proto) !== null){
            proto = Object.getPrototypeOf(proto);
        }
        return Object.getPrototypeOf(value) === proto;
    } catch (_) {
        return false;
    }
}
function isASCII(character) {
    return character.charCodeAt(0) <= 127;
}
function calculateStringSize(value) {
    const size = value.split('').reduce((total, character)=>{
        if (isASCII(character)) {
            return total + 1;
        }
        return total + 2;
    }, 0);
    // Also detect characters that need backslash escape
    return size + (value.match(ESCAPE_CHARACTERS_REGEXP) ?? []).length;
}
function calculateNumberSize(value) {
    return value.toString().length;
}

//# sourceMappingURL=misc.js.map