| 1234567891011121314151617181920212223242526272829303132333435363738 |
- const push = (name, action, customisation = null) => {
- if (action !== null && typeof(action) !== "function") {
- throw new TypeError("Action must be an function.");
- }
- if (typeof(name) !== "string") {
- throw new TypeError("Name of the push must be string.");
- }
- if (customisation !== null && typeof(customisation) !== "function") {
- throw new TypeError("Customisation must be null or function");
- }
- const target = document.createElement("button");
-
- target.type = "button";
- target.name = name;
- target.id = "push-" + name;
-
- target.innerText = name
- .toUpperCase()
- .replaceAll("-", " ")
- .replaceAll("_", " ");
- target.classList.add("push");
-
- if (action !== null) {
- target.addEventListener("click", action);
- }
- if (customisation) {
- customisation(target);
- }
- return target;
- };
- export { push };
|