Socket
Socket
Sign inDemoInstall

argon-html

Package Overview
Dependencies
0
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    argon-html

HTML template tag to convert template string to DOM nodes


Version published
Weekly downloads
3
increased by200%
Maintainers
1
Install size
38.3 kB
Created
Weekly downloads
 

Readme

Source

CodeQL

Argon HTML

HTML template tag to convert template string to DOM nodes

Install

npm i argon-html

Usage

Covert template string to compatible HTML string

Simple example:

import { htmlString } from "argon-html";

const text = "Hello World!";

const htmlStr = htmlString`
  <div class="container">
    <div class="text">${text}</div>
  </div>
`;

console.log(htmlStr);

/**
 * Output:
 *
 * <div class="container">
 *  <div class="text">Hello World</div>
 * </div>
 */

Complex example:

import { htmlString } from "argon-html";

const text = [
  '<div class="text">Hello</div>',
  '<div class="text">World</div>',
  { key: "value" },
];

const htmlStr = htmlString`
  <div class="container">
    ${text}
  </div>
`;

console.log(htmlStr);

/**
 * Output:
 *
 * <div class="container">
 *  <div class="text">Hello</div>
 *  <div class="text">World</div>
 *  {"key": "value"}
 * </div>
 */

Convert template string to DocumentFragment

import { html } from "argon-html";

const text = [
  '<div class="text">Hello</div>',
  '<div class="text">World</div>',
  { key: "value" },
];

const fragment = html`
  <div class="container">
    ${text}
  </div>
`;

console.log(fragment);

document.body.appendChild(fragment);

/**
 * Output:
 *
 * <DocumentFragment>
 *  <div class="container">
 *    <div class="text">Hello</div>
 *    <div class="text">World</div>
 *    {"key": "value"}
 *  </div>
 * </DocumentFragment>
 */

Keywords

FAQs

Last updated on 19 Jul 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc