{"id":14065,"library":"string-strip-html","title":"Strip HTML Tags from Strings","description":"The `string-strip-html` package, currently at version 13.5.3, is a robust utility designed to efficiently remove HTML tags from arbitrary string inputs. It is actively maintained as part of the Codsen monorepo, with updates released as needed for feature enhancements and bug fixes. A key differentiator is its \"no parser\" approach, meaning it does not attempt to fully parse or validate HTML. This design makes it exceptionally resilient and suitable for stripping tags from malformed, incomplete, or \"mixed\" HTML sources often found in user-generated content or messy data, where traditional DOM parsers might fail or be overkill. It provides granular control over which tags to strip and offers options to remove entire tag-content blocks (e.g., `<script>...</script>`). Since version 9.0.0, the library is distributed exclusively as an ECMAScript Module (ESM), aligning with modern JavaScript ecosystem standards and requiring `import` syntax.","status":"active","version":"13.5.3","language":"javascript","source_language":"en","source_url":"https://github.com/codsen/codsen","tags":["javascript","code","extract","from","html","jsp","mixed","remove","separate","typescript"],"install":[{"cmd":"npm install string-strip-html","lang":"bash","label":"npm"},{"cmd":"yarn add string-strip-html","lang":"bash","label":"yarn"},{"cmd":"pnpm add string-strip-html","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package is pure ESM since v9. For CommonJS environments, use version 8.5.0 or earlier.","wrong":"const { stripHtml } = require('string-strip-html');","symbol":"stripHtml","correct":"import { stripHtml } from 'string-strip-html';"},{"note":"`stripHtml` is a named export, not a default export.","wrong":"import stripHtml from 'string-strip-html';","symbol":"stripHtml","correct":"import { stripHtml } from 'string-strip-html';"},{"note":"TypeScript type import for configuring `stripHtml` behavior.","symbol":"StripHtmlOptions","correct":"import type { StripHtmlOptions } from 'string-strip-html';"}],"quickstart":{"code":"import { strict as assert } from \"assert\";\nimport { stripHtml } from \"string-strip-html\";\n\n// Basic usage: removes HTML tags, replacing them with a single space.\nassert.equal(\n  stripHtml(\"Some text <b>and</b> text.\").result,\n  \"Some text and text.\"\n);\n\n// Handles consecutive tags gracefully by collapsing whitespace.\nassert.equal(stripHtml(\"aaa<div>bbb</div>ccc\").result, \"aaa bbb ccc\");\n\n// Option to strip specific tags along with their entire contents.\nassert.equal(\n  stripHtml(\"a <pre><code>void a;</code></pre> b\", {\n    stripTogetherWithTheirContents: [\n      \"script\", // default\n      \"style\",  // default\n      \"xml\",    // default\n      \"pre\"     // custom-added\n    ]\n  }).result,\n  \"a b\"\n);\n\n// Intelligently distinguishes between HTML tags and legitimate angle brackets.\nassert.equal(stripHtml(\"a < b and c > d\").result, \"a < b and c > d\");\n","lang":"javascript","description":"Demonstrates basic HTML stripping, whitespace handling, stripping tag contents, and proper handling of angle brackets that are not HTML tags."},"warnings":[{"fix":"Update your project to use ES modules with `import` syntax, or explicitly install version 8.5.0 (`npm i string-strip-html@8.5.0`) for CommonJS compatibility.","message":"The package was converted to pure ECMAScript Modules (ESM) starting from version 9.0.0. CommonJS `require()` statements will no longer work.","severity":"breaking","affected_versions":">=9.0.0"},{"fix":"If you require a full HTML parser for validation, manipulation, or complex error correction, consider libraries like `jsdom` or `cheerio` instead. This library is best for simple, robust tag removal.","message":"This library does not parse HTML like a DOM parser. It works by detecting patterns that resemble HTML tags. It will not correct malformed HTML, balance tags, or provide a DOM tree.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Carefully select which tags to include in `stripTogetherWithTheirContents`. Use this option primarily for tags whose content is irrelevant after stripping (e.g., `<script>`, `<style>`, `<pre>`) rather than general layout tags.","message":"The `stripTogetherWithTheirContents` option completely removes specified tags and everything between their opening and closing tags. Be mindful when adding common HTML structural tags like `div` or `span`.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'13.5.3':15 '9.0.0':129 'activ':32 'align':140 'approach':58 'arbitrari':27 'attempt':63 'block':125 'bug':49 'code':151 'codsen':38 'content':94,124 'control':110 'current':12 'data':97 'design':20,71 'differenti':53 'distribut':133 'dom':100 'e.g':126 'ecmascript':137 'ecosystem':144 'effici':22 'enhanc':47 'entir':121 'esm':139 'except':74 'exclus':134 'extract':152 'fail':103 'featur':46 'fix':50 'found':89 'fulli':65 'generat':93 'granular':109 'html':2,10,24,69,86,154 'import':148 'incomplet':83 'input':29 'javascript':143,150 'jsp':155 'key':52 'librari':131 'maintain':33 'make':72 'malform':82 'mean':59 'messi':96 'might':102 'mix':85,156 'modern':142 'modul':138 'monorepo':39 'need':44 'offer':117 'often':88 'option':118 'overkil':106 'packag':11 'pars':66 'parser':57,101 'part':35 'provid':108 'releas':42 'remov':23,120,157 'requir':147 'resili':75 'robust':18 'separ':158 'sinc':127 'sourc':87 'standard':145 'string':5,8,28 'string-strip-html':7 'strip':1,9,79,115 'suitabl':77 'syntax':149 'tag':3,25,80,113,123 'tag-cont':122 'tradit':99 'typescript':159 'updat':41 'user':92 'user-gener':91 'util':19 'valid':68 'version':14,128","created_at":"2026-04-20T01:57:45.531884+00:00","updated_at":"2026-04-20T01:57:45.531884+00:00","problems":[{"fix":"If using Node.js, ensure your package is configured for ESM (e.g., `\"type\": \"module\"` in `package.json`) and use `import { stripHtml } from 'string-strip-html';`. Alternatively, downgrade to version 8.5.0 for CommonJS support: `npm install string-strip-html@8.5.0`.","cause":"Attempting to `require()` `string-strip-html` in a CommonJS context when the installed version is ESM-only.","error":"TypeError: require is not a function"},{"fix":"Change the import statement to use named import syntax: `import { stripHtml } from 'string-strip-html';`.","cause":"Attempting to use a default import (`import stripHtml from 'string-strip-html';`) when `stripHtml` is a named export.","error":"SyntaxError: Named export 'stripHtml' not found. The requested module 'string-strip-html' does not provide an export named 'stripHtml'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":"https://codsen.com/os/string-strip-html","github":"https://github.com/codsen/codsen","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/string-strip-html","openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization","data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}