@popeindustries/lit-html
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -0,1 +1,47 @@ | ||
/* global window */ | ||
/* global ReadableStream */ | ||
import { render } from 'lit-html'; | ||
export * from 'lit-html'; | ||
const RENDER_ELEMENT = window.document.createElement('div'); | ||
/** | ||
* lit-html-server API parity | ||
* @param {import('lit-html').TemplateResult} result | ||
* @returns {ReadableStream} | ||
*/ | ||
export function renderToStream(result) { | ||
if (typeof ReadableStream === 'undefined') { | ||
throw Error('ReadableStream not supported on this platform'); | ||
} | ||
return new ReadableStream({ | ||
start(controller) { | ||
controller.enqueue(renderToBuffer(result)); | ||
controller.close(); | ||
} | ||
}); | ||
} | ||
/** | ||
* lit-html-server API parity | ||
* @param {import('lit-html').TemplateResult} result | ||
* @returns {Uint8Array} | ||
*/ | ||
export function renderToBuffer(result) { | ||
if (typeof TextEncoder === 'undefined') { | ||
throw Error('TextEncoder not supported on this platform'); | ||
} | ||
return new TextEncoder().encode(renderToString(result)); | ||
} | ||
/** | ||
* lit-html-server API parity | ||
* @param {import('lit-html').TemplateResult} result | ||
* @returns {string} html string | ||
*/ | ||
export function renderToString(result) { | ||
render(result, RENDER_ELEMENT); | ||
const htmlString = RENDER_ELEMENT.innerHTML; | ||
return htmlString; | ||
} |
declare module '@popeindustries/lit-html' { | ||
export * from 'lit-html'; | ||
export { renderToBuffer, renderToStream, renderToString } from '@popeindustries/lit-html-server'; | ||
export { | ||
renderToBuffer, | ||
renderToStream, | ||
renderToString | ||
} from '@popeindustries/lit-html/browser/index.js'; | ||
} | ||
@@ -5,0 +9,0 @@ |
{ | ||
"name": "@popeindustries/lit-html", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Seamlessly render lit-html templates on the server and in the browser", | ||
@@ -47,2 +47,3 @@ "keywords": [ | ||
"babel-eslint": "^10.0.1", | ||
"dvlp": "^7.5.2", | ||
"eslint": "^6.1.0", | ||
@@ -61,3 +62,4 @@ "eslint-config-prettier": "^6.0.0", | ||
"format": "prettier --write './{src,test}/**/*.{js,json}'", | ||
"lint": "eslint './{src,test}/**/*.js'" | ||
"lint": "eslint './{src,test}/**/*.js'", | ||
"test": "dvlp tests/" | ||
}, | ||
@@ -64,0 +66,0 @@ "husky": { |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
10484
109
10
1