Files
2026-09-13 18:50:58 -07:00

14 lines
486 B
TypeScript

/**
* A rendered tree node's children as the element table built them, or
* none for a string, a null, or a childless element.
*
* @param node an element, a string child, or anything else
* @returns the children array, possibly empty
*/
export function childrenOf(node: unknown): readonly unknown[] {
const isElement = typeof node === 'object' && node !== null
const held: unknown = isElement ? Reflect.get(node, 'children') : null
return Array.isArray(held) ? held : []
}