From 10c5021922013d4e6ce269d68290e57d476b2ed2 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 30 Dec 2023 15:48:04 -0400 Subject: html: implement isHTML with oneOf --- src/util/html.js | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'src/util/html.js') diff --git a/src/util/html.js b/src/util/html.js index edc210b0..174a515d 100644 --- a/src/util/html.js +++ b/src/util/html.js @@ -7,6 +7,10 @@ import {empty, typeAppearance} from '#sugar'; import * as commonValidators from '#validators'; const { + is, + isArray, + isString, + oneOf, validateArrayItems, validateInstanceOf, } = commonValidators; @@ -1213,26 +1217,19 @@ export const isTag = export const isTemplate = validateInstanceOf(Template); -export function isHTML(value) { - if (typeof value === 'string') { - return true; - } - - if (value === null || value === undefined || value === false) { - return true; - } - - if (isBlank(value) || value instanceof Tag || value instanceof Template) { - return true; - } +export const isArrayOfHTML = + validateArrayItems(value => isHTML(value)); - if (isArrayOfHTML(value)) { - return true; - } +export const isHTML = + oneOf( + is(null, undefined, false), + isString, + isTag, + isTemplate, - throw new TypeError( - `Expected html (tag, template, or blank), got ${typeAppearance(value)}`); -} + value => { + isArray(value); + return value.length === 0; + }, -export const isArrayOfHTML = - validateArrayItems(isHTML); + isArrayOfHTML); -- cgit 1.3.0-6-gf8a5