New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@popeindustries/lit-html-server

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@popeindustries/lit-html-server - npm Package Compare versions

Comparing version 1.5.1 to 1.6.0

124

browser/index.js

@@ -128,2 +128,12 @@ /* global window */

/**
* Determine if "value" is an object
*
* @param { unknown } value
* @returns { boolean }
*/
function isObject(value) {
return Object.prototype.toString.call(value) === '[object Object]';
}
/**
* An empty string Buffer

@@ -168,4 +178,4 @@ */

return string.replace(RE_SCRIPT_STYLE_TAG, '<\\/$1').replace(/<!--/g, '\\x3C!--');
case 'attribute':
case 'text':
case 'attribute':
default:

@@ -212,2 +222,6 @@ return string.replace(RE_HTML, (match) => HTML_ESCAPES[match]);

/**
* @typedef RenderOptions { import('./index.js).RenderOptions }
*/
/**
* Determine if "part" is a NodePart

@@ -267,5 +281,6 @@ *

* @param { any } value
* @param { RenderOptions } [options]
* @returns { any }
*/
getValue(value) {
getValue(value /*, options */) {
return value;

@@ -288,5 +303,6 @@ }

* @param { any } value
* @param { RenderOptions } [options]
* @returns { any }
*/
getValue(value) {
getValue(value /*, options */) {
return resolveNodeValue(value, this);

@@ -323,5 +339,6 @@ }

* @param { Array<unknown> } values
* @param { RenderOptions } [options]
* @returns { Buffer|Promise<Buffer> }
*/
getValue(values) {
getValue(values, options) {
let chunks = [this.prefix];

@@ -333,3 +350,7 @@ let chunkLength = this.prefix.length;

const string = this.strings[i];
let value = resolveAttributeValue(values[i], this);
let value = resolveAttributeValue(
values[i],
this,
options !== undefined ? options.serializePropertyAttributes : false
);

@@ -409,5 +430,6 @@ // Bail if 'nothing'

* @param { Array<unknown> } values
* @param { RenderOptions } [options]
* @returns { Buffer|Promise<Buffer> }
*/
getValue(values) {
getValue(values /*, options */) {
let value = values[0];

@@ -434,9 +456,18 @@

* Retrieve resolved string Buffer from passed "values".
* Properties have no server-side representation,
* so always returns an empty string.
* Returns an empty string unless "options.serializePropertyAttributes=true"
*
* @param { Array<unknown> } values
* @returns { string }
* @param { RenderOptions } [options]
* @returns { Buffer }
*/
getValue(/* values */) {
getValue(values, options) {
if (options !== undefined && options.serializePropertyAttributes) {
const value = super.getValue(values, options);
const prefix = Buffer.from('.');
return value instanceof Promise
? value.then((value) => Buffer.concat([prefix, value]))
: Buffer.concat([prefix, value]);
}
return emptyStringBuffer;

@@ -457,5 +488,6 @@ }

* @param { Array<unknown> } values
* @returns { string }
* @param { RenderOptions } [options]
* @returns { Buffer }
*/
getValue(/* values */) {
getValue(/* values, options */) {
return emptyStringBuffer;

@@ -470,5 +502,6 @@ }

* @param { AttributePart } part
* @returns { unknown }
* @param { boolean } [serialiseObjectsAndArrays]
* @returns { any }
*/
function resolveAttributeValue(value, part) {
function resolveAttributeValue(value, part, serialiseObjectsAndArrays = false) {
if (isDirective(value)) {

@@ -494,4 +527,6 @@ value = resolveDirectiveValue(value, part);

return value;
} else if (serialiseObjectsAndArrays && (isObject(value) || Array.isArray(value))) {
return Buffer.from(escape(JSON.stringify(value), 'attribute'));
} else if (isPromise(value)) {
return value.then((value) => resolveAttributeValue(value, part));
return value.then((value) => resolveAttributeValue(value, part, serialiseObjectsAndArrays));
} else if (isSyncIterator(value)) {

@@ -503,3 +538,3 @@ if (!Array.isArray(value)) {

value.reduce((values, value) => {
value = resolveAttributeValue(value, part);
value = resolveAttributeValue(value, part, serialiseObjectsAndArrays);
// Flatten

@@ -523,3 +558,3 @@ if (Array.isArray(value)) {

* @param { NodePart } part
* @returns { unknown }
* @returns { any }
*/

@@ -598,2 +633,6 @@ function resolveNodeValue(value, part) {

/**
* @typedef RenderOptions { import('./index.js).RenderOptions }
*/
let id = 0;

@@ -646,10 +685,10 @@

*
* @param { boolean } deep - recursively resolve nested TemplateResults
* @param { RenderOptions } [options]
* @returns { unknown }
*/
read(deep) {
read(options) {
let buffer = emptyStringBuffer;
let chunk, chunks;
while ((chunk = this.readChunk()) !== null) {
while ((chunk = this.readChunk(options)) !== null) {
if (Buffer.isBuffer(chunk)) {

@@ -661,3 +700,3 @@ buffer = Buffer.concat([buffer, chunk], buffer.length + chunk.length);

}
buffer = reduce(buffer, chunks, chunk, deep);
buffer = reduce(buffer, chunks, chunk);
}

@@ -676,6 +715,6 @@ }

* Consume template result content one chunk at a time.
*
* @param { RenderOptions } [options]
* @returns { unknown }
*/
readChunk() {
readChunk(options) {
const isString = this.index % 2 === 0;

@@ -704,9 +743,9 @@ const index = (this.index / 2) | 0;

if (part.length > 1) {
value = part.getValue(this.values.slice(index, index + part.length));
value = part.getValue(this.values.slice(index, index + part.length), options);
this.index += part.length;
} else {
value = part.getValue([this.values[index]]);
value = part.getValue([this.values[index]], options);
}
} else {
value = part.getValue(this.values[index]);
value = part.getValue(this.values[index], options);
}

@@ -725,15 +764,10 @@

* @param { unknown } chunk
* @param { boolean } [deep]
* @returns { Buffer }
*/
function reduce(buffer, chunks, chunk, deep = false) {
function reduce(buffer, chunks, chunk) {
if (Buffer.isBuffer(chunk)) {
return Buffer.concat([buffer, chunk], buffer.length + chunk.length);
} else if (isTemplateResult(chunk)) {
if (deep) {
return reduce(buffer, chunks, chunk.read(deep), deep);
} else {
chunks.push(buffer, chunk);
return emptyStringBuffer;
}
chunks.push(buffer, chunk);
return emptyStringBuffer;
} else if (Array.isArray(chunk)) {

@@ -807,5 +841,6 @@ return chunk.reduce((buffer, chunk) => reduce(buffer, chunks, chunk), buffer);

* @param { number } [highWaterMark] - byte length to buffer before pushing data
* @param { RenderOptions } [options]
* @returns { () => void }
*/
getProcessor(renderer, stack, highWaterMark = 0) {
getProcessor(renderer, stack, highWaterMark = 0, options) {
const buffer = [];

@@ -843,3 +878,3 @@ let bufferLength = 0;

popStack = false;
chunk = getTemplateResultChunk(chunk, stack);
chunk = getTemplateResultChunk(chunk, stack, options);
}

@@ -928,9 +963,10 @@

* @param { Array<unknown> } stack
* @param { RenderOptions } [options]
*/
function getTemplateResultChunk(result, stack) {
let chunk = result.readChunk();
function getTemplateResultChunk(result, stack, options) {
let chunk = result.readChunk(options);
// Skip empty strings
if (Buffer.isBuffer(chunk) && chunk.length === 0) {
chunk = result.readChunk();
chunk = result.readChunk(options);
}

@@ -944,3 +980,3 @@

stack.unshift(chunk);
chunk = getTemplateResultChunk(chunk, stack);
chunk = getTemplateResultChunk(chunk, stack, options);
}

@@ -955,2 +991,3 @@

* @typedef TemplateResultRenderer { import('./default-template-result-renderer.js).TemplateResultRenderer }
* @typedef RenderOptions { import('./index.js).RenderOptions }
*/

@@ -968,5 +1005,6 @@

* @param { boolean } [asBuffer]
* @param { RenderOptions } [options]
* @returns { Promise<string> }
*/
constructor(result, processor, asBuffer = false) {
constructor(result, processor, asBuffer = false, options) {
return new Promise((resolve, reject) => {

@@ -996,3 +1034,5 @@ let stack = [result];

},
stack
stack,
0,
options
)();

@@ -999,0 +1039,0 @@ });

@@ -12,2 +12,6 @@ declare module '@popeindustries/lit-html-server' {

type RenderOptions = {
serializePropertyAttributes: boolean;
};
export const defaultTemplateProcessor: DefaultTemplateProcessor;

@@ -58,17 +62,17 @@ export const defaultTemplateResultProcessor: DefaultTemplateResultProcessor;

* Render a template result to a string resolving Promise.
* *Note* that TemplateResults are single use, and can only be rendered once.
*/
export function renderToString(result: TemplateResult): Promise<string>;
export function renderToString(result: TemplateResult, options?: RenderOptions): Promise<string>;
/**
* Render a template result to a Readable stream
* *Note* that TemplateResults are single use, and can only be rendered once.
*/
export function renderToStream(result: TemplateResult): import('stream').Readable;
export function renderToStream(
result: TemplateResult,
options?: RenderOptions
): import('stream').Readable;
/**
* Render a template result to a Buffer resolving Promise.
* *Note* that TemplateResults are single use, and can only be rendered once.
*/
export function renderToBuffer(result: TemplateResult): Promise<Buffer>;
export function renderToBuffer(result: TemplateResult, options?: RenderOptions): Promise<Buffer>;

@@ -94,3 +98,3 @@ /**

*/
getValue(value: unknown): unknown;
getValue(value: unknown, options?: RenderOptions): unknown;
}

@@ -107,3 +111,3 @@

*/
getValue(values: Array<unknown>): Buffer | Promise<Buffer>;
getValue(values: Array<unknown>, options?: RenderOptions): Buffer | Promise<Buffer>;
}

@@ -119,3 +123,3 @@

*/
getValue(values: Array<unknown>): Buffer | Promise<Buffer>;
getValue(values: Array<unknown>, options?: RenderOptions): Buffer | Promise<Buffer>;
}

@@ -133,3 +137,3 @@

*/
getValue(values: Array<unknown>): Buffer;
getValue(values: Array<unknown>, options?: RenderOptions): Buffer;
}

@@ -147,3 +151,3 @@

*/
getValue(values: Array<unknown>): Buffer;
getValue(values: Array<unknown>, options?: RenderOptions): Buffer;
}

@@ -181,3 +185,4 @@

stack: Array<unknown>,
highWaterMark?: number
highWaterMark?: number,
options?: RenderOptions
): () => void;

@@ -205,3 +210,3 @@

*/
read(deep: boolean): unknown;
read(options?: RenderOptions): unknown;

@@ -211,3 +216,3 @@ /**

*/
readChunk(): unknown;
readChunk(options?: RenderOptions): unknown;
}

@@ -214,0 +219,0 @@

@@ -65,2 +65,12 @@ 'use strict';

/**
* Determine if "value" is an object
*
* @param { unknown } value
* @returns { boolean }
*/
function isObject(value) {
return Object.prototype.toString.call(value) === '[object Object]';
}
/**
* An empty string Buffer

@@ -105,4 +115,4 @@ */

return string.replace(RE_SCRIPT_STYLE_TAG, '<\\/$1').replace(/<!--/g, '\\x3C!--');
case 'attribute':
case 'text':
case 'attribute':
default:

@@ -149,2 +159,6 @@ return string.replace(RE_HTML, (match) => HTML_ESCAPES[match]);

/**
* @typedef RenderOptions { import('./index.js).RenderOptions }
*/
/**
* Determine if "part" is a NodePart

@@ -204,5 +218,6 @@ *

* @param { any } value
* @param { RenderOptions } [options]
* @returns { any }
*/
getValue(value) {
getValue(value /*, options */) {
return value;

@@ -225,5 +240,6 @@ }

* @param { any } value
* @param { RenderOptions } [options]
* @returns { any }
*/
getValue(value) {
getValue(value /*, options */) {
return resolveNodeValue(value, this);

@@ -260,5 +276,6 @@ }

* @param { Array<unknown> } values
* @param { RenderOptions } [options]
* @returns { Buffer|Promise<Buffer> }
*/
getValue(values) {
getValue(values, options) {
let chunks = [this.prefix];

@@ -270,3 +287,7 @@ let chunkLength = this.prefix.length;

const string = this.strings[i];
let value = resolveAttributeValue(values[i], this);
let value = resolveAttributeValue(
values[i],
this,
options !== undefined ? options.serializePropertyAttributes : false
);

@@ -346,5 +367,6 @@ // Bail if 'nothing'

* @param { Array<unknown> } values
* @param { RenderOptions } [options]
* @returns { Buffer|Promise<Buffer> }
*/
getValue(values) {
getValue(values /*, options */) {
let value = values[0];

@@ -371,9 +393,18 @@

* Retrieve resolved string Buffer from passed "values".
* Properties have no server-side representation,
* so always returns an empty string.
* Returns an empty string unless "options.serializePropertyAttributes=true"
*
* @param { Array<unknown> } values
* @returns { string }
* @param { RenderOptions } [options]
* @returns { Buffer }
*/
getValue(/* values */) {
getValue(values, options) {
if (options !== undefined && options.serializePropertyAttributes) {
const value = super.getValue(values, options);
const prefix = Buffer.from('.');
return value instanceof Promise
? value.then((value) => Buffer.concat([prefix, value]))
: Buffer.concat([prefix, value]);
}
return emptyStringBuffer;

@@ -394,5 +425,6 @@ }

* @param { Array<unknown> } values
* @returns { string }
* @param { RenderOptions } [options]
* @returns { Buffer }
*/
getValue(/* values */) {
getValue(/* values, options */) {
return emptyStringBuffer;

@@ -407,5 +439,6 @@ }

* @param { AttributePart } part
* @returns { unknown }
* @param { boolean } [serialiseObjectsAndArrays]
* @returns { any }
*/
function resolveAttributeValue(value, part) {
function resolveAttributeValue(value, part, serialiseObjectsAndArrays = false) {
if (isDirective(value)) {

@@ -431,4 +464,6 @@ value = resolveDirectiveValue(value, part);

return value;
} else if (serialiseObjectsAndArrays && (isObject(value) || Array.isArray(value))) {
return Buffer.from(escape(JSON.stringify(value), 'attribute'));
} else if (isPromise(value)) {
return value.then((value) => resolveAttributeValue(value, part));
return value.then((value) => resolveAttributeValue(value, part, serialiseObjectsAndArrays));
} else if (isSyncIterator(value)) {

@@ -440,3 +475,3 @@ if (!Array.isArray(value)) {

value.reduce((values, value) => {
value = resolveAttributeValue(value, part);
value = resolveAttributeValue(value, part, serialiseObjectsAndArrays);
// Flatten

@@ -460,3 +495,3 @@ if (Array.isArray(value)) {

* @param { NodePart } part
* @returns { unknown }
* @returns { any }
*/

@@ -535,2 +570,6 @@ function resolveNodeValue(value, part) {

/**
* @typedef RenderOptions { import('./index.js).RenderOptions }
*/
let id = 0;

@@ -583,10 +622,10 @@

*
* @param { boolean } deep - recursively resolve nested TemplateResults
* @param { RenderOptions } [options]
* @returns { unknown }
*/
read(deep) {
read(options) {
let buffer = emptyStringBuffer;
let chunk, chunks;
while ((chunk = this.readChunk()) !== null) {
while ((chunk = this.readChunk(options)) !== null) {
if (Buffer.isBuffer(chunk)) {

@@ -598,3 +637,3 @@ buffer = Buffer.concat([buffer, chunk], buffer.length + chunk.length);

}
buffer = reduce(buffer, chunks, chunk, deep);
buffer = reduce(buffer, chunks, chunk);
}

@@ -613,6 +652,6 @@ }

* Consume template result content one chunk at a time.
*
* @param { RenderOptions } [options]
* @returns { unknown }
*/
readChunk() {
readChunk(options) {
const isString = this.index % 2 === 0;

@@ -641,9 +680,9 @@ const index = (this.index / 2) | 0;

if (part.length > 1) {
value = part.getValue(this.values.slice(index, index + part.length));
value = part.getValue(this.values.slice(index, index + part.length), options);
this.index += part.length;
} else {
value = part.getValue([this.values[index]]);
value = part.getValue([this.values[index]], options);
}
} else {
value = part.getValue(this.values[index]);
value = part.getValue(this.values[index], options);
}

@@ -662,15 +701,10 @@

* @param { unknown } chunk
* @param { boolean } [deep]
* @returns { Buffer }
*/
function reduce(buffer, chunks, chunk, deep = false) {
function reduce(buffer, chunks, chunk) {
if (Buffer.isBuffer(chunk)) {
return Buffer.concat([buffer, chunk], buffer.length + chunk.length);
} else if (isTemplateResult(chunk)) {
if (deep) {
return reduce(buffer, chunks, chunk.read(deep), deep);
} else {
chunks.push(buffer, chunk);
return emptyStringBuffer;
}
chunks.push(buffer, chunk);
return emptyStringBuffer;
} else if (Array.isArray(chunk)) {

@@ -744,5 +778,6 @@ return chunk.reduce((buffer, chunk) => reduce(buffer, chunks, chunk), buffer);

* @param { number } [highWaterMark] - byte length to buffer before pushing data
* @param { RenderOptions } [options]
* @returns { () => void }
*/
getProcessor(renderer, stack, highWaterMark = 0) {
getProcessor(renderer, stack, highWaterMark = 0, options) {
const buffer = [];

@@ -780,3 +815,3 @@ let bufferLength = 0;

popStack = false;
chunk = getTemplateResultChunk(chunk, stack);
chunk = getTemplateResultChunk(chunk, stack, options);
}

@@ -865,9 +900,10 @@

* @param { Array<unknown> } stack
* @param { RenderOptions } [options]
*/
function getTemplateResultChunk(result, stack) {
let chunk = result.readChunk();
function getTemplateResultChunk(result, stack, options) {
let chunk = result.readChunk(options);
// Skip empty strings
if (Buffer.isBuffer(chunk) && chunk.length === 0) {
chunk = result.readChunk();
chunk = result.readChunk(options);
}

@@ -881,3 +917,3 @@

stack.unshift(chunk);
chunk = getTemplateResultChunk(chunk, stack);
chunk = getTemplateResultChunk(chunk, stack, options);
}

@@ -892,2 +928,3 @@

* @typedef TemplateResultRenderer { import('./default-template-result-renderer.js).TemplateResultRenderer }
* @typedef RenderOptions { import('./index.js).RenderOptions }
*/

@@ -905,5 +942,6 @@

* @param { boolean } [asBuffer]
* @param { RenderOptions } [options]
* @returns { Promise<string> }
*/
constructor(result, processor, asBuffer = false) {
constructor(result, processor, asBuffer = false, options) {
return new Promise((resolve, reject) => {

@@ -933,3 +971,5 @@ let stack = [result];

},
stack
stack,
0,
options
)();

@@ -944,2 +984,3 @@ });

* @typedef TemplateResultRenderer { import('./default-template-result-renderer.js).TemplateResultRenderer }
* @typedef RenderOptions { import('./index.js).RenderOptions }
*/

@@ -958,9 +999,10 @@

* @param { TemplateResultProcessor } processor
* @param { RenderOptions } [options]
* @returns { Readable }
*/
constructor(result, processor) {
constructor(result, processor, options) {
super({ autoDestroy: true });
this.stack = [result];
this.process = processor.getProcessor(this, this.stack, 16384);
this.process = processor.getProcessor(this, this.stack, 16384, options);
}

@@ -1248,9 +1290,9 @@

* Render a template result to a Readable stream
* *Note* that TemplateResults are single use, and can only be rendered once.
*
* @param { TemplateResult } result - a template result returned from call to "html`...`"
* @param { RenderOptions } [options]
* @returns { Readable }
*/
function renderToStream(result) {
return new StreamTemplateRenderer(result, defaultTemplateResultProcessor);
function renderToStream(result, options) {
return new StreamTemplateRenderer(result, defaultTemplateResultProcessor, options);
}

@@ -1260,9 +1302,9 @@

* Render a template result to a string resolving Promise.
* *Note* that TemplateResults are single use, and can only be rendered once.
*
* @param { TemplateResult } result - a template result returned from call to "html`...`"
* @param { RenderOptions } [options]
* @returns { Promise<string> }
*/
function renderToString(result) {
return new PromiseTemplateRenderer(result, defaultTemplateResultProcessor, false);
function renderToString(result, options) {
return new PromiseTemplateRenderer(result, defaultTemplateResultProcessor, false, options);
}

@@ -1272,9 +1314,9 @@

* Render a template result to a Buffer resolving Promise.
* *Note* that TemplateResults are single use, and can only be rendered once.
*
* @param { TemplateResult } result - a template result returned from call to "html`...`"
* @param { RenderOptions } [options]
* @returns { Promise<Buffer> }
*/
function renderToBuffer(result) {
return new PromiseTemplateRenderer(result, defaultTemplateResultProcessor, true);
function renderToBuffer(result, options) {
return new PromiseTemplateRenderer(result, defaultTemplateResultProcessor, true, options);
}

@@ -1281,0 +1323,0 @@

{
"name": "@popeindustries/lit-html-server",
"version": "1.5.1",
"version": "1.6.0",
"description": "Render lit-html templates on the server",

@@ -5,0 +5,0 @@ "keywords": [

@@ -187,4 +187,8 @@ [![NPM Version](https://img.shields.io/npm/v/@popeindustries/lit-html-server.svg?style=flat)](https://npmjs.org/package/@popeindustries/lit-html-server)

### `renderToStream(TemplateResult): Readable`
> The following render methods accept an `options` object with the following properties:
>
> - **`serializePropertyAttributes: boolean`** - enable `JSON.stringify` of property attribute values (default: `false`)
### `renderToStream(result: TemplateResult, options: RenderOptions): Readable`
Returns the result of the template tagged by `html` as a Node.js `Readable` stream of markup:

@@ -203,3 +207,3 @@

### `renderToString(TemplateResult): Promise<string>`
### `renderToString(result: TemplateResult, options: RenderOptions): Promise<string>`

@@ -220,3 +224,3 @@ Returns the result of the template tagged by `html` as a Promise which resolves to a string of markup:

### `renderToBuffer(TemplateResult): Promise<Buffer>`
### `renderToBuffer(result: TemplateResult, options: RenderOptions): Promise<Buffer>`

@@ -341,5 +345,6 @@ Returns the result of the template tagged by `html` as a Promise which resolves to a Buffer of markup:

- property (attribute markup removed):
- property (attribute markup removed unless `RenderOptions.serializePropertyAttributes = true` ):
```js
const value = { some: 'text' };
html`

@@ -349,2 +354,7 @@ <input .value="${value}" />

//=> <input />
html`
<input .value="${value}" />
`;
//=> <input .value="{&quot;some&quot;:&quot;text&quot;}"/>
// (when render options.serializePropertyAttributes = true)
```

@@ -351,0 +361,0 @@

Sorry, the diff of this file is not supported yet

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