import { JSXPrimitive, JSXElement } from './jsx' /** * A fast duck-type to check whether any value is a JSX Element. A JSX Element * must always be an object with *at least* a string `elementName`, so that’s * all we check for. */ export const isJSXElement = (value: any): value is JSXElement => value != null && typeof value === 'object' && typeof value.elementName === 'string' /** * Gets whether a value is a `JSXPrimitive` */ export const isJSXPrimitive = (value: any): value is JSXPrimitive => value == null || typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string' /** * Transforms a JSX primitive node to a string. * * If the node is null or undefined, an empty string is returned. If the node * is a boolean an empty string is returned (even for `true`!). If the node is * a number the node gets cast into a string. If the node is a string, nothing * happens. * * These are fairly intuitive rules, all except for `true` returning an empty * string. */ export const primitiveToString = (node: JSXPrimitive): string => { if (node == null) return '' if (typeof node === 'boolean') return '' return String(node) }