Mr Toh posted a good article comparing various means to strip tags from HTML, including our npm package string-strip-html
.
To add 2p.
It’s not just about speed.
The primary reason why you’d use an npm package, rather than regex, is whitespace management. The string-strip-html
ensures the stripped results looks as if a human deleted the tags. Our program can even be used to generate email text versions, placing URLs besides the stripped link labels.
The second reason is string-strip-html
can tackle broken HTML, dirty HTML and HTML mixed with other languages.
The third reason is string-strip-html
saves you time: writing unit tests, writing correct type definitions (you’re using TypeScript, right?) and tackling edge cases.