MOBILE-2611 utils: Function to check whether HTML content is blank

main
Albert Gasset 2018-10-01 17:49:55 +02:00
parent 6547bcf541
commit c770fb9014
1 changed files with 17 additions and 0 deletions

View File

@ -427,6 +427,23 @@ export class CoreTextUtilsProvider {
return /<[a-z][\s\S]*>/i.test(text);
}
/**
* Check if HTML content is blank.
*
* @param {string} content HTML content.
* @return {boolean} True if the string does not contain actual content: text, images, etc.
*/
htmlIsBlank(content: string): boolean {
if (!content) {
return true;
}
const div = document.createElement('div');
div.innerHTML = content;
return div.textContent === '' && div.querySelector('img, object, hr') === null;
}
/**
* Check if a text contains Unicode long chars.
* Using as threshold Hex value D800