🥞 Removes HTML code from the given string. Can even extract text-only from the given an HTML string. ✨
npm install @igorskyflyer/strip-html
Strip HTML cleanly • Normalize messy whitespace • Fast replacement • Return plain text •
- Features
- Usage
- API
- Examples
- Changelog
- Support
- License
- Related
- Author
- ✅ Strips HTML tags cleanly
- 🧹 Trims leading and trailing whitespace
- 📏 Collapses multiple spaces, tabs, newlines into one
- ⚙️ Provides safe defaults for predictable output
Install it by executing any of the following, depending on your preferred package manager:
``bash`
pnpm add @igorskyflyer/strip-html
`bash`
yarn add @igorskyflyer/strip-html
`bash`
npm i @igorskyflyer/strip-html
Strips HTML tags completely.
html: string - The HTML string to process.
args: IOptions - The options to pass.
An object with the following properties:
`ts`
interface IOptions {
trimWhitespace?: boolean
}
trimWhitespace?: boolean - If true, trims and normalizes whitespace - internal runs of whitespace (spaces, tabs, newlines) collapse to a single space. Leading/trailing whitespace is always trimmed.
Returns the processed string.
---
Strips only the HTML code while keeping the text content.
html: string - The HTML string to process.
args: IOptions - The options to pass.
An object with the following properties:
`ts`
interface IOptions {
trimWhitespace?: boolean
}
trimWhitespace?: boolean - If true, trims and normalizes whitespace - internal runs of whitespace (spaces, tabs, newlines) collapse to a single space. Leading/trailing whitespace is always trimmed.
Returns the processed string.
example.ts`ts
import { stripHtmlCode, stripHtml } from '@igorskyflyer/strip-html'
console.log(
stripHtmlCode(
))/*
will print
Title
This is a paragraph with some emphasis and a link.
Item 1
Item 2
Item 3
*/
console.log(
stripHtml(
)) // will print an empty string, i.e. ''console.log(stripHtml(
Hello world)) // will print 'Hello world'console.log(
stripHtmlCode(
, { trimWhitespace: true })) // will print 'Title This is a paragraph with some emphasis and a link. Item 1 Item 2 Item 3'
``📑 Read about the latest changes in the CHANGELOG.
Licensed under the MIT license.
> _✒ DúöScríbî allows you to convert letters with diacritics to regular letters. 🤓_
@igorskyflyer/magic-queryselector
> _🪄 A TypeScript-types patch for querySelector/querySelectorAll, make them return types you expect them to! 🔮_
@igorskyflyer/astro-escaped-component
> _🏃🏻♂️➡️ An Astro component that holds only HTML-encoded content. 📜_
> _🧵 Provides ways of checking whether a String is present in an Array of Strings using custom Comparators. 🔍_
@igorskyflyer/strip-html-headings
> _🍛 Strips HTML headings! 🍤_