All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ui.static.regexInspector.js Maven / Gradle / Ivy

There is a newer version: 0.8.0
Show newest version
function regexInspectorDispose(textInput) {
    textInput.popover("dispose");
}

function regexInspectorShow(textInput) {
    textInput.popover("show");
}

function regexInspector(textInput, options) {
    textInput.popover("dispose");
    textInput.popover({
        trigger: 'focus',
        placement: 'bottom',
        container: 'body',
        html: true,
        content: function () {
            return generatePopupHtml(textInput.val(), options);
        },
        title: function() {
            return options.title ? options.title : "Regex matches";
        },
    });
    if (!options.disableChangeHook) {
        textInput.on("keypress, input", function () {
            textInput.popover('hide');
            textInput.popover('show');
        });
    } else {
        textInput.popover('show');
    }
}

function generatePopupHtml(inputValue, options) {
    let result;
    try {
        result = processRegex(inputValue, options);
    } catch (e) {
        return 'Invalid regex: ' + e + '';
    }
    let html = "";
    html += "";
    html += "";
    html += "";
    html += "";
    html += "";
    html += "";
    html += "";
    html += "";
    html += "";
    html += "
Hits ("+result.matching.length+")Misses ("+result.filtered.length+")
"; result.matching.forEach(function (value) { html += value + "
"; }); html += "
"; result.filtered.forEach(function (value) { html += value + "
"; }); html += "
"; return html; } function processRegex(inputValue, options) { let value = options.valuePreProcessor ? options.valuePreProcessor(inputValue) : inputValue; let data = options.source; if (value.trim().length === 0) { return { matching: data, filtered: [] }; } let matching = []; let filtered = []; let regex = options.matchEntire ? RegExp("^" + value + "$") : RegExp(value); data.forEach(function (value) { if (value.match(regex)) { matching.push(value); } else { filtered.push(value); } }); return { matching: matching, filtered: filtered }; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy