Socket
Socket
Sign inDemoInstall

@joyned/html-fairy

Package Overview
Dependencies
1
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @joyned/html-fairy

A simple, tiny, and XSS-protected tool for creating HTML structures from strings and arguments.


Version published
Weekly downloads
0
Maintainers
2
Install size
16.0 kB
Created
Weekly downloads
 

Readme

Source

GitHub license npm version packge size

CI CD

html-fairy

A simple, tiny, and XSS-protected tool for creating HTML structures from strings and arguments.

Installation

npm install @joyned/html-fairy

Usage

import htmlFairy from "@joyned/html-fairy";

const element = htmlFairy`<div data-attribute="value">Content</div>`;

Any argument that is an HTML element will be included in the resulting structure in the same position as the corresponding placeholder in the template string. Non-element arguments will be converted to HTML-escaped strings and included in the resulting structure.

import htmlFairy from "@joyned/html-fairy";

const value = 'foo';
const element = htmlFairy`<div data-attribute="${value}">Content</div>`;

Arrays of elements can also be passed as arguments, and the resulting structure will include all the elements from the array in the correct nested position.

import htmlFairy from "@joyned/html-fairy";

const list = ['a', 'b', 'c'].map((x) => htmlFairy`<li>${x}</li>`);
const element = htmlFairy`<ul>${list}</ul>`;

It's prevent XSS by default.

import htmlFairy from "@joyned/html-fairy";

const evilUserInput = '<script>alert("XSS")</script>';
const someElement = htmlFairy`<div>no xss</div>`;
const element = htmlFairy`<div>${someElement}${evilUserInput}</div>`;
no-xss

License

html-fairy is released under the MIT License. See the LICENSE file for details.

FAQs

Last updated on 31 Jan 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