
Security News
PodRocket Podcast: Inside the Recent npm Supply Chain Attacks
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
htmlstrip-native
Advanced tools
#Simple HTML tags stripping library
via npm:
npm install htmlstrip-native
git clone git://github.com/zaro/node-htmlstrip-native.git
cd node-htmlstrip-native
npm install
Example:
var html_strip = require('htmlstrip-native');
var html = '<style>b {color: red;}</style>' +
' Yey, <b> No more, tags</b>' +
'<script>document.write("Hello from Javascript")</script>';
var options = {
include_script : false,
include_style : false,
compact_whitespace : true,
include_attributes : { 'alt': true }
};
// Strip tags and decode HTML entities
var text = html_strip.html_strip(html,options);
console.log(text)
// Decode HTML entities only
var no_entities = html_strip.html_entities_decode('Hello ⌣')
The html_strip function expects either a string as first argument or a 'utf-16le', encoded Buffer. The optional second argument can hold the following options:
{
include_script : true, // include the content of <script> tags
include_style : true, // include the content of <style> tags
compact_whitespace : false // compact consecutive '\s' whitespace into single char
include_attributes : { // include attribute values in the output
'*':true , // special value, means : Include ALL attributes
'alt': true , // include attributes named 'alt'
}
}
Same thing can be achieved really simply without native modules with htmlparser2 for example. This module is ~30 times faster than using htmlparser2.
FAQs
Strip html tags with ease and efficiency
The npm package htmlstrip-native receives a total of 28 weekly downloads. As such, htmlstrip-native popularity was classified as not popular.
We found that htmlstrip-native demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.