0789c24fe818f9ae7060da92acd07f6555474f8bb97653b586460909978e63eaa24c82164e18c2d47788efd8188cc50ac12c763d1c2d89abef8a8bd100dbfa 867 B

123456789101112131415161718192021222324252627282930313233343536
  1. function getConsole() {
  2. if (typeof window !== "undefined") {
  3. return window.console;
  4. }
  5. return global.console;
  6. }
  7. const console = getConsole();
  8. function cached(fn) {
  9. const cache = Object.create(null);
  10. return function cachedFn(str) {
  11. const hit = cache[str];
  12. return hit || (cache[str] = fn(str));
  13. };
  14. }
  15. const regex = /-(\w)/g;
  16. const camelize = cached(str =>
  17. str.replace(regex, (_, c) => (c ? c.toUpperCase() : ""))
  18. );
  19. function removeNode(node) {
  20. if (node.parentElement !== null) {
  21. node.parentElement.removeChild(node);
  22. }
  23. }
  24. function insertNodeAt(fatherNode, node, position) {
  25. const refNode =
  26. position === 0
  27. ? fatherNode.children[0]
  28. : fatherNode.children[position - 1].nextSibling;
  29. fatherNode.insertBefore(node, refNode);
  30. }
  31. export { insertNodeAt, camelize, console, removeNode };