UNPKG

1.13 kBJavaScriptView Raw
1!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.domCreateElementQuerySelector=t()}(this,function(){"use strict";function e(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"div",n=e.match(/^[a-z]+/i),i=e.match(/#([a-z]+[a-z0-9-]*)/gi),o=e.match(/\.([a-z]+[a-z0-9-]*)/gi),a=e.match(/\[([a-z][a-z-]+)(=['|"]?([^\]]*)['|"]?)?\]/gi),r=n?n[0]:"div";if(i&&i.length>1)throw t("only 1 ID is allowed");var c=document.createElement(r);if(i&&(c.id=i[0].replace("#","")),o){var d=o.join(" ").replace(/\./g,"");c.setAttribute("class",d)}a&&a.forEach(function(e){e=e.slice(0,-1).slice(1);var t=e.split("="),n=t[0],i=t[1];i&&(i=i.replace(/^['"](.*)['"]$/,"$1")),c.setAttribute(n,i||"")});for(var l=arguments.length,f=Array(l>1?l-1:0),u=1;u<l;u++)f[u-1]=arguments[u];return f.forEach(function(e){"string"==typeof e||"number"==typeof e?c.appendChild(document.createTextNode(e)):e.nodeType===document.ELEMENT_NODE&&c.appendChild(e)}),c}function t(e){this.message=e,this.name="CreateElementException"}return module.exports=exports.default,e});