Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript: Converts HtmlEntities Package to TS #69326

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @type {HTMLTextAreaElement} */
let _decodeTextArea;
let _decodeTextArea: HTMLTextAreaElement | undefined;

/**
* Decodes the HTML entities from a given string.
Expand All @@ -16,7 +16,7 @@ let _decodeTextArea;
*
* @return {string} The decoded string.
*/
export function decodeEntities( html ) {
export function decodeEntities( html: string ): string {
// Not a string, or no entities to decode.
if ( 'string' !== typeof html || -1 === html.indexOf( '&' ) ) {
return html;
Expand All @@ -37,7 +37,7 @@ export function decodeEntities( html ) {
}

_decodeTextArea.innerHTML = html;
const decoded = _decodeTextArea.textContent;
const decoded = _decodeTextArea.textContent ?? '';
_decodeTextArea.innerHTML = '';

/**
Expand All @@ -57,5 +57,5 @@ export function decodeEntities( html ) {
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent
*/
return /** @type {string} */ ( decoded );
return /** @type {string} */ decoded;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Internal dependencies
*/
import { decodeEntities } from '../';
import { decodeEntities } from '..';

describe( 'decodeEntities', () => {
it( 'should not change html with no entities', () => {
Expand Down
Loading