From 474e8afe7328b80cda5e437e1d1b8c1191425d72 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 13 Jul 2022 00:34:36 -0300 Subject: begin htmlifying listings & listing specs --- src/util/html.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/util/html.js') diff --git a/src/util/html.js b/src/util/html.js index 338df71b..bdb385b5 100644 --- a/src/util/html.js +++ b/src/util/html.js @@ -55,7 +55,7 @@ export function tag(tagName, ...args) { } if (attrs) { - const attrString = attributes(args[0]); + const attrString = attributes(attrs); if (attrString) { openTag = `${tagName} ${attrString}`; } @@ -121,3 +121,19 @@ export function attributes(attribs) { ) .join(' '); } + +// Ensures the passed value is an array of elements, for usage in [...spread] +// syntax. This may be used when it's not guaranteed whether the return value of +// an external function is one child or an array, or in combination with +// conditionals, e.g. fragment(cond && [x, y, z]). +export function fragment(childOrChildren) { + if (!childOrChildren) { + return []; + } + + if (Array.isArray(childOrChildren)) { + return childOrChildren; + } + + return [childOrChildren]; +} -- cgit 1.3.0-6-gf8a5