Socket
Socket
Sign inDemoInstall

@so1ve/leafac-html

Package Overview
Dependencies
2
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @so1ve/leafac-html

Radically Straightforward HTML


Version published
Weekly downloads
71
decreased by-26.8%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

@so1ve/html

HTML tagged template literals

Source Package Continuous Integration

Videos


Demonstration


Code Review

Installation

$ npm install @so1ve/html

Use @so1ve/html with Prettier (automatic formatting), and the Visual Studio Code extensions Prettier - Code formatter (Prettier support) and es6-string-html (syntax highlighting).

Features, Usage, and Examples

  • Use tagged template literals as an HTML template engine. For example:

    import html from "@so1ve/html";
    
    console.log(html`<p>${"Leandro Facchinetti"}</p>`); // => <p>Leandro Facchinetti</p>
    
  • Safe by default. For example:

    console.log(html`<p>${`<script>alert(1);</script>`}</p>`); // => <p>&#x3C;script&#x3E;alert(1);&#x3C;/script&#x3E;</p>
    
  • Unsafely interpolate trusted HTML with $${...}. For example:

    console.log(html`<p>$${`<span>Leandro Facchinetti</span>`}</p>`); // => <p><span>Leandro Facchinetti</span></p>
    
  • Join interpolated arrays. For example:

    console.log(html`<p>${["Leandro", " ", "Facchinetti"]}</p>`); // => <p>Leandro Facchinetti</p>
    

    Array interpolations are safe by default; if you wish to unsafely interpolate an array of trusted HTML use $${[...]}.

  • @so1ve/html doesn’t encode HTML itself. It relies on he, which is much more robust than any bespoke encoding.

  • @so1ve/html doesn’t try to format the output. If you need pretty HTML, you may call Prettier programmatically on the output.

  • @so1ve/html generates strings. No kind of virtual DOM here. For readability, the HTML type is exported in TypeScript, and you may use it like in the following example:

    import { html, HTML } from ".";
    const name: HTML = html`<p>Leandro Facchinetti</p>`;
    console.log(name);
    
  • @so1ve/html sanitizes (removes) invalid XML characters. It uses sanitize-xml-string. For example:

    console.log(html`<p>A backspace is invalid in XML: |\b|</p>`); // => <p>A backspace is invalid in XML: ||</p>
    

Prior Art

Keywords

FAQs

Last updated on 17 Oct 2022

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