Documentation v4.0.0

Overview

Escapes HTML special characters (&, ', `, ", <, >) in a string.

Import

import {utils} from 'metronic-extension';
const {escapeHTML} = utils;

Signature

escapeHTML(str: string): string
Parameter Type Description
str string String to escape.
Returns: string — Escaped string.

Example

Result:
<div class="mb-3">
  <label class="form-label">Input value</label>
  <input id="escapeHTMLInput" class="form-control form-control-solid" placeholder="Enter text with HTML characters...">
</div>
<div>
  <span class="fw-bold">Result: </span>
  <code id="escapeHTMLResult"></code>
</div>
import {utils} from 'metronic-extension';
const {escapeHTML} = utils;

escapeHTML('I <b>think</b> this is good.');
// 'I &lt;b&gt;think&lt;/b&gt; this is good.'

escapeHTML('John "Johnny" Smith');
// 'John &quot;Johnny&quot; Smith'