« get me outta code hell

validators: is: handle strings with spaces nicer - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/validators.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2026-05-11 19:58:06 -0300
committer(quasar) nebula <qznebula@protonmail.com>2026-05-11 19:58:06 -0300
commit42723c7d476a0ac0595b802e25df38ef27abc208 (patch)
treeeaad403cfa09546bcc8919e4b39e6cdb4bde5397 /src/validators.js
parentae238fcd365f6b668828768e7bae6640414a4a21 (diff)
validators: is: handle strings with spaces nicer
Diffstat (limited to 'src/validators.js')
-rw-r--r--src/validators.js7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/validators.js b/src/validators.js
index 2c3bd8e6..0300f629 100644
--- a/src/validators.js
+++ b/src/validators.js
@@ -196,9 +196,14 @@ export function is(...values) {
     };
   }
 
+  const joiner =
+    (Array.from(values).some(v => typeof v === 'string' && v.includes(' '))
+      ? ', '
+      : ' ');
+
   const fn = (value) => {
     if (!values.has(value)) {
-      throw new TypeError(`Expected one of ${Array.from(values).join(' ')}, got ${value}`);
+      throw new TypeError(`Expected one of ${Array.from(values).join(joiner)}, got ${value}`);
     }
 
     return true;