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

async-htm-to-string

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-htm-to-string

Renders a htm tagged template asyncly into a string

  • 2.1.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

async-htm-to-string

Renders a htm tagged template asyncly into a string.

npm version npm downloads Module type: CJS+ESM Types in JS js-semistandard-style Follow @voxpelli@mastodon.social

Usage

Simple

npm install async-htm-to-string
const { html, renderToString } = require('async-htm-to-string');

const customTag = ({ prefix }, children) => html`<div>${prefix}-${children}</div>`;
const dynamicContent = 'bar';
// Will equal "<div>foo-bar</div>
const result = await renderToString(html`<${customTag} prefix="foo">${dynamicContent}</${customTag}>`);

API

html

Is h() bound to htm (htm.bind(h)). Used with template literals, like:

const renderableElement = html`<div>${content}</div>`;

rawHtml / rawHtml(rawString)

If you need to provide pre-escaped raw HTML content, then you can use rawHtml as either a template literal or by calling it with the

const renderableElement = rawHtml`<div>&amp;${'&quot;'}</div>`;
const renderableElement = rawHtml('<div>&amp;</div>');

You can also use the result of any of those rawHtml inside html, like:

const renderableElement = html`<div>${rawHtml`&amp;`}</div>`;

h(type, props, ...children)

The inner method that's htm is bound to.

render(renderableElement)

Takes the output from html and returns an async iterator that yields the strings as they are rendered

renderToString(renderableElement)

Same as render(), but asyncly returns a single string with the fully rendered result, rather than an async iterator.

Helpers

generatorToString(somethingIterable)

Asyncly loops over an iterable (like eg. an async iterable) and concatenates together the result into a single string that it resolves to. The brains behind renderToString().

Keywords

FAQs

Package last updated on 15 Jun 2023

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