« get me outta code hell

html: Attributes: push() util - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util/html.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-08-16 15:19:30 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-08-16 15:19:30 -0300
commit9da32b4b2e255801307caa8f62b7dd49aafcf96b (patch)
tree6dbdef800aa4dc7fabaef7fdab87ab0404bc3a97 /src/util/html.js
parentadf0adde987a368298e135c23ce307efbc38d888 (diff)
html: Attributes: push() util
Diffstat (limited to 'src/util/html.js')
-rw-r--r--src/util/html.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/util/html.js b/src/util/html.js
index 712a0a68..4e243f7d 100644
--- a/src/util/html.js
+++ b/src/util/html.js
@@ -470,6 +470,18 @@ export class Attributes {
     return delete this.#attributes[attribute];
   }
 
+  push(attribute, ...values) {
+    const oldValue = this.get(attribute);
+    const newValue =
+      (Array.isArray(oldValue)
+        ? oldValue.concat(values)
+     : oldValue
+        ? [oldValue, ...values]
+        : values);
+    this.set(attribute, newValue);
+    return newValue;
+  }
+
   toString() {
     return Object.entries(this.attributes)
       .map(([key, val]) => {