Skip to content

dbspt/scorpion-html

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scorpion HTML

Commitizen friendly

Scorpion-core support pack.

Installation

$ npm install @dbservices/scorpion-html

Features, Usage, and Examples

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

    import html from "@dbservices/scorpion-html";
    
    console.log(html`<p>${"Scorpion HTML"}</p>`); // => <p>Scorpion HTML</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>Scorpion HTML</span>`}</p>`); // => <p><span>Scorpion HTML</span></p>
  • Join interpolated arrays. For example:

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

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