From 518647f8b80ffda6d502b1a75656da7f2ae4b9d3 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 28 Sep 2023 14:00:18 -0300 Subject: data: templateCompositeFrom: improve error message consistency --- src/util/sugar.js | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/util') 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 -- cgit 1.3.0-6-gf8a5