index.cjs 983 B

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. function crelt() {
  3. var elt = arguments[0];
  4. if (typeof elt == "string") elt = document.createElement(elt);
  5. var i = 1, next = arguments[1];
  6. if (next && typeof next == "object" && next.nodeType == null && !Array.isArray(next)) {
  7. for (var name in next) if (Object.prototype.hasOwnProperty.call(next, name)) {
  8. var value = next[name];
  9. if (typeof value == "string") elt.setAttribute(name, value);
  10. else if (value != null) elt[name] = value;
  11. }
  12. i++;
  13. }
  14. for (; i < arguments.length; i++) add(elt, arguments[i]);
  15. return elt
  16. }
  17. function add(elt, child) {
  18. if (typeof child == "string") {
  19. elt.appendChild(document.createTextNode(child));
  20. } else if (child == null) ; 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. }
  28. module.exports = crelt;