index.es.js 951 B

12345678910111213141516171819202122232425262728
  1. export default function crelt() {
  2. var elt = arguments[0]
  3. if (typeof elt == "string") elt = document.createElement(elt)
  4. var i = 1, next = arguments[1]
  5. if (next && typeof next == "object" && next.nodeType == null && !Array.isArray(next)) {
  6. for (var name in next) if (Object.prototype.hasOwnProperty.call(next, name)) {
  7. var value = next[name]
  8. if (typeof value == "string") elt.setAttribute(name, value)
  9. else if (value != null) elt[name] = value
  10. }
  11. i++
  12. }
  13. for (; i < arguments.length; i++) add(elt, arguments[i])
  14. return elt
  15. }
  16. function add(elt, child) {
  17. if (typeof child == "string") {
  18. elt.appendChild(document.createTextNode(child))
  19. } else if (child == null) {
  20. } else if (child.nodeType != null) {
  21. elt.appendChild(child)
  22. } else if (Array.isArray(child)) {
  23. for (var i = 0; i < child.length; i++) add(elt, child[i])
  24. } else {
  25. throw new RangeError("Unsupported child node: " + child)
  26. }
  27. }