"use strict";
/* eslint {"@typescript-eslint/ban-types": ["error", {"types": {"Function": false}}]} */
Object.defineProperty(exports, "__esModule", { value: true });
exports.instanceOf = exports.has = exports.isEnumValue = exports.isFunction = exports.isEmpty = exports.isPlainObject = exports.isObject = exports.isArray = exports.isUint8Array = exports.isAnyArrayBuffer = exports.isInteger = exports.isNumber = exports.isHttpUrl = exports.isBase64 = exports.isString = exports.isBoolean = exports.isNull = exports.isDefined = exports.isNotDefined = void 0;
function isNotDefined(value) {
    return (isNull(value) ||
        (isString(value) ? value === '' || value.toLowerCase() === 'null' || value.toLowerCase() === 'undefined' : false));
}
exports.isNotDefined = isNotDefined;
function isDefined(value) {
    return !isNotDefined(value);
}
exports.isDefined = isDefined;
function isNull(value) {
    return value == null;
}
exports.isNull = isNull;
function isBoolean(value) {
    return typeof value === 'boolean' || value instanceof Boolean;
}
exports.isBoolean = isBoolean;
function isString(value) {
    return Object.prototype.toString.call(value) === '[object String]';
}
exports.isString = isString;
function isBase64(value) {
    return isString(value) && /^[A-Za-z0-9+/]*={0,2}$/.test(value);
}
exports.isBase64 = isBase64;
function isHttpUrl(value) {
    try {
        const url = new URL(value);
        return url.protocol === 'http:' || url.protocol === 'https:';
    }
    catch {
        return false;
    }
}
exports.isHttpUrl = isHttpUrl;
function isNumber(value) {
    return typeof value === 'number' || value instanceof Number;
}
exports.isNumber = isNumber;
function isInteger(value) {
    return isNumber(value) && Number.isInteger(value);
}
exports.isInteger = isInteger;
function isAnyArrayBuffer(value) {
    return !!value && (value[Symbol.toStringTag] === 'ArrayBuffer' || value[Symbol.toStringTag] === 'SharedArrayBuffer');
}
exports.isAnyArrayBuffer = isAnyArrayBuffer;
function isUint8Array(value) {
    return !!value && value[Symbol.toStringTag] === 'Uint8Array';
}
exports.isUint8Array = isUint8Array;
function isArray(value) {
    return Array.isArray(value);
}
exports.isArray = isArray;
function isObject(value) {
    return typeof value === 'object' && value !== null;
}
exports.isObject = isObject;
function isPlainObject(value) {
    return isObject(value) && (!value.constructor || value.constructor.name === 'Object');
}
exports.isPlainObject = isPlainObject;
function isEmpty(value) {
    if (!value)
        return true;
    if (isObject(value))
        return Object.keys(value).length === 0;
    return value.length === 0;
}
exports.isEmpty = isEmpty;
function isFunction(value, key) {
    if (key && has(value, key))
        return typeof value[key] === 'function';
    return typeof value === 'function';
}
exports.isFunction = isFunction;
function isEnumValue(value, enumeration) {
    const values = new Set(Object.values(enumeration));
    return values.has(value);
}
exports.isEnumValue = isEnumValue;
function has(value, keys) {
    if (!isObject(value))
        return false;
    if (!isArray(keys))
        keys = [keys];
    for (const key of keys) {
        if (!(key in value))
            return false;
    }
    return true;
}
exports.has = has;
function instanceOf(value, ctorOrName) {
    if (!isObject(value))
        return false;
    if (!isString(ctorOrName))
        return value instanceof ctorOrName;
    let proto = Object.getPrototypeOf(value);
    while (proto) {
        if (proto.constructor.name === ctorOrName)
            return true;
        proto = Object.getPrototypeOf(proto);
    }
    return false;
}
exports.instanceOf = instanceOf;
