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

0.1.1 • Public • Published

capHTMLString

Note: This is a WIP, just a quick package setup for a function I wrote for a separate project. It's not perfect but mostly works.

Usage

const newHTMLString = capHTMLString(yourHTMLString, cap)

Where:

  • cap: is the number of characters to cap your string to.
  • yourHTMLString: the string containing HTML you want to cap.

How it works

The function first parses your string into a div (this is why this only runs on browsers), then goes through all child nodes recursively, checking their character count (ignoring HTML) and capping text ChildNodes when it is necessary, then ignores any subsequent sibling Nodes.

Readme

Keywords

none

Package Sidebar

Install

npm i cap-html-string

Weekly Downloads

2

Version

0.1.1

License

ISC

Unpacked Size

13.4 kB

Total Files

8

Last publish

Collaborators

  • diegoferreyra