jsx-async-runtime
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -1,5 +0,5 @@ | ||
function $(t,e,...i){e??={};let n=[];for(let s of i)p(s,n);return e?.children&&p(e.children,n),e.children=n,Object.freeze(n),Object.freeze(e),{type:"tag",tag:t,props:e}}function p(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 i of t)p(i,e);else t!=null&&e.push(t);break}}function x(t){return typeof t=="string"?t.replace(J,e=>h[e]||e):t}var h={"&":"&","<":"<",">":">",'"':""","'":"'"},J=new RegExp(`[${Object.keys(h).join("")}]`,"g");function m(t){let e=[];for(let i of t){let n=T(i);n.length>0&&e.push(n)}return e.join(" ")}function T([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 i=Object.entries(e).map(([s,r])=>`${s}: ${r}`);return`style="${u(i.join("; "))}"`;case"class":let n=Object.entries(e).filter(([s,r])=>r).map(([s,r])=>s);return`class="${u(n.join(" "))}"`;default:return`${t}="${u(JSON.stringify(e))}"`}return`${t}="${u(e.toString())}"`}function u(t){return t.replaceAll('"',""")}function S(t){return{tag:t.tag.toString(),attributes:E(t),children:X(t)}}function E(t){let e=[];for(let[i,n]of Object.entries(t.props))i!=="children"&&e.push([i,n]);return e}function X(t){return t.props.children?Array.isArray(t.props.children)?t.props.children:[t.props.children]:[]}var j=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);async function a(t,e){if(t===null||typeof t!="object")return String(t);let{currentIndent:i=0,indent:n=2}=e??{},s=" ".repeat(i);if(t.type==="textNode")return`${s}${t.text}`;if(typeof t.tag=="string"){let r=S(t);if(r.tag===""){let c=[];for(let f of r.children){let o=await a(f,{indent:n,currentIndent:i});o.length>0&&c.push(o)}return c.join(` | ||
`)}else{let c=m(r.attributes),f=c.length?" ":"";if(r.children.length===0&&j.has(r.tag))return`${s}<${r.tag}${f}${c}>`;let o=r.children.length===0||r.children.every(A),l=`${s}<${r.tag}${f}${c}>`,d=`${o?"":s}</${r.tag}>`,g=[];for(let y of r.children){let b=await a(y,{indent:o?0:n,currentIndent:o?0:i+n});b.length>0&&g.push(b)}return o?`${l}${g.join("")}${d}`:`${l} | ||
function $(t,e,...i){e??={};let n=[];for(let s of i)p(s,n);return e?.children&&p(e.children,n),e.children=n,Object.freeze(n),Object.freeze(e),{type:"tag",tag:t,props:e}}function p(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 i of t)p(i,e);else t!=null&&e.push(t);break}}function x(t){return typeof t=="string"?t.replace(J,e=>h[e]||e):t}var h={"&":"&","<":"<",">":">",'"':""","'":"'"},J=new RegExp(`[${Object.keys(h).join("")}]`,"g");function m(t){let e=[];for(let i of t){let n=T(i);n.length>0&&e.push(n)}return e.join(" ")}function T([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 i=Object.entries(e).map(([s,r])=>`${s}: ${r}`);return`style="${f(i.join("; "))}"`;case"class":let n=Object.entries(e).filter(([s,r])=>r).map(([s,r])=>s);return`class="${f(n.join(" "))}"`;default:return`${t}="${f(JSON.stringify(e))}"`}return`${t}="${f(e.toString())}"`}function f(t){return t.replaceAll('"',""")}function S(t){return{tag:t.tag.toString(),attributes:X(t),children:E(t)}}function X(t){let e=[];for(let[i,n]of Object.entries(t.props))i!=="children"&&e.push([i,n]);return e}function E(t){return t.props.children?Array.isArray(t.props.children)?t.props.children:[t.props.children]:[]}var j=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);async function a(t,e){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""}let{currentIndent:i=0,indent:n=2}=e??{},s=" ".repeat(i);if(t.type==="textNode")return`${s}${t.text}`;if(typeof t.tag=="string"){let r=S(t);if(r.tag===""){let c=[];for(let u of r.children){let o=await a(u,{indent:n,currentIndent:i});o.length>0&&c.push(o)}return c.join(` | ||
`)}else{let c=m(r.attributes),u=c.length?" ":"";if(r.children.length===0&&j.has(r.tag))return`${s}<${r.tag}${u}${c}>`;let o=r.children.length===0||r.children.every(A),l=`${s}<${r.tag}${u}${c}>`,d=`${o?"":s}</${r.tag}>`,g=[];for(let y of r.children){let b=await a(y,{indent:o?0:n,currentIndent:o?0:i+n});b.length>0&&g.push(b)}return o?`${l}${g.join("")}${d}`:`${l} | ||
${g.join(` | ||
`)} | ||
${d}`}}else{let r=await t.tag(t.props);return await a(r,{indent:n,currentIndent:i})}}function A(t){return t!=null&&typeof t=="object"&&"type"in t&&t.type==="textNode"}async function w(t,e){return await a(await t,e)}export{$ as createElement,x as escapeEntities,w as renderToString}; |
{ | ||
"name": "jsx-async-runtime", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "An asynchronous JSX runtime without dependencies to be used as server-side template engine.", | ||
@@ -48,6 +48,6 @@ "keywords": [ | ||
"devDependencies": { | ||
"esbuild": "0.19.10", | ||
"prettier": "3.1.1", | ||
"typescript": "5.3.3" | ||
"esbuild": "latest", | ||
"prettier": "latest", | ||
"typescript": "latest" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32756