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

express-engine-jsx

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-engine-jsx - npm Package Compare versions

Comparing version 3.4.3 to 3.5.0

34

index.d.ts

@@ -0,6 +1,12 @@

import {Stream} from "node:stream";
import {ScriptOptions} from "node:vm";
import {ParserOptions} from '@babel/parser/typings/babel-parser';
import {BabylonOptions} from 'babylon';
import {createElement, Context} from 'react';
declare function engine(path: string, params: object, cb: HtmlCallback): void;
declare function engine(path: string, cb: HtmlCallback): void;
declare function engine(path: string, params?: object): string;
declare function engine(path: string, params?: object): HtmlResult;
type HtmlCallback = (err: null|Error, html: string) => void;
type HtmlCallback = (err: null|Error, html: HtmlResult) => void;

@@ -11,5 +17,6 @@ declare namespace engine {

doctype?: string,
replace?: (html: string) => string,
renderer?: (node: ReturnType<typeof createElement>) => HtmlResult,
replace?: (html: HtmlResult, params: object) => HtmlResult,
templatePath?: string,
parserOptions?: import('@babel/parser/typings/babel-parser').ParserOptions,
parserOptions?: ParserOptions,
sourceMap?: boolean,

@@ -23,6 +30,6 @@ addOnChange?: boolean,

addOnChange?: boolean,
parserOptions?: import('@babel/parser/typings/babel-parser').ParserOptions,
template?: false | string | Buffer | (({BODY}) => any),
parserOptions?: ParserOptions,
template?: false | JsxCode | (({BODY}) => any),
templatePath?: string,
templateOptions?: import('babylon').BabylonOptions,
templateOptions?: BabylonOptions,
}

@@ -33,3 +40,3 @@

context?: object,
scriptOptions?: import('vm').ScriptOptions,
scriptOptions?: ScriptOptions,
}

@@ -41,9 +48,12 @@

export function convert(code: string|Buffer, options?: ConvertOptions): string|{code: string, map: null|object};
export function convert(code: JsxCode, options?: ConvertOptions): string|{code: string, map: null|object};
export function run(code: string|Buffer, options?: RunOptions): any;
export function run(code: JsxCode, options?: RunOptions): any;
export const Context: import('react').Context<{ locales: object, settings: object }>;
export const Context: Context<{locales: object, settings: object}>;
}
export = engine;
export = engine;
type JsxCode = string | Buffer;
type HtmlResult = string | Stream;
const React = require('react');
const ReactDOM = require('react-dom/server');
const Combiner = require('combined-stream');
const options = require('./options');

@@ -24,4 +24,6 @@ const requireJSX = require('./require');

const {renderer, replace, doctype} = options;
try {
var html = ReactDOM.renderToStaticMarkup(
var html = renderer(
React.createElement(Context.Provider, {value: context},

@@ -66,8 +68,16 @@ React.createElement(Component, params)

if (options.replace) {
html = options.replace(html);
if (replace) {
html = replace(html, params);
}
if (options.doctype) {
html = options.doctype + html;
if (doctype) {
if (typeof html === 'string') {
html = doctype + html;
}
else {
const combiner = new Combiner();
combiner.append(doctype);
combiner.append(html);
html = combiner;
}
}

@@ -74,0 +84,0 @@

const {resolve} = require('path');
const {renderToStaticMarkup} = require('react-dom/server');

@@ -21,3 +22,4 @@ const DEV = process.env.NODE_ENV !== 'production';

replace: null,
renderer: renderToStaticMarkup,
templatePath: resolve(__dirname, 'template.jsx'),
};
{
"name": "express-engine-jsx",
"version": "3.4.3",
"version": "3.5.0",
"description": "JSX engine for ExpressJS",

@@ -28,9 +28,10 @@ "main": "index.js",

"dependencies": {
"@babel/core": "^7.17.5",
"@babel/parser": "^7.17.3",
"@babel/plugin-transform-modules-commonjs": "^7.16.8",
"@babel/plugin-transform-react-jsx": "^7.17.3",
"@babel/template": "^7.16.7",
"@babel/types": "^7.17.0",
"@babel/core": "^7.21.3",
"@babel/parser": "^7.21.3",
"@babel/plugin-transform-modules-commonjs": "^7.21.2",
"@babel/plugin-transform-react-jsx": "^7.21.0",
"@babel/template": "^7.20.7",
"@babel/types": "^7.21.3",
"callsites": "^3.1.0",
"combined-stream": "^1.0.8",
"source-map-sync": "^0.8.0-beta.2"

@@ -40,8 +41,8 @@ },

"@types/babylon": "^6.16.6",
"@types/node": "^17.0.20",
"@types/react": "^17.0.39",
"chai": "^4.3.6",
"mocha": "^9.2.1",
"react": ">=16.8",
"react-dom": ">=16.6"
"@types/node": "^17.0.45",
"@types/react": "^17.0.55",
"chai": "^4.3.7",
"mocha": "^9.2.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},

@@ -48,0 +49,0 @@ "peerDependencies": {

@@ -7,2 +7,15 @@ express-engine-jsx

* [How it works](#how-it-works)
* [Usage](#usage)
* [API](#api)
* [engine](#engine)
* [options](#options)
* [require](#require)
* [convert](#convert)
* [run](#run)
* [Context](#context)
* [attr-map](#attr-map)
* [How to integrate to other engine](#how-to-integrate-to-other-engine)
* [Problem with more than one component in template root](#problem-with-more-than-one-component-in-template-root)
Example of `users.jsx` template file

@@ -159,3 +172,3 @@ ```jsx harmony

* `locals` - object with properties which will be local variables in jsx file
* `callback` - optional Node style callback which will receive html string as second argument
* `callback` - optional, Node style callback which will receive result of `options.renderer` as second argument

@@ -182,2 +195,3 @@ If you pass to `engine` only path and locals then it will return html.

* `doctype` - string which will be prepended to output html, default value is `"<!DOCTYPE html>\n"`
* `renderer` - function, default `ReactDOM.renderToStaticMarkup`
* `replace` - function which will take output html (without doctype), and it should return new html

@@ -184,0 +198,0 @@ * `addOnChange` - boolean, default `true`. Will add `onChnage={() => false}` to every `<input>` with `value` or `checked` attribute. Used to omit ReactDOM warning about `value` prop without `onChange` handler.

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