<commit_before>define([
    'framework/framework',
    'framework/libs/core-modules/akqa-core/utils'
],
function (App, CoreUtils) {

    var Utils = function () {
        this.initialize();
    };

    Utils.prototype = {

        /**
         * Initialize.
         */
        initialize: function () {
            this._setupBindPolyfill();
        },

        /**
         * Adds a CSS class to an element.
         * @param {HTMLElement} el - The element to add a class to.
         * @param {string} className - The css class value to add
         */
        addClass: function  (el, className) {
            if (!this.hasClass(el, className)) {
                var existingNames = el.className;
                if (existingNames) {
                    el.className = existingNames + ' ';
                }
                el.className = el.className + className;
            }
        },

        /**
         * Remvoes a CSS class from an element.
         * @param {HTMLElement} el - The element to remove class from.
         * @param {string} className - The css class value to remove
         */
        removeClass: function (el, className) {
            var re;
            if (this.hasClass(el, className)) {

                if (el.className === className) {
                    // if the only class that exists,  remove to 
                     el.className = '';
                } else {
                    re = '[\\s]*' + className;
                    re = new RegExp(re, 'i');
                    el.className = el.className.replace(re, '');
                }
            }
        },

        /**
         * Checks if an element has a class.
         * @param {HTMLElement} el - The element to check.
         * @param {string} className - The css class value to check
         */
        hasClass: function (el, className) {
            return el.className.indexOf(className) !== -1;
        },

        /**
         * Creates an HTML Element from an html string.
         * @param {string} html - String of html
         * @returns {HTMLElement} - Returns and html element node
         */
        createHtmlElement: function (html) {
            var tempParentEl,
                el;
            if (html) {
                html = this.trim(html);
                tempParentEl = document.createElement('div');
                tempParentEl.innerHTML = html;
                el = tempParentEl.childNodes[0];
                return tempParentEl.removeChild(el);
            }
        },

        /**
         * Wrap a container element around another element.
         * @param {HTMLElement} el - The element to be wrapped
         * @param {string} html - The wrapper element
         */
        wrapHtmlElement: function (el, html) {
            var origContainer = el.parentNode,
                container = this.createHtmlElement(html);
            origContainer.replaceChild(container, el);
            container.innerHTML = el.outerHTML;
            return container;
        },

        /**
         * Zaps whitespace from both ends of a string.
         * @param {string} val - The string value to trim
         * @returns {string} Returns a trimmed string
         */
        trim: function (val) {
            if (!String.prototype.trim) {
                String.prototype.trim = function () {
                    return val.replace(/^\s+|\s+$/g, '');
                };
            } else {
                val = val.trim();
            }
            return val;
        },

        /**
         * Gets a simplified mapping of all attributes of an element.
         * @param {HTMLElement} el - The element containing attributes
         * @returns {object} - Returns an object containing all attribute mappings
         */
        getElementAttrMap: function (el) {
            var attrs = el.attributes,
                map = {};
            if (attrs.length) {
                for (var i = 0; i < attrs.length; i++) {<commit_msg>Fixed issue where the element returned from wrapHtmlElement method were not the same as the one passed to it<commit_after>define([
    'framework/framework',
    'framework/libs/core-modules/akqa-core/utils'
],
function (App, CoreUtils) {

    var Utils = function () {
        this.initialize();
    };

    Utils.prototype = {

        /**
         * Initialize.
         */
        initialize: function () {
            this._setupBindPolyfill();
        },

        /**
         * Adds a CSS class to an element.
         * @param {HTMLElement} el - The element to add a class to.
         * @param {string} className - The css class value to add
         */
        addClass: function  (el, className) {
            if (!this.hasClass(el, className)) {
                var existingNames = el.className;
                if (existingNames) {
                    el.className = existingNames + ' ';
                }
                el.className = el.className + className;
            }
        },

        /**
         * Remvoes a CSS class from an element.
         * @param {HTMLElement} el - The element to remove class from.
         * @param {string} className - The css class value to remove
         */
        removeClass: function (el, className) {
            var re;
            if (this.hasClass(el, className)) {

                if (el.className === className) {
                    // if the only class that exists,  remove to 
                     el.className = '';
                } else {
                    re = '[\\s]*' + className;
                    re = new RegExp(re, 'i');
                    el.className = el.className.replace(re, '');
                }
            }
        },

        /**
         * Checks if an element has a class.
         * @param {HTMLElement} el - The element to check.
         * @param {string} className - The css class value to check
         */
        hasClass: function (el, className) {
            return el.className.indexOf(className) !== -1;
        },

        /**
         * Creates an HTML Element from an html string.
         * @param {string} html - String of html
         * @returns {HTMLElement} - Returns and html element node
         */
        createHtmlElement: function (html) {
            var tempParentEl,
                el;
            if (html) {
                html = this.trim(html);
                tempParentEl = document.createElement('div');
                tempParentEl.innerHTML = html;
                el = tempParentEl.childNodes[0];
                return tempParentEl.removeChild(el);
            }
        },

        /**
         * Wrap a container element around another element.
         * @param {HTMLElement} el - The element to be wrapped
         * @param {string} html - The wrapper element
         */
        wrapHtmlElement: function (el, html) {
            var origContainer = el.parentNode,
                container = this.createHtmlElement(html);
            origContainer.replaceChild(container, el);
            container.appendChild(el);
            return container;
        },

        /**
         * Zaps whitespace from both ends of a string.
         * @param {string} val - The string value to trim
         * @returns {string} Returns a trimmed string
         */
        trim: function (val) {
            if (!String.prototype.trim) {
                String.prototype.trim = function () {
                    return val.replace(/^\s+|\s+$/g, '');
                };
            } else {
                val = val.trim();
            }
            return val;
        },

        /**
         * Gets a simplified mapping of all attributes of an element.
         * @param {HTMLElement} el - The element containing attributes
         * @returns {object} - Returns an object containing all attribute mappings
         */
        getElementAttrMap: function (el) {
            var attrs = el.attributes,
                map = {};
            if (attrs.length) {
                for (var i = 0; i < attrs.length; i++) {
{'fraction_non_alphanumeric': 0.1038183179435987, 'fraction_numerical': 0.0007486897928624906, 'mean_word_length': 1.351819248826291, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6393948', 'n_tokens_mistral': 2040, 'n_tokens_neox': 1963, 'n_words': 611}