Skip to content

Commit

Permalink
Added removeHTML function and removeHTML tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenMasterJacob20011 committed Jun 5, 2024
1 parent 35a3412 commit 8d1873d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,16 @@ export function setActionProperty(component, action, result, row, data, instance
return component;
}

/**
* Removes HTML tags from string e.g. <div>Hello World</div> => Hello World
* @param {string} str
* @returns {string}
*/
export function removeHTML(str) {
const doc = new window.DOMParser().parseFromString(str, 'text/html');
return (doc.body.textContent || '').trim();
}

/**
* Unescape HTML characters like &lt, &gt, &amp and etc.
* @param str
Expand Down
7 changes: 7 additions & 0 deletions src/utils/utils.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,13 @@ describe('Util Tests', () => {
});
});

describe('removeHTML', () => {
it('should remove html tags from string', () => {
const removedHTML = utils.removeHTML('<div><p> Hello</p> <p>World</p></div>');
expect(removedHTML).to.equal('Hello World');
});
});

describe('getCurrencyAffixes', () => {
it('USD en', (done) => {
try {
Expand Down

0 comments on commit 8d1873d

Please sign in to comment.