jsx-async-runtime
Advanced tools
Comparing version 0.2.2 to 0.3.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=>u[e]||e):t}var u={"&":"&","<":"<",">":">",'"':""","'":"'"},h=new RegExp(`[${Object.keys(u).join("")}]`,"g");function g(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:m(t)}}function d(t){let e=[];for(let[r,n]of Object.entries(t.props))r!=="children"&&e.push([r,n]);return e}function m(t){return t.props.children?Array.isArray(t.props.children)?t.props.children:[t.props.children]:[]}var y=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=g(e.attributes),n=r.length?" ":"";if(e.children.length===0&&y.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)}}async function x(t){return await o(await t)}export{l as createElement,b as escapeEntities,x as renderToString}; | ||
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}; |
export * from "./jsx/jsx.types"; | ||
export { createElement } from "./jsx/jsx-runtime"; | ||
export { escapeEntities } from "./render/escape-entities"; | ||
export { renderToString } from "./render/render-to-string"; | ||
export { jsxToString, | ||
/** @deprecated */ | ||
jsxToString as renderToString, } from "./render/jsx-to-string"; |
{ | ||
"name": "jsx-async-runtime", | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"description": "An asynchronous JSX runtime without dependencies to be used as html template engine.", | ||
@@ -49,6 +49,6 @@ "keywords": [ | ||
"devDependencies": { | ||
"esbuild": "0.22.0", | ||
"esbuild": "0.23.0", | ||
"nodemon": "3.1.4", | ||
"typescript": "5.5.2" | ||
"typescript": "5.5.3" | ||
} | ||
} |
@@ -37,3 +37,3 @@ # jsx-async-runtime | ||
```jsx | ||
import { escapeEntities, renderToString } from "jsx-async-runtime"; | ||
import { escapeEntities, jsxToString } from "jsx-async-runtime"; | ||
@@ -98,3 +98,3 @@ export default function App() { | ||
console.log(await renderToString(<App />)); | ||
console.log(await jsxToString(<App />)); | ||
``` |
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
744
32357
19