New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

htmlescape

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

htmlescape

Properly escape JSON for usage as an object literal inside of a `<script>` tag

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1M
increased by11.13%
Maintainers
1
Weekly downloads
 
Created

What is htmlescape?

The htmlescape npm package is used to escape and unescape HTML entities in strings. This is particularly useful for preventing XSS (Cross-Site Scripting) attacks by ensuring that any HTML content is properly escaped before being rendered in a web page.

What are htmlescape's main functionalities?

Escape HTML

This feature allows you to escape HTML entities in a string to prevent XSS attacks. The code sample demonstrates how to convert potentially dangerous HTML content into a safe string.

const htmlescape = require('htmlescape');
const unsafeString = '<script>alert("XSS")</script>';
const safeString = htmlescape(unsafeString);
console.log(safeString); // &lt;script&gt;alert(&quot;XSS&quot;)&lt;/script&gt;

Unescape HTML

This feature allows you to unescape HTML entities in a string. The code sample demonstrates how to convert an escaped HTML string back to its original form.

const htmlescape = require('htmlescape');
const escapedString = '&lt;script&gt;alert(&quot;XSS&quot;)&lt;/script&gt;';
const unescapedString = htmlescape.unescape(escapedString);
console.log(unescapedString); // <script>alert("XSS")</script>

Other packages similar to htmlescape

Keywords

FAQs

Package last updated on 23 Mar 2016

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