(function language_init() {
    "use strict";
    const language = {
        setlexer: function language_setlexer(input) {
            const langmap = {
                c_cpp: "script",
                coldfusion: "markup",
                csharp: "script",
                css: "style",
                csv: "csv",
                dustjs: "markup",
                ejs: "markup",
                go: "markup",
                handlebars: "markup",
                html: "markup",
                html_ruby: "markup",
                java: "script",
                javascript: "script",
                json: "script",
                jsp: "markup",
                jsx: "script",
                less: "style",
                markdown: "markdown",
                markup: "markup",
                php: "script",
                phphtml: "markup",
                qml: "style",
                scss: "style",
                swig: "markup",
                text: "text",
                titanium: "script",
                tss: "script",
                twig: "markup",
                typescript: "script",
                velocity: "markup",
                xhtml: "markup",
                xml: "markup"
            };
            if (typeof input !== "string") {
                return "script";
            }
            if (input.indexOf("html") > -1) {
                return "markup";
            }
            if (langmap[input] === undefined) {
                return "script";
            }
            return langmap[input];
        },
        nameproper: function language_nameproper(input) {
            const langmap = {
                c_cpp: "C++ (Not yet supported)",
                coldfusion: "ColdFusion",
                csharp: "C#",
                dustjs: "Dust.js",
                ejs: "EJS Template",
                elm: "Elm Template",
                go: "Go Lang Template",
                handlebars: "Handlebars Template",
                html_ruby: "ERB (Ruby) Template",
                java: "Java",
                javascript: "JavaScript",
                jsp: "JSTL (JSP)",
                jsx: "React JSX",
                liquid: "Liquid Template",
                markdown: "markdown",
                markup: "markup",
                phphtml: "HTML/PHP",
                scss: "SCSS",
                text: "Plain Text",
                titanium: "Titanium Stylesheets",
                tss: "Titanium Stylesheets",
                twig: "HTML TWIG Template",
                typescript: "TypeScript",
                velocity: "Apache Velocity",
                volt: "Volt Template"
            };
            if (typeof input !== "string" || langmap[input] === undefined) {
                return input.toUpperCase();
            }
            return langmap[input];
        },
        // * [0] = language value for ace mode
        // * [1] = prettydiff language category (lexer) from [0]
        // * [2] = pretty formatting for text output to user
        auto: function language_auto(sample, defaultLang) {
            let b = [], c = 0;
            const vartest = ((/(((var)|(let)|(const)|(function)|(import))\s+(\w|\$)+[a-zA-Z0-9]*)/).test(sample) === true && (/@import/).test(sample) === false), finalstatic = (/((((final)|(public)|(private))\s+static)|(static\s+void))/).test(sample), output = function language_auto_output(langname) {
                if (langname === "unknown") {
                    return [defaultLang, language.setlexer(defaultLang), "unknown"];
                }
                if (langname === "xhtml" || langname === "markup") {
                    return ["xml", language.setlexer("xml"), "XHTML"];
                }
                if (langname === "tss") {
                    return ["tss", language.setlexer("tss"), "Titanium Stylesheets"];
                }
                if (langname === "phphtml") {
                    return ["php", language.setlexer(langname), language.nameproper(langname)];
                }
                return [langname, language.setlexer(langname), language.nameproper(langname)];
            }, cssA = function language_auto_cssA() {
                if ((/\$[a-zA-Z]/).test(sample) === true || (/\{\s*(\w|\.|\$|#)+\s*\{/).test(sample) === true) {
                    return output("scss");
                }
                if ((/@[a-zA-Z]/).test(sample) === true || (/\{\s*(\w|\.|@|#)+\s*\{/).test(sample) === true) {
                    return output("less");
                }
                return output("css");
            }, notmarkup = function language_auto_notmarkup() {
                let d = 1, join = "", flaga = false, flagb = false;
                const publicprivate = (/((public)|(private))\s+(static\s+)?(((v|V)oid)|(class)|(final))/).test(sample), javascriptA = function language_auto_notmarkup_javascriptA() {
                    if (sample.indexOf("(") > -1 || sample.indexOf("=") > -1 || (sample.indexOf(";") > -1 && sample.indexOf("{") > -1)) {
                        if (vartest === false && ((/\n\s+#region\s/).test(sample) === true || (/\[\w+:/).test(sample) === true)) {
                            return output("csharp");
                        }
                        if (finalstatic === true || (/\w<\w+(,\s+\w+)*>/).test(sample) === true) {
                            if ((/:\s*((number)|(string))/).test(sample) === false && vartest === false && (finalstatic === true || publicprivate === true)) {
                                return output("java");
                            }
                            return output("typescript");
                        }
                        if ((/final\s+static/).test(sample) === true) {
                            return output("java");
                        }
                        return output("javascript");
                    }
                    return output("unknown");
                }, cssOrJavaScript = function language_auto_notmarkup_cssOrJavaScript() {
                    if ((/:\s*((number)|(string))/).test(sample) === true && (/((public)|(private))\s+/).test(sample) === true) {
                        return output("typescript");
                    }
                    if ((/import\s+java(\.|(fx))/).test(sample) === true || (/((public)|(private))\s+static\s+/).test(sample) === true) {
                        return output("java");
                    }
                    if ((/\sclass\s+\w/).test(sample) === false && (/<[a-zA-Z]/).test(sample) === true && (/<\/[a-zA-Z]/).test(sample) === true && ((/\s?\{%/).test(sample) === true || (/\{(\{|#)(?!(\{|#|=))/).test(sample) === true)) {
                        return output("twig");
                    }
                    if ((/^(\s*(\$|@))/).test(sample) === false && (/(\};?\s*)$/).test(sample) === true) {
                        if ((/export\s+default\s+\{/).test(sample) === true || (/(\?|:)\s*(\{|\[)/).test(sample) === true || (/(\{|\s|;)render\s*\(\)\s*\{/).test(sample) === true || (/^(\s*return;?\s*\{)/).test(sample) === true) {
                            return output("javascript");
                        }
                    }
                    if ((/\{\{#/).test(sample) === true && (/\{\{\//).test(sample) === true && (/<\w/).test(sample) === true) {
                        return output("handlebars");
                    }
                    if ((/\{\s*(\w|\.|@|#)+\s*\{/).test(sample) === true) {
                        return output("less");
                    }
                    if ((/\$(\w|-)/).test(sample) === true) {
                        return output("scss");
                    }
                    if ((/(;|\{|:)\s*@\w/).test(sample) === true) {
                        return output("less");
                    }
                    if ((/class\s+\w+\s+\{/).test(sample) === true) {
                        return output("java");
                    }
                    return output("css");
                };
                if (d < c) {
                    do {
                        if (flaga === false) {
                            if (b[d] === "*" && b[d - 1] === "/") {
                                b[d - 1] = "";
                                flaga = true;
                            }
                            else if (flagb === false && b[d] === "f" && d < c - 6 && b[d + 1] === "i" && b[d + 2] === "l" && b[d + 3] === "t" && b[d + 4] === "e" && b[d + 5] === "r" && b[d + 6] === ":") {
                                flagb = true;
                            }
                        }
                        else if (flaga === true && b[d] === "*" && d !== c - 1 && b[d + 1] === "/") {
                            flaga = false;
                            b[d] = "";
                            b[d + 1] = "";
                        }
                        else if (flagb === true && b[d] === ";") {
                            flagb = false;
                            b[d] = "";
                        }
                        if (flaga === true || flagb === true) {
                            b[d] = "";
                        }
                        d = d + 1;
                    } while (d < c);
                }
                join = b.join("");
                if ((/\s\/\//).test(sample) === false && (/\/\/\s/).test(sample) === false && (/^(\s*(\{|\[)(?!%))/).test(sample) === true && (/((\]|\})\s*)$/).test(sample) && sample.indexOf(",") !== -1) {
                    return output("json");
                }
                if ((/((\}?(\(\))?\)*;?\s*)|([a-z0-9]("|')?\)*);?(\s*\})*)$/i).test(sample) === true && (vartest === true || publicprivate === true || (/console\.log\(/).test(sample) === true || (/export\s+default\s+class\s+/).test(sample) === true || (/document\.get/).test(sample) === true || (/((=|(\$\())\s*function)|(\s*function\s+(\w*\s+)?\()/).test(sample) === true || sample.indexOf("{") === -1 || (/^(\s*if\s+\()/).test(sample) === true)) {
                    return javascriptA();
                }
                // * u007b === {
                // * u0024 === $
                // * u002e === .
                if (sample.indexOf("{") > -1 && ((/^(\s*[\u007b\u0024\u002e#@a-z0-9])/i).test(sample) === true || (/^(\s*\/(\*|\/))/).test(sample) === true || (/^(\s*\*\s*\{)/).test(sample) === true) && (/^(\s*if\s*\()/).test(sample) === false && (/=\s*(\{|\[|\()/).test(join) === false && (((/(\+|-|=|\?)=/).test(join) === false || (/\/\/\s*=+/).test(join) === true) || ((/=+('|")?\)/).test(sample) === true && (/;\s*base64/).test(sample) === true)) && (/function(\s+\w+)*\s*\(/).test(join) === false) {
                    if ((/\s*#((include)|(define)|(endif))\s+/).test(sample)) {
                        return output("c_cpp");
                    }
                    return cssOrJavaScript();
                }
                if ((/"\s*:\s*\{/).test(sample) === true) {
                    return output("tss");
                }
                if (sample.indexOf("{%") > -1) {
                    return output("twig");
                }
                return output("unknown");
            }, markup = function language_auto_markup() {
                const html = function language_auto_markup_html() {
                    if ((/<%\s*\}/).test(sample) === true) {
                        return output("ejs");
                    }
                    if ((/<%\s*end/).test(sample) === true) {
                        return output("html_ruby");
                    }
                    if ((/\{\{(#|\/|\{)/).test(sample) === true) {
                        return output("handlebars");
                    }
                    if ((/\{\{end\}\}/).test(sample) === true) {
                        //place holder for Go lang templates
                        return output("html");
                    }
                    if ((/\s?\{%/).test(sample) === true && (/\{(\{|#)(?!(\{|#|=))/).test(sample) === true) {
                        return output("twig");
                    }
                    if ((/<\?/).test(sample) === true) {
                        if ((/^\s*<\?/).test(sample) === true && (/\?>\s*$/).test(sample) === true) {
                            return output("php");
                        }
                        return output("phphtml");
                    }
                    if ((/<jsp:include\s/).test(sample) === true || (/<c:((set)|(if))\s/).test(sample) === true) {
                        return output("jsp");
                    }
                    if ((/\{(#|\?|\^|@|<|\+|~)/).test(sample) === true && (/\{\//).test(sample) === true) {
                        return output("dustjs");
                    }
                    return output("html");
                };
                if ((/<cfset\s/i).test(sample) === true || (/<cfif\s/i).test(sample) === true) {
                    return output("coldfusion");
                }
                if ((/^(\s*<!doctype\u0020html>)/i).test(sample) === true ||
                    (/^(\s*<html)/i).test(sample) === true ||
                    ((/<form\s/i).test(sample) === true &&
                        (/<label\s/i).test(sample) === true &&
                        (/<input\s/i).test(sample) === true) ||
                    ((/^(\s*<!DOCTYPE\s+((html)|(HTML))\s+PUBLIC\s+)/).test(sample) === true &&
                        (/XHTML\s+1\.1/).test(sample) === false &&
                        (/XHTML\s+1\.0\s+(S|s)((trict)|(TRICT))/).test(sample) === false)) {
                    return html();
                }
                if ((/<jsp:include\s/).test(sample) === true || (/<c:((set)|(if))\s/).test(sample) === true) {
                    return output("jsp");
                }
                if ((/<%\s*\}/).test(sample) === true) {
                    return output("ejs");
                }
                if ((/<%\s*end/).test(sample) === true) {
                    return output("html_ruby");
                }
                if ((/\{\{(#|\/|\{)/).test(sample) === true) {
                    return output("handlebars");
                }
                if ((/\{\{end\}\}/).test(sample) === true) {
                    //place holder for Go lang templates
                    return output("xml");
                }
                if ((/\s?\{%/).test(sample) === true && (/\{\{(?!(\{|#|=))/).test(sample) === true) {
                    return output("twig");
                }
                if ((/<\?(?!(xml))/).test(sample) === true) {
                    if ((/^\s*<\?/).test(sample) === true && (/\?>\s*$/).test(sample) === true) {
                        return output("php");
                    }
                    return output("phphtml");
                }
                if ((/\{(#|\?|\^|@|<|\+|~)/).test(sample) === true && (/\{\//).test(sample) === true) {
                    return output("dustjs");
                }
                if ((/<jsp:include\s/).test(sample) === true || (/<c:((set)|(if))\s/).test(sample) === true) {
                    return output("jsp");
                }
                return output("xml");
            };
            if (sample === null) {
                return output("unknown");
            }
            if (((/\n\s*#{1,6}\s+/).test(sample) === true || (/\n\s*(\*|-|(\d+\.))\s/).test(sample) === true) &&
                ((/\[( |x|X)\]/).test(sample) === true || (/\s\*\*\S\D/).test(sample) === true || (/\n\s*```/).test(sample) === true || ((/-+\|(-+\|)+/).test(sample) === true && (/<!--/).test(sample) === false))) {
                return output("markdown");
            }
            if ((/^(\s*<!DOCTYPE\s+html>)/i).test(sample) === true) {
                return output("html");
            }
            if (finalstatic === false && (/^(\s*((if)|(for)|(function))\s*\()/).test(sample) === false && (/(\s|;|\})((if)|(for)|(function\s*\w*))\s*\(/).test(sample) === false && vartest === false && (/return\s*\w*\s*(;|\})/).test(sample) === false && (sample === undefined || (/^(\s*#(?!(!\/)))/).test(sample) === true || ((/\n\s*(\.|@)\w+(\(|(\s*:))/).test(sample) === true && (/>\s*<\w/).test(sample) === false))) {
                return cssA();
            }
            b = sample
                .replace(/\[[a-zA-Z][\w-]*=("|')?[a-zA-Z][\w-]*("|')?\]/g, "")
                .split("");
            c = b.length;
            if ((/^(\s*\{(%|#|\{))/).test(sample) === true) {
                return markup();
            }
            if (((/^([\s\w-]*<)/).test(sample) === false && (/(>[\s\w-]*)$/).test(sample) === false) || finalstatic === true) {
                return notmarkup();
            }
            if ((((/(>[\w\s:]*)?<(\/|!|#)?[\w\s:\-[]+/).test(sample) === true || ((/^\s*</).test(sample) === true && (/<\/\w+(\w|\d)+>\s*$/).test(sample) === true) || (/^(\s*<\?xml)/).test(sample) === true) && ((/^([\s\w]*<)/).test(sample) === true || (/(>[\s\w]*)$/).test(sample) === true)) || ((/^(\s*<s((cript)|(tyle)))/i).test(sample) === true && (/(<\/s((cript)|(tyle))>\s*)$/i).test(sample) === true)) {
                if ((/^([\s\w]*<)/).test(sample) === false || (/(>[\s\w]*)$/).test(sample) === false) {
                    return notmarkup();
                }
                return markup();
            }
            return output("unknown");
        }
    };
    global.prettydiff.api.language = language;
}());
