« get me outta code hell

data: templateCompositeFrom: improve error message consistency - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-09-28 14:00:18 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-28 14:00:18 -0300
commit518647f8b80ffda6d502b1a75656da7f2ae4b9d3 (patch)
tree9a9cdf792be5e74a852688e93bc600166ac2aa57 /src/util
parentd719eff73be9b18a3c83b984e68469c3be91457c (diff)
data: templateCompositeFrom: improve error message consistency
Diffstat (limited to 'src/util')
-rw-r--r--src/util/sugar.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/util/sugar.js b/src/util/sugar.js
index 24d409fb..ef6ab18c 100644
--- a/src/util/sugar.js
+++ b/src/util/sugar.js
@@ -230,6 +230,16 @@ export function escapeRegex(string) {
   return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
 }
 
+// Gets the "look" of some arbitrary value. It's like typeof, but smarter.
+// Don't use this for actually validating types - it's only suitable for
+// inclusion in error messages.
+export function typeAppearance(value) {
+  if (value === null) return 'null';
+  if (value === undefined) return 'undefined';
+  if (Array.isArray(value)) return 'array';
+  return typeof value;
+}
+
 // Binds default values for arguments in a {key: value} type function argument
 // (typically the second argument, but may be overridden by providing a
 // [bindOpts.bindIndex] argument). Typically useful for preparing a function for