jsx-async-runtime
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -1,1 +0,1 @@ | ||
function l(t,e,...r){e??={};let n=[];for(let s of r)a(s,n);return e?.children&&a(e.children,n),e.children=n,Object.freeze(n),Object.freeze(e),{type:"tag",tag:t,props:e}}function a(t,e){switch(typeof t){case"string":e.push({type:"textNode",text:t});break;case"number":e.push({type:"textNode",text:t.toString()});break;case"object":if(Array.isArray(t))for(let r of t)a(r,e);else t!=null&&e.push(t);break}}function b(t){return typeof t=="string"?t.replace(h,e=>g[e]||e):t}var g={"&":"&","<":"<",">":">",'"':""","'":"'"},h=new RegExp(`[${Object.keys(g).join("")}]`,"g");function u(t){let e=[];for(let r of t){let n=S(r);n.length>0&&e.push(n)}return e.join(" ")}function S([t,e]){if(e===!0)return t;if(e===!1||e===null||e===void 0)return"";if(typeof e=="object")switch(t){case"style":let r=Object.entries(e).map(([s,i])=>`${s}: ${i}`);return`style="${c(r.join("; "))}"`;case"class":let n=Object.entries(e).filter(([s,i])=>i).map(([s,i])=>s);return n.length>0?`class="${c(n.join(" "))}"`:"";default:return`${t}="${c(JSON.stringify(e))}"`}return`${t}="${c(e.toString())}"`}function c(t){return t.replaceAll('"',""")}function p(t){return{tag:t.tag.toString(),attributes:d(t),children:y(t)}}function d(t){let e=[];for(let[r,n]of Object.entries(t.props))r!=="children"&&e.push([r,n]);return e}function y(t){return t.props.children?Array.isArray(t.props.children)?t.props.children:[t.props.children]:[]}var m=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);async function o(t){if(t===null)return"";switch(typeof t){case"string":return t;case"bigint":case"number":return String(t);case"boolean":case"function":case"symbol":case"undefined":return""}if(t.type==="textNode")return t.text;if(typeof t.tag=="string"){let e=p(t);if(e.tag===""){let r=[];for(let n of e.children){let s=await o(n);s.length>0&&r.push(s)}return r.join("")}else{let r=u(e.attributes),n=r.length?" ":"";if(e.children.length===0&&m.has(e.tag))return`<${e.tag}${n}${r}>`;let s=[];for(let i of e.children){let f=await o(i);f.length>0&&s.push(f)}return`<${e.tag}${n}${r}>${s.join("")}</${e.tag}>`}}else{let e=await t.tag(t.props);return await o(e)}}export{l as createElement,b as escapeEntities,o as jsxToString,o as renderToString}; | ||
function p(t,e,...r){e??={};let n=[];for(let s of r)a(s,n);return e?.children&&a(e.children,n),e.children=n,Object.freeze(n),Object.freeze(e),{type:"tag",tag:t,props:e}}function a(t,e){switch(typeof t){case"string":e.push({type:"textNode",text:t});break;case"number":e.push({type:"textNode",text:t.toString()});break;case"object":if(Array.isArray(t))for(let r of t)a(r,e);else t!=null&&e.push(t);break}}function h(t){return typeof t=="string"?t.replace(b,e=>g[e]||e):t}var g={"&":"&","<":"<",">":">",'"':""","'":"'"},b=new RegExp(`[${Object.keys(g).join("")}]`,"g");function u(t){let e=[];for(let r of t){let n=S(r);n.length>0&&e.push(n)}return e.join(" ")}function S([t,e]){if(e===!0)return t;if(e===!1||e===null||e===void 0)return"";if(typeof e=="object")switch(t){case"style":let r=Object.entries(e).map(([s,i])=>`${s}: ${i}`);return`style="${c(r.join("; "))}"`;case"class":let n=Object.entries(e).filter(([s,i])=>i).map(([s,i])=>s);return n.length>0?`class="${c(n.join(" "))}"`:"";default:return`${t}="${c(JSON.stringify(e))}"`}return`${t}="${c(e.toString())}"`}function c(t){return t.replaceAll('"',""")}function l(t){return{tag:t.tag.toString(),attributes:d(t),children:y(t)}}function d(t){let e=[];for(let[r,n]of Object.entries(t.props))r!=="children"&&e.push([r,n]);return e}function y(t){return t.props.children?Array.isArray(t.props.children)?t.props.children:[t.props.children]:[]}var m=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);async function o(t){if(t===null)return"";switch(typeof t){case"string":return t;case"bigint":case"number":return String(t);case"boolean":case"function":case"symbol":case"undefined":return""}if(t.type==="textNode")return t.text;if(typeof t.tag=="string"){let e=l(t);if(e.tag===""){let r=[];for(let n of e.children){let s=await o.call(this,n);s.length>0&&r.push(s)}return r.join("")}else{let r=u(e.attributes),n=r.length?" ":"";if(e.children.length===0&&m.has(e.tag))return`<${e.tag}${n}${r}>`;let s=[];for(let i of e.children){let f=await o.call(this,i);f.length>0&&s.push(f)}return`<${e.tag}${n}${r}>${s.join("")}</${e.tag}>`}}else{let e=await t.tag.call(this,t.props);return await o.call(this,e)}}export{p as createElement,h as escapeEntities,o as jsxToString,o as renderToString}; |
@@ -0,1 +1,7 @@ | ||
/** | ||
* Escapes special HTML entities in a given input string. | ||
* | ||
* @param {string} input - The input string to escape. | ||
* @return {string} The input string with special HTML entities escaped. | ||
*/ | ||
export declare function escapeEntities(input: string): string; |
@@ -1,1 +0,8 @@ | ||
export declare function jsxToString(jsxElement: JSX.Element): Promise<string>; | ||
/** | ||
* Renders a JSX element to a string representation. | ||
* | ||
* @param {any} this - The (optional) 'this' context of the function. | ||
* @param {JSX.Element} jsxElement - The JSX element to render. | ||
* @return {Promise<string>} The string representation of the rendered JSX element. | ||
*/ | ||
export declare function jsxToString(this: any, jsxElement: JSX.Element): Promise<string>; |
{ | ||
"name": "jsx-async-runtime", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "An asynchronous JSX runtime without dependencies to be used as html template engine.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
32887
757