UNPKG

sipp

Version:

An Opinionated, High-Productivity MVC Web Framework in TypeScript

51 lines 1.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Fragment = exports.h = void 0; function stringifyChildren(child) { let stringifiedChild = typeof child === 'string' ? child : ''; if (!stringifiedChild) { if (child instanceof String) { stringifiedChild = child.toString(); } if (Array.isArray(child)) { stringifiedChild = child.map(stringifyChildren).join(''); } else if (child && typeof child.toString === 'function') { stringifiedChild = child.toString(); } if (!child && child !== null) { stringifiedChild = `${child}`; } } return stringifiedChild; } const h = (tagName, props, ...children) => { if (typeof tagName === 'function') { return tagName(Object.assign({ children }, props)); } let stringifiedChildren = children.map(stringifyChildren).join(''); let stringifiedProps = ''; if (props) { stringifiedProps = Object.entries(props) .map(([key, value]) => { if (value == null) { return ''; } if (value && typeof value.toString === 'function') { return `${key}="${value.toString()}"`; } return `${key}="${value}"`; }) .join(' '); } return `<${tagName}${stringifiedProps ? ' ' + stringifiedProps : ''}>${stringifiedChildren}</${tagName}>`; }; exports.h = h; const Fragment = ({ children } = { children: undefined }) => { if (!children) { return ''; } return children.map(stringifyChildren).join(''); }; exports.Fragment = Fragment; //# sourceMappingURL=jsx.js.map