Socket
Socket
Sign inDemoInstall

jsxte

Package Overview
Dependencies
0
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.2.1 to 2.3.0

dist/cjs/error-boundary/error-boundary.cjs

42

dist/legacy/context-map/context-map.js

@@ -5,17 +5,3 @@ "use strict";

var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __export = (target, all) => {

@@ -53,2 +39,7 @@ for (var name in all)

}
/**
* Retrieve the context data for the specified context. If the
* context has never been set by any of this component
* ancestors an error will be thrown.
*/
get(ref) {

@@ -63,2 +54,10 @@ const value = this.map.get(ref.id);

}
/**
* Partially update the state of the context data. Works only
* for objects and can only be used if some context data is
* already set beforehand.
*
* Updates to the context made with this method are only
* visible to this component and it's descendants.
*/
update(ref, updateData) {

@@ -76,3 +75,3 @@ const data = this.get(ref);

} else {
return void this.map.set(ref.id, __spreadValues(__spreadValues({}, data), updateData));
return void this.map.set(ref.id, { ...data, ...updateData });
}

@@ -85,8 +84,21 @@ } else {

}
/**
* Sets the context data for the specified context.
*
* Changes to the context made with this method are only
* visible to this component and it's descendants.
*/
set(ref, data) {
this.map.set(ref.id, data);
}
/** Check if the context data for the specified context is set. */
has(ref) {
return this.map.has(ref.id);
}
/**
* Replaces this context entries with the entries of the
* context provided.
*
* @internal
*/
replace(context) {

@@ -93,0 +105,0 @@ this.map = context.map;

@@ -19,22 +19,2 @@ "use strict";

var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};

@@ -49,7 +29,7 @@ // src/express/index.ts

var import_jsx_runtime = require("../jsx/jsx-runtime.js");
var __express = (filePath, options, callback) => __async(void 0, null, function* () {
options != null ? options : options = {};
var __express = async (filePath, options, callback) => {
options ?? (options = {});
try {
const Component = require(filePath).default;
const html = yield (0, import_render_to_html.renderToHtmlAsync)((0, import_jsx_runtime.createElement)(Component, options));
const html = await (0, import_render_to_html.renderToHtmlAsync)((0, import_jsx_runtime.createElement)(Component, options));
return callback(null, html);

@@ -59,3 +39,3 @@ } catch (e) {

}
});
};
var expressExtend = (app) => {

@@ -62,0 +42,0 @@ app.engine("js", __express);

@@ -19,22 +19,2 @@ "use strict";

var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};

@@ -49,2 +29,3 @@ // src/html-parser/jsx-elem-to-html.ts

var import_context_map = require("../context-map/context-map.js");
var import_error_boundary = require("../error-boundary/error-boundary.js");
var import_pad = require("../utilities/pad.js");

@@ -56,3 +37,3 @@ var import_attribute_to_html_tag_string = require("./attribute-to-html-tag-string.js");

var jsxElemToHtmlSync = (element, contextMap = import_context_map.ContextMap.create(), options) => {
const { attributeMap = {}, currentIndent = 0, indent = 2 } = options != null ? options : {};
const { attributeMap = {}, currentIndent = 0, indent = 2 } = options ?? {};
contextMap = import_context_map.ContextMap.clone(contextMap);

@@ -66,2 +47,33 @@ if (!isSyncElem(element))

if (typeof element.tag !== "string") {
if (import_error_boundary.ErrorBoundary._isErrorBoundary(element.tag)) {
const boundary = new element.tag(element.props);
try {
const subElem2 = boundary.render(
element.props,
contextMap
);
if (subElem2 instanceof Promise) {
throw new Error(
`Encountered an async Component: [${element.tag.name}.render] Asynchronous Component's cannot be parsed by rendertoHTML. If you wante to use asynchronous components use renderToHtmlAsync instead.`
);
}
return jsxElemToHtmlSync(subElem2, contextMap, {
indent,
currentIndent,
attributeMap
});
} catch (e) {
const fallbackElem = boundary.onError(e, element.props, contextMap);
if (fallbackElem instanceof Promise) {
throw new Error(
`Encountered an async Component: [${element.tag.name}.onError] Asynchronous Component's cannot be parsed by rendertoHTML. If you wante to use asynchronous components use renderToHtmlAsync instead.`
);
}
return jsxElemToHtmlSync(fallbackElem, contextMap, {
indent,
currentIndent,
attributeMap
});
}
}
const subElem = element.tag(

@@ -120,4 +132,4 @@ element.props,

};
var jsxElemToHtmlAsync = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (element, contextMap = import_context_map.ContextMap.create(), options) {
const { attributeMap = {}, currentIndent = 0, indent = 2 } = options != null ? options : {};
var jsxElemToHtmlAsync = async (element, contextMap = import_context_map.ContextMap.create(), options) => {
const { attributeMap = {}, currentIndent = 0, indent = 2 } = options ?? {};
contextMap = import_context_map.ContextMap.clone(contextMap);

@@ -131,7 +143,32 @@ if (!isSyncElem(element))

if (typeof element.tag !== "string") {
const subElem = yield element.tag(
if (import_error_boundary.ErrorBoundary._isErrorBoundary(element.tag)) {
const boundary = new element.tag(element.props);
try {
const subElem2 = await boundary.render(
element.props,
contextMap
);
return await jsxElemToHtmlAsync(subElem2, contextMap, {
indent,
currentIndent,
attributeMap
});
} catch (e) {
const fallbackElem = await boundary.onError(
e,
element.props,
contextMap
);
return await jsxElemToHtmlAsync(fallbackElem, contextMap, {
indent,
currentIndent,
attributeMap
});
}
}
const subElem = await element.tag(
element.props,
contextMap
);
return yield jsxElemToHtmlAsync(subElem, contextMap, {
return await jsxElemToHtmlAsync(subElem, contextMap, {
indent,

@@ -146,3 +183,3 @@ currentIndent,

for (const child of htmlStruct.children) {
const renderedChild = yield jsxElemToHtmlAsync(child, contextMap, {
const renderedChild = await jsxElemToHtmlAsync(child, contextMap, {
indent,

@@ -166,3 +203,3 @@ currentIndent: currentIndent + indent,

for (const child of htmlStruct.children) {
const renderedChild = yield jsxElemToHtmlAsync(child, contextMap, {
const renderedChild = await jsxElemToHtmlAsync(child, contextMap, {
indent: inlineTag ? 0 : indent,

@@ -181,2 +218,2 @@ currentIndent: inlineTag ? 0 : currentIndent + indent,

}
});
};

@@ -19,22 +19,2 @@ "use strict";

var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};

@@ -52,4 +32,4 @@ // src/html-parser/render-to-html.ts

};
var renderToHtmlAsync = (component, options) => __async(void 0, null, function* () {
return yield (0, import_jsx_elem_to_html.jsxElemToHtmlAsync)(yield component, void 0, options);
});
var renderToHtmlAsync = async (component, options) => {
return await (0, import_jsx_elem_to_html.jsxElemToHtmlAsync)(await component, void 0, options);
};

@@ -24,2 +24,3 @@ "use strict";

__export(src_exports, {
ErrorBoundary: () => import_error_boundary.ErrorBoundary,
defineContext: () => import_context_map.defineContext,

@@ -36,2 +37,3 @@ memo: () => import_memo.memo,

__reExport(src_exports, require("./jsx/prop-types/index.js"), module.exports);
var import_error_boundary = require("./error-boundary/error-boundary.js");
var import_context_map = require("./context-map/context-map.js");

@@ -38,0 +40,0 @@ var import_render_to_html = require("./html-parser/render-to-html.js");

@@ -33,3 +33,3 @@ "use strict";

var createElement = (tag, props, ...children) => {
props != null ? props : props = {};
props ?? (props = {});
if (children) {

@@ -41,3 +41,3 @@ props.children = [

}
if (props == null ? void 0 : props.children) {
if (props?.children) {
if (typeof props.children === "string") {

@@ -73,2 +73,3 @@ props.children = { type: "textNode", text: props.children };

type: "tag",
// @ts-expect-error
tag,

@@ -75,0 +76,0 @@ props

@@ -27,2 +27,3 @@ "use strict";

var import_context_map = require("../context-map/context-map.js");
var import_error_boundary = require("../error-boundary/error-boundary.js");
var import_map_attribute_name = require("./map-attribute-name.js");

@@ -48,2 +49,29 @@ var import_resolve_element = require("./resolve-element.js");

if (typeof element.tag !== "string") {
if (import_error_boundary.ErrorBoundary._isErrorBoundary(element.tag)) {
const boundary = new element.tag(element.props);
try {
const subElem2 = boundary.render(
element.props,
contextMap
);
if (subElem2 instanceof Promise) {
throw new Error(
`Encountered an async Component: [${element.tag.name}.render] Asynchronous Component's cannot be parsed by rendertoHTML. If you wante to use asynchronous components use renderToHtmlAsync instead.`
);
}
return jsxElemToTagFuncArgsSync(subElem2, attributeMap, contextMap);
} catch (e) {
const fallbackElem = boundary.onError(
e,
element.props,
contextMap
);
if (fallbackElem instanceof Promise) {
throw new Error(
`Encountered an async Component: [${element.tag.name}.onError] Asynchronous Component's cannot be parsed by rendertoHTML. If you wante to use asynchronous components use renderToHtmlAsync instead.`
);
}
return jsxElemToTagFuncArgsSync(fallbackElem, attributeMap, contextMap);
}
}
const subElem = element.tag(

@@ -50,0 +78,0 @@ element.props,

@@ -28,6 +28,5 @@ "use strict";

var renderToStringTemplateTag = (tag, Component, options) => {
var _a;
const [templateStringArray, params] = (0, import_jsx_elem_to_strings.jsxElemToTagFuncArgsSync)(
Component,
(_a = options == null ? void 0 : options.attributeMap) != null ? _a : {}
options?.attributeMap ?? {}
);

@@ -34,0 +33,0 @@ Object.assign(templateStringArray, { raw: [...templateStringArray] });

@@ -5,17 +5,3 @@ "use strict";

var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __objRest = (source, exclude) => {
var target = {};
for (var prop in source)
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
target[prop] = source[prop];
if (source != null && __getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(source)) {
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
target[prop] = source[prop];
}
return target;
};
var __export = (target, all) => {

@@ -49,7 +35,7 @@ for (var name in all)

var resolveElement = (element) => {
const _a = element.props, { children } = _a, attributes = __objRest(_a, ["children"]);
const { children, ...attributes } = element.props;
return {
attributes,
children: asArray(children != null ? children : []).flat()
children: asArray(children ?? []).flat()
};
};

@@ -27,7 +27,7 @@ "use strict";

var CacheEntry = class {
constructor(props, value, maxAge = 15 * 60 * 1e3) {
constructor(props, value, maxAge) {
this.value = value;
this.maxAge = maxAge;
this.createdAt = Date.now();
this.props = Array.from(Object.entries(props));
this.props = new Map(Object.entries(props));
}

@@ -38,6 +38,7 @@ isExpired(now) {

compareProps(propEntries) {
if (propEntries.length !== this.props.length)
if (propEntries.length !== this.props.size)
return false;
for (const [key, value] of propEntries) {
const cachedPropValue = this.props.find(([k]) => k === key);
for (let i = 0; i < propEntries.length; i++) {
const [key, value] = propEntries[i];
const cachedPropValue = this.props.get(key);
if (cachedPropValue !== value)

@@ -50,8 +51,17 @@ return false;

var Cache = class {
constructor(maxAge) {
constructor(maxAge = 15 * 60 * 1e3, maxEntries = 10) {
this.maxAge = maxAge;
this.maxEntries = maxEntries;
this.lastInvalidate = Date.now();
this.invalidationInterval = 5 * 60 * 1e3;
this.entries = [];
if (maxEntries < 1) {
throw new Error("Cache maxEntries must be greater than 0");
}
}
enforceEntryLimit() {
while (this.entries.length > this.maxEntries) {
this.entries.shift();
}
}
invalidateExpired() {

@@ -64,5 +74,3 @@ const now = Date.now();

this.lastInvalidate = Date.now();
setTimeout(() => {
this.invalidateExpired();
}, 0);
setTimeout(() => this.invalidateExpired(), 0);
}

@@ -79,3 +87,4 @@ const propsEntries = Array.from(Object.entries(props));

this.entries.push(new CacheEntry(props, value, this.maxAge));
setTimeout(() => this.enforceEntryLimit(), 0);
}
};

@@ -5,29 +5,3 @@ "use strict";

var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __objRest = (source, exclude) => {
var target = {};
for (var prop in source)
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
target[prop] = source[prop];
if (source != null && __getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(source)) {
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
target[prop] = source[prop];
}
return target;
};
var __export = (target, all) => {

@@ -46,22 +20,2 @@ for (var name in all)

var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};

@@ -82,15 +36,19 @@ // src/utilities/memo.ts

var memo = (Component, options) => {
const { maxCacheAge, renderAsynchronously = false } = options != null ? options : {};
const cache = new import_cache.Cache(maxCacheAge);
const {
maxCacheAge,
maxCacheEntries,
renderAsynchronously = false
} = options ?? {};
const cache = new import_cache.Cache(maxCacheAge, maxCacheEntries);
if (renderAsynchronously) {
const MemoComponentAsync = (props, context) => __async(void 0, null, function* () {
const _a = props, { children } = _a, propsNoChildren = __objRest(_a, ["children"]);
const MemoComponentAsync = async (props, context) => {
const { children, ...propsNoChildren } = props;
const cachedResult = cache.get(propsNoChildren);
if (cachedResult)
return cachedResult;
const result = yield (0, import_render_to_html.renderToHtmlAsync)(
const result = await (0, import_render_to_html.renderToHtmlAsync)(
(0, import_jsx_runtime.jsx)(
ReplaceMap,
{ context },
(0, import_jsx_runtime.jsx)(Component, __spreadValues({}, propsNoChildren), children)
(0, import_jsx_runtime.jsx)(Component, { ...propsNoChildren }, children)
)

@@ -104,7 +62,7 @@ );

return textNode;
});
};
return MemoComponentAsync;
}
const MemoComponent = (props, context) => {
const _a = props, { children } = _a, propsNoChildren = __objRest(_a, ["children"]);
const { children, ...propsNoChildren } = props;
const cachedResult = cache.get(propsNoChildren);

@@ -117,3 +75,3 @@ if (cachedResult)

{ context },
(0, import_jsx_runtime.jsx)(Component, __spreadValues({}, propsNoChildren), children)
(0, import_jsx_runtime.jsx)(Component, { ...propsNoChildren }, children)
)

@@ -120,0 +78,0 @@ );

@@ -1,2 +0,2 @@

declare type ExpressApp = {
type ExpressApp = {
engine(ext: string, fn: (path: string, options: object, callback: (e: any, rendered?: string) => void) => void): any;

@@ -3,0 +3,0 @@ set(setting: string, val: any): any;

import { ContextMap } from "../context-map/context-map";
declare type InternalOptions = {
type InternalOptions = {
indent?: number;

@@ -4,0 +4,0 @@ currentIndent?: number;

@@ -1,2 +0,2 @@

declare type HtmlRenderOptions = {
type HtmlRenderOptions = {
indent?: number;

@@ -3,0 +3,0 @@ attributeMap?: Record<string, string>;

@@ -1,3 +0,3 @@

export declare type RendererHTMLAttributes = [string, string | undefined][];
export declare type HTMLElementStruct = {
export type RendererHTMLAttributes = [string, string | undefined][];
export type HTMLElementStruct = {
tag: string;

@@ -7,4 +7,4 @@ children: JSX.Element[];

};
export declare type Rewrap<T extends object> = T extends infer OBJ ? {
export type Rewrap<T extends object> = T extends infer OBJ ? {
[K in keyof OBJ]: OBJ[K] extends infer O ? O : never;
} : never;

@@ -5,2 +5,3 @@ import "./utilities/array-flat-polyfill";

export * from "./jsx/prop-types/index";
export { ErrorBoundary } from "./error-boundary/error-boundary";
export { defineContext } from "./context-map/context-map";

@@ -7,0 +8,0 @@ export { renderToHtml, renderToHtmlAsync } from "./html-parser/render-to-html";

import type { ContextMap } from "../context-map/context-map";
import type { ErrorBoundaryElement } from "../error-boundary/error-boundary";
import type { Rewrap } from "../html-parser/types";
export declare type AttributeBool = true | false | "true" | "false";
export declare type HTMLProps<T extends object = never> = Rewrap<ExtendBaseProps<[
export type AttributeBool = true | false | "true" | "false";
export type HTMLProps<T extends object = never> = Rewrap<ExtendBaseProps<[
T
] extends [never] ? JSXTE.BaseHTMLTagProps : Partial<T> & JSXTE.BaseHTMLTagProps>>;
declare type ExtendBaseProps<P> = {
type ExtendBaseProps<P> = {
[K in keyof P]: JSXTE.AttributeAcceptedTypes extends {

@@ -18,3 +19,3 @@ [E in K]: infer T;

type: "tag";
tag: string | ((props: ElementProps, contextMap: ContextMap) => Element) | ((props: ElementProps, contextMap: ContextMap) => Promise<Element>);
tag: string | ((props: ElementProps, contextMap: ContextMap) => Element) | ((props: ElementProps, contextMap: ContextMap) => Promise<Element>) | ErrorBoundaryElement;
props: ElementProps;

@@ -21,0 +22,0 @@ };

import type { ContextMap } from "../context-map/context-map";
declare type CreateElementProps = {
type CreateElementProps = {
[k: string]: any;

@@ -4,0 +4,0 @@ children?: JSXTE.ElementChildren;

@@ -51,3 +51,4 @@ import type { HTMLProps } from "./base-html-tag-props";

type AsyncElement = Promise<JSXTE.TagElement | JSXTE.TextNodeElement>;
type Element = JSXTE.TagElement | JSXTE.TextNodeElement | AsyncElement;
type SyncElement = JSXTE.TagElement | JSXTE.TextNodeElement;
type Element = SyncElement | AsyncElement;
type LibraryManagedAttributes<T, PropsWithChildren> = PropsWithChildren;

@@ -54,0 +55,0 @@ interface IntrinsicElements {

import type { AttributeBool } from "../base-html-tag-props";
export declare type InputType = "button" | "checkbox" | "color" | "date" | "datetime-local" | "datetime-local" | "file" | "hidden" | "image" | "month" | "number" | "password" | "radio" | "range" | "reset" | "search" | "submit" | "tel" | "text" | "time" | "url" | "week";
export type InputType = "button" | "checkbox" | "color" | "date" | "datetime-local" | "datetime-local" | "file" | "hidden" | "image" | "month" | "number" | "password" | "radio" | "range" | "reset" | "search" | "submit" | "tel" | "text" | "time" | "url" | "week";
export interface InputTagProps {

@@ -4,0 +4,0 @@ accept?: string;

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

export declare type Crossorigin = "anonymous" | "use-credentials";
export type Crossorigin = "anonymous" | "use-credentials";

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

export declare type RefererPolicy = "no-referrer" | "no-referrer-when-downgrade" | "origin" | "origin-when-cross-origin" | "same-origin" | "strict-origin-when-cross-origin" | "unsafe-url";
export type RefererPolicy = "no-referrer" | "no-referrer-when-downgrade" | "origin" | "origin-when-cross-origin" | "same-origin" | "strict-origin-when-cross-origin" | "unsafe-url";

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

export declare type Target = "_blank" | "_self" | "_parent" | "_top";
export type Target = "_blank" | "_self" | "_parent" | "_top";
import { ContextMap } from "../context-map/context-map";
declare type TagFunctionArgs = [string[], any[]];
type TagFunctionArgs = [string[], any[]];
export declare const jsxElemToTagFuncArgsSync: (element: JSX.Element, attributeMap: Record<string, string>, contextMap?: ContextMap) => TagFunctionArgs;
export {};
import type { StringTemplateTag } from "./string-template-tag-type";
export declare type StringTemplateParserOptions = {
export type StringTemplateParserOptions = {
/**

@@ -4,0 +4,0 @@ * Mappings for html attribute names. Attributes defined in

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

export declare type StringTemplateTag<R> = (template: TemplateStringsArray, ...arg: any[]) => R;
export type StringTemplateTag<R> = (template: TemplateStringsArray, ...arg: any[]) => R;
export declare class Cache<T> {
private maxAge?;
private readonly maxAge;
private readonly maxEntries;
private lastInvalidate;
private invalidationInterval;
private entries;
constructor(maxAge?: number | undefined);
invalidateExpired(): void;
constructor(maxAge?: number, maxEntries?: number);
private enforceEntryLimit;
private invalidateExpired;
get(props: object): T | undefined;
set(props: object, value: T): void;
}

@@ -25,2 +25,4 @@ import type { ContextMap } from "../context-map/context-map";

renderAsynchronously?: boolean;
/** Maximum number of cached entries to keep in memory. Default: 10. */
maxCacheEntries?: number;
}) => ((props: P, context: ContextMap) => Promise<JSXTE.TextNodeElement>) | ((props: P, context: ContextMap) => JSXTE.TextNodeElement);
{
"devDependencies": {
"@ncpa0cpl/nodepack": "^2.0.2",
"@types/jest": "^27.5.1",
"@typescript-eslint/eslint-plugin": "^5.23.0",
"@typescript-eslint/parser": "^5.23.0",
"esbuild": "^0.14.51",
"esbuild": "^0.17.4",
"eslint": "^8.15.0",

@@ -13,10 +14,10 @@ "eslint-config-prettier": "^8.5.0",

"jest": "^28.1.0",
"node-os-walk": "^1.0.0",
"node-os-walk": "^1.0.2",
"prettier": "^2.6.2",
"prettier-plugin-jsdoc": "^0.3.38",
"prettier-plugin-jsdoc": "^0.4.2",
"ts-jest": "^28.0.2",
"typescript": "^4.7.4"
"typescript": "^4.9.4"
},
"name": "jsxte",
"version": "2.2.1",
"version": "2.3.0",
"main": "./dist/legacy/index.js",

@@ -37,5 +38,3 @@ "types": "./dist/types/index.d.ts",

"scripts": {
"build": "rm -rf ./dist && yarn build:esm && yarn build:cjs && yarn build:types",
"build:esm": "node ./scripts/build.mjs esmodule",
"build:cjs": "node ./scripts/build.mjs commonjs",
"build": "node ./scripts/build.mjs",
"build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly --outDir ./dist/types",

@@ -63,3 +62,4 @@ "test:lint": "eslint .",

"email": "szymonb21@gmail.com"
}
},
"packageManager": "yarn@1.22.19"
}
# JSX Template Engine
![NPM](https://img.shields.io/npm/l/jsxte?style=for-the-badge) [![npm](https://img.shields.io/npm/v/jsxte?style=for-the-badge)](https://www.npmjs.com/package/jsxte) ![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/npm/jsxte?style=for-the-badge) ![GitHub last commit](https://img.shields.io/github/last-commit/ncpa0cpl/jsxte?style=for-the-badge)
A JSX based html templating engine for browsers or Node environments.
1. [Getting started](#getting-started)
1. [Installation](#installation)
2. [Building](#building)
2. [Asynchronous Components](#asynchronous-components)
3. [Context](#context)
1. [Example](#example)
2. [Provider/Consumer Pattern](#providerconsumer-pattern)
4. [Error Boundaries](#error-boundaries)
1. [Example](#example-1)
5. [Extending the typings](#extending-the-typings)
1. [Adding custom web component tags](#adding-custom-web-component-tags)
2. [Adding a global html attribute](#adding-a-global-html-attribute)
6. [Express JS View Engine](#express-js-view-engine)
7. [Rendering to a string tag template](#rendering-to-a-string-tag-template)
1. [Example](#example-2)
## Getting started
### Installation
```bash
npm i jsxte
```
or
```bash
yarn add jsxte
```
### Building
To use the `jsxte` you will have to set up your transpiler to use this package for transforming the JSX syntax, if you use typescript for transpiling all you have to do is set these options in the tsconfig:

@@ -188,2 +220,45 @@

## Error Boundaries
Error boundaries are components that catch errors thrown by their children and allow you to display a fallback UI instead of having the rendering outright fail.
Error boundaries work with both synchronous and asynchronous components. But the `onError` handler should never return an asynchronous component.
### Example
```tsx
import { ErrorBoundary, renderToHtml } from "jsxte";
class Boundary extends ErrorBoundary {
render(props: JSXTE.ElementProps, context: ContextMap) {
return <>{props.children}</>;
}
onError(
error: unknown,
originalProps: JSXTE.ElementProps,
context: ContextMap
) {
return <h1>Something went wrong!</h1>;
}
}
const FailingComponent: JSXTE.Component = () => {
throw new Error("Unexpected failure!");
};
const html = renderToHtml(
<div>
<Boundary>
<FailingComponent />
</Boundary>
</div>
);
// html:
// <div>
// <h1>Something went wrong!</h1>
// </div>
```
## Extending the typings

@@ -190,0 +265,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc