push.js 625 B

123456789101112131415161718192021222324252627
  1. const push = (name, action) => {
  2. if (typeof(action) !== "function") {
  3. throw new TypeError("Action must be an function.");
  4. }
  5. if (typeof(name) !== "string") {
  6. throw new TypeError("Name of the push must be string.");
  7. }
  8. const target = document.createElement("input");
  9. target.type = "button";
  10. target.name = name;
  11. target.id = "push-" + name;
  12. target.value = name
  13. .toUpperCase()
  14. .replaceAll("-", " ")
  15. .replaceAll("_", " ");
  16. target.classList.add("push");
  17. target.addEventListener("click", action);
  18. return target;
  19. };
  20. export { push };