« get me outta code hell

real pragma, and some eslint fixes - 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>2022-06-26 18:02:27 -0300
committer(quasar) nebula <qznebula@protonmail.com>2022-06-26 18:02:27 -0300
commitc75b029160248b6935e5c0f5156cc7a870311e82 (patch)
tree693c5cca195e50b048b0086e768aa06a7c1986ee /src/util/html.js
parentf65e712fe8b8b1a196da2db286ebc6a5c9bf7433 (diff)
real pragma, and some eslint fixes
Diffstat (limited to 'src/util/html.js')
-rw-r--r--src/util/html.js60
1 files changed, 30 insertions, 30 deletions
diff --git a/src/util/html.js b/src/util/html.js
index 913dc7b..f5b7bdc 100644
--- a/src/util/html.js
+++ b/src/util/html.js
@@ -1,23 +1,23 @@
-// @format
-//
+/** @format */
+
 // Some really simple functions for formatting HTML content.
 
 // COMPREHENSIVE!
 // https://html.spec.whatwg.org/multipage/syntax.html#void-elements
 export const selfClosingTags = [
-  "area",
-  "base",
-  "br",
-  "col",
-  "embed",
-  "hr",
-  "img",
-  "input",
-  "link",
-  "meta",
-  "source",
-  "track",
-  "wbr",
+  'area',
+  'base',
+  'br',
+  'col',
+  'embed',
+  'hr',
+  'img',
+  'input',
+  'link',
+  'meta',
+  'source',
+  'track',
+  'wbr',
 ];
 
 // Pass to tag() as an attri8utes key to make tag() return a 8lank string
@@ -32,7 +32,7 @@ export function tag(tagName, ...args) {
   let content;
   let attrs;
 
-  if (typeof args[0] === "object" && !Array.isArray(args[0])) {
+  if (typeof args[0] === 'object' && !Array.isArray(args[0])) {
     attrs = args[0];
     content = args[1];
   } else {
@@ -44,7 +44,7 @@ export function tag(tagName, ...args) {
   }
 
   if (attrs?.[onlyIfContent] && !content) {
-    return "";
+    return '';
   }
 
   if (attrs) {
@@ -59,17 +59,17 @@ export function tag(tagName, ...args) {
   }
 
   if (Array.isArray(content)) {
-    content = content.filter(Boolean).join("\n");
+    content = content.filter(Boolean).join('\n');
   }
 
   if (content) {
-    if (content.includes("\n")) {
+    if (content.includes('\n')) {
       return (
         `<${openTag}>\n` +
         content
-          .split("\n")
-          .map((line) => "    " + line + "\n")
-          .join("") +
+          .split('\n')
+          .map((line) => '    ' + line + '\n')
+          .join('') +
         `</${tagName}>`
       );
     } else {
@@ -85,18 +85,18 @@ export function tag(tagName, ...args) {
 }
 
 export function escapeAttributeValue(value) {
-  return value.replaceAll('"', "&quot;").replaceAll("'", "&apos;");
+  return value.replaceAll('"', '&quot;').replaceAll("'", '&apos;');
 }
 
 export function attributes(attribs) {
   return Object.entries(attribs)
     .map(([key, val]) => {
-      if (typeof val === "undefined" || val === null) return [key, val, false];
-      else if (typeof val === "string") return [key, val, true];
-      else if (typeof val === "boolean") return [key, val, val];
-      else if (typeof val === "number") return [key, val.toString(), true];
+      if (typeof val === 'undefined' || val === null) return [key, val, false];
+      else if (typeof val === 'string') return [key, val, true];
+      else if (typeof val === 'boolean') return [key, val, val];
+      else if (typeof val === 'number') return [key, val.toString(), true];
       else if (Array.isArray(val))
-        return [key, val.filter(Boolean).join(" "), val.length > 0];
+        return [key, val.filter(Boolean).join(' '), val.length > 0];
       else
         throw new Error(
           `Attribute value for ${key} should be primitive or array, got ${typeof val}`
@@ -104,9 +104,9 @@ export function attributes(attribs) {
     })
     .filter(([key, val, keep]) => keep)
     .map(([key, val]) =>
-      typeof val === "boolean"
+      typeof val === 'boolean'
         ? `${key}`
         : `${key}="${escapeAttributeValue(val)}"`
     )
-    .join(" ");
+    .join(' ');
 }