🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

html-truncator

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-truncator

truncate html to a specified length but maintain the structure

1.0.17
latest
npm
Version published
Maintainers
1
Created
Source

html-truncator

This function takes in an HTML string and a maximum length and returns a truncated version of the HTML string that is no longer than the maximum length. The resulting string is valid HTML and ends with an ellipsis.

Install

npm i html-truncator

Usage


const htmlString = "<p>This is some long HTML text</p>";
const truncatedHtml = truncate(htmlString, 10);

console.log(truncatedHtml);
// Output: <p>This is so</p>...

Notes

This package uses the htmlparser2 package to parse the input HTML string and generate a DOM tree, which is then traversed recursively to build the truncated HTML string. The resulting string is valid HTML and ends with an ellipsis.

Keywords

html

FAQs

Package last updated on 21 Apr 2023

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