"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get equalsIgnoreCase () {
        return equalsIgnoreCase;
    },
    get isJSON () {
        return isJSON;
    },
    get isPercentValue () {
        return isPercentValue;
    },
    get randomString () {
        return randomString;
    },
    get sanitize () {
        return sanitize;
    },
    get stripTags () {
        return stripTags;
    },
    get substitute () {
        return substitute;
    },
    get toHyphen () {
        return toHyphen;
    },
    get toUpperCaseFirst () {
        return toUpperCaseFirst;
    }
});
const _dompurify = /*#__PURE__*/ _interop_require_default(require("dompurify"));
const _mixed = require("./mixed");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
function toUpperCaseFirst(string) {
    return string[0].toUpperCase() + string.substr(1);
}
function equalsIgnoreCase(...strings) {
    const unique = [];
    let length = strings.length;
    while(length){
        length -= 1;
        const string = (0, _mixed.stringify)(strings[length]).toLowerCase();
        if (unique.indexOf(string) === -1) {
            unique.push(string);
        }
    }
    return unique.length === 1;
}
function randomString() {
    /**
   * @returns {string}
   */ function s4() {
        return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
    }
    return s4() + s4() + s4() + s4();
}
function isJSON(string) {
    if (typeof string !== 'string') {
        return false;
    }
    try {
        const parsed = JSON.parse(string);
        return typeof parsed === 'object' && parsed !== null;
    } catch  {
        return false;
    }
}
function isPercentValue(value) {
    return /^([0-9][0-9]?%$)|(^100%$)/.test(value);
}
function substitute(template, variables = {}) {
    return `${template}`.replace(/(?:\\)?\[([^[\]]+)]/g, (match, name)=>{
        if (match.charAt(0) === '\\') {
            return match.substr(1, match.length - 1);
        }
        return variables[name] === undefined ? '' : variables[name];
    });
}
function stripTags(string) {
    return sanitize(`${string}`, {
        ALLOWED_TAGS: []
    });
}
function sanitize(string, options) {
    return _dompurify.default.sanitize(string, options);
}
function toHyphen(str) {
    if (typeof str !== 'string') {
        return str;
    }
    return str.replace(/([A-Z])/g, '-$1').replace(/_/g, '-').toLowerCase();
}
