Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsx-async-runtime

Package Overview
Dependencies
Maintainers
0
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsx-async-runtime - npm Package Compare versions

Comparing version 0.4.1 to 0.4.2

195

dist/esm/index.js

@@ -1,1 +0,194 @@

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 h(t){return typeof t=="string"?t.replace(b,e=>u[e]||e):t}var u={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},b=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('"',"&quot;")}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.call(this,n);s.length>0&&r.push(s)}return r.join("")}else{let r=g(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}>`}}if(typeof t.tag=="function"){let e=await t.tag.call(this,t.props);return await o.call(this,e)}return""}export{l as createElement,h as escapeEntities,o as jsxToString,o as renderToString};
// src/jsx/jsx-runtime.ts
function createElement(tag, props, ...children) {
props ??= {};
const finalChildren = [];
for (const child of children) {
mapChildren(child, finalChildren);
}
if (props?.children) {
mapChildren(props.children, finalChildren);
}
props.children = finalChildren;
Object.freeze(finalChildren);
Object.freeze(props);
return {
type: "tag",
//@ts-expect-error
tag,
props
};
}
function mapChildren(children, accumulator) {
switch (typeof children) {
case "string":
accumulator.push({ type: "textNode", text: children });
break;
case "number":
accumulator.push({ type: "textNode", text: children.toString() });
break;
case "object":
if (Array.isArray(children)) {
for (const child of children) {
mapChildren(child, accumulator);
}
} else if (children != null) {
accumulator.push(children);
}
break;
}
}
// src/render/escape-entities.ts
function escapeEntities(input) {
return typeof input === "string" ? input.replace(ESCAPE, (match) => ENTITIES[match] || match) : input;
}
var ENTITIES = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
"'": "&#39;"
};
var ESCAPE = new RegExp(`[${Object.keys(ENTITIES).join("")}]`, "g");
// src/render/attributes-to-string.ts
function attributesToString(attributes) {
const result = [];
for (const attribute of attributes) {
const str = attributeToString(attribute);
if (str.length > 0) {
result.push(str);
}
}
return result.join(" ");
}
function attributeToString([key, value]) {
if (value === true) {
return key;
}
if (value === false || value === null || value === void 0) {
return "";
}
if (typeof value === "object") {
switch (key) {
case "style":
const styles = Object.entries(value).map(([k, v]) => `${k}: ${v}`);
return `style="${escapeQuotes(styles.join("; "))}"`;
case "class":
const classes = Object.entries(value).filter(([k, v]) => v).map(([k, v]) => k);
return classes.length > 0 ? `class="${escapeQuotes(classes.join(" "))}"` : "";
default:
return `${key}="${escapeQuotes(JSON.stringify(value))}"`;
}
}
return `${key}="${escapeQuotes(value.toString())}"`;
}
function escapeQuotes(str) {
return str.replaceAll('"', "&quot;");
}
// src/render/create-element.ts
function createElement2(element) {
return {
tag: element.tag.toString(),
attributes: createAttributes(element),
children: createChildren(element)
};
}
function createAttributes(element) {
const attributes = [];
for (const [key, value] of Object.entries(element.props)) {
if (key !== "children") {
attributes.push([key, value]);
}
}
return attributes;
}
function createChildren(element) {
if (!element.props.children) {
return [];
}
if (Array.isArray(element.props.children)) {
return element.props.children;
}
return [element.props.children];
}
// src/render/jsx-to-string.ts
var VOID_TAGS = /* @__PURE__ */ new Set([
"area",
"base",
"br",
"col",
"embed",
"hr",
"img",
"input",
"link",
"meta",
"param",
"source",
"track",
"wbr"
]);
async function jsxToString(jsxElement) {
if (jsxElement === null) {
return "";
}
switch (typeof jsxElement) {
case "string":
return jsxElement;
case "bigint":
case "number":
return String(jsxElement);
case "boolean":
case "function":
case "symbol":
case "undefined":
return "";
}
assertSync(jsxElement);
if (jsxElement.type === "textNode") {
return jsxElement.text;
}
if (typeof jsxElement.tag === "string") {
const element = createElement2(jsxElement);
if (element.tag === "") {
const result = [];
for (const child of element.children) {
const str = await jsxToString.call(this, child);
if (str.length > 0) {
result.push(str);
}
}
return result.join("");
} else {
const attributes = attributesToString(element.attributes);
const separator = attributes.length ? " " : "";
if (element.children.length === 0 && VOID_TAGS.has(element.tag)) {
return `<${element.tag}${separator}${attributes}>`;
}
const children = [];
for (const child of element.children) {
const str = await jsxToString.call(this, child);
if (str.length > 0) {
children.push(str);
}
}
return `<${element.tag}${separator}${attributes}>${children.join("")}</${element.tag}>`;
}
}
if (typeof jsxElement.tag === "function") {
const jsxElementTag = await jsxElement.tag.call(this, jsxElement.props);
return await jsxToString.call(this, jsxElementTag);
}
return "";
}
function assertSync(e) {
}
export {
createElement,
escapeEntities,
jsxToString,
jsxToString as renderToString
};

@@ -1,1 +0,56 @@

function x(t,e,...s){e??={};let n=[];for(let a of s)o(a,n);return e?.children&&o(e.children,n),e.children=n,Object.freeze(n),Object.freeze(e),{type:"tag",tag:t,props:e}}function o(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 s of t)o(s,e);else t!=null&&e.push(t);break}}var r=x,f=r,c=r,m=r,i="",j=i;export{i as Fragment,j as _Fragment,c as _jsx,m as _jsxs,x as createElement,r as jsx,r as jsxDEV,f as jsxs,f as jsxsDEV};
// src/jsx/jsx-runtime.ts
function createElement(tag, props, ...children) {
props ??= {};
const finalChildren = [];
for (const child of children) {
mapChildren(child, finalChildren);
}
if (props?.children) {
mapChildren(props.children, finalChildren);
}
props.children = finalChildren;
Object.freeze(finalChildren);
Object.freeze(props);
return {
type: "tag",
//@ts-expect-error
tag,
props
};
}
function mapChildren(children, accumulator) {
switch (typeof children) {
case "string":
accumulator.push({ type: "textNode", text: children });
break;
case "number":
accumulator.push({ type: "textNode", text: children.toString() });
break;
case "object":
if (Array.isArray(children)) {
for (const child of children) {
mapChildren(child, accumulator);
}
} else if (children != null) {
accumulator.push(children);
}
break;
}
}
var jsx = createElement;
var jsxs = jsx;
var _jsx = jsx;
var _jsxs = jsx;
var Fragment = "";
var _Fragment = Fragment;
export {
Fragment,
_Fragment,
_jsx,
_jsxs,
createElement,
jsx,
jsx as jsxDEV,
jsxs,
jsxs as jsxsDEV
};

@@ -1,1 +0,54 @@

function x(t,e,...r){e??={};let n=[];for(let i of r)o(i,n);return e?.children&&o(e.children,n),e.children=n,Object.freeze(n),Object.freeze(e),{type:"tag",tag:t,props:e}}function o(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)o(r,e);else t!=null&&e.push(t);break}}var s=x,c=s,a=s,l=s,f="",p=f;export{f as Fragment,p as _Fragment,a as _jsx,l as _jsxs,x as createElement,s as jsx,c as jsxs};
// src/jsx/jsx-runtime.ts
function createElement(tag, props, ...children) {
props ??= {};
const finalChildren = [];
for (const child of children) {
mapChildren(child, finalChildren);
}
if (props?.children) {
mapChildren(props.children, finalChildren);
}
props.children = finalChildren;
Object.freeze(finalChildren);
Object.freeze(props);
return {
type: "tag",
//@ts-expect-error
tag,
props
};
}
function mapChildren(children, accumulator) {
switch (typeof children) {
case "string":
accumulator.push({ type: "textNode", text: children });
break;
case "number":
accumulator.push({ type: "textNode", text: children.toString() });
break;
case "object":
if (Array.isArray(children)) {
for (const child of children) {
mapChildren(child, accumulator);
}
} else if (children != null) {
accumulator.push(children);
}
break;
}
}
var jsx = createElement;
var jsxs = jsx;
var _jsx = jsx;
var _jsxs = jsx;
var Fragment = "";
var _Fragment = Fragment;
export {
Fragment,
_Fragment,
_jsx,
_jsxs,
createElement,
jsx,
jsxs
};

4

package.json
{
"name": "jsx-async-runtime",
"version": "0.4.1",
"version": "0.4.2",
"description": "An asynchronous JSX runtime without dependencies to be used as html template engine.",

@@ -45,3 +45,3 @@ "keywords": [

"build": "rm -r dist ; npm run build:types && npm run build:esm",
"build:esm": "esbuild --minify --platform=neutral --format=esm --outdir=./dist/esm --bundle ./src/*.ts",
"build:esm": "esbuild --platform=neutral --format=esm --outdir=./dist/esm --bundle ./src/*.ts",
"build:types": "tsc --emitDeclarationOnly --outDir ./dist/types"

@@ -48,0 +48,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc