Methods
(static) decodeHtmlEntities(str) → {string}
Decodes HTML entities in a string using the following rules:
- & becomes &
- " becomes "
- ' becomes '
- < becomes <
- > becomes >
It is different than dom.decodeHTML, which decodes all characters using the browser's DOMParser. This function only decodes the characters listed above and should be used when DOMParser is not available.
- Source:
- See:
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string
|
The string to decode |
Returns:
- Type:
-
string
The decoded string
Example
htmlDecode('<a href="#">Link</a>') // <a href="#">Link</a>
(static) encodeHtmlEntities(str) → {string}
Encodes HTML entities in a string using the following rules:
- & (ampersand) becomes &
- " (double quote) becomes "
- ' (single quote) becomes '
- < (less than) becomes <
-
(greater than) becomes >
It is different than dom.encodeHTML, which encodes all characters using the browser's DOMParser. This function only encodes the characters listed above and should be used when DOMParser is not available.
- Source:
- See:
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string
|
The string to encode |
Returns:
- Type:
-
string
The encoded string
Example
htmlEncode('<a href="#">Link</a>') // <a href="#">Link</a>