html-truncator
TypeScript icon, indicating that this package has built-in type declarations

1.0.17 • Public • Published

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.

/html-truncator/

    Package Sidebar

    Install

    npm i html-truncator

    Weekly Downloads

    2

    Version

    1.0.17

    License

    MIT

    Unpacked Size

    7.75 kB

    Total Files

    8

    Last publish

    Collaborators

    • rjmacarthy