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

Render lit-html templates on the server

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.8K
decreased by-10.14%
Maintainers
1
Weekly downloads
 
Created
Source

NPM Version Build Status

lit-html-server

Render lit-html templates on the server as Node.js streams. Supports all lit-html types and special attribute bindings.

Although based on lit-html semantics, lit-html-server is a great general purpose HTML template streaming library. Tagged template literals are a native JavaScript feature, and the HTML rendered is 100% standard markup, with no special syntax or client-side runtime dependencies.

Usage

Install with npm/yarn:

$ npm install --save @popeindustries/lit-html-server

...write your lit-html template:

const { html } = require('@popeindustries/lit-html-server');

function layout(data) {
  return html`<!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>${data.title}</title>
    </head>
    <body>
      ${body(data.api)}
    </body>
    </html>`;
}

async function body(apiPath) {
  // Some Promise-based request method
  const data = await fetchRemoteData(apiPath);

  return html`<h1>${data.title}</h1>
    <x-widget ?enabled=${data.hasWidget}></x-widget>
    <p class="${data.invertedText ? 'negative' : ''}">${data.text}</p>`;
}

...and render:

const { render } = require('@popeindustries/lit-html-server');

// Returns a Node.js Readable stream which can be piped to `response`
render(layout({ title: 'Home', api: '/api/home' }));

TODO

  • html escape values
  • handle special attribute bindings (?.@)
  • add missing attribute quotes
  • support sync iterators
  • port default directives
  • support async iterators (wait until no longer experimental)

Thanks!

Thanks to Thomas Parslow for the stream-template library that was the basis for this streaming implementation, and thanks to Justin Fagnani and the team behind the lit-html project!

Keywords

FAQs

Package last updated on 03 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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