Skip to content

wrapIfNeeded

wrapIfNeeded(content, threshold?, tag?) → string · XML

Automatically wrap content in CDATA if it contains enough special characters to benefit. See Chapter 22.

  • content (required): the text content

  • threshold (optional): special char count threshold

  • tag (optional): wrapper format

utlx
wrapIfNeeded("<script>alert('hi')</script>")
// "<![CDATA[<script>alert('hi')</script>]]>"

wrapIfNeeded("plain text")              // "plain text" (no wrapping needed)

Released under AGPL-3.0.