aboutsummaryrefslogtreecommitdiffstats
path: root/apps/comments/src/utils/decodeHtmlEntities.js
blob: 4c4929542569f518999732da18372833408faf9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/**
 * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

/**
 * @param {any} value -
 * @param {any} passes -
 */
export function decodeHtmlEntities(value, passes = 1) {
	const parser = new DOMParser()
	let decoded = value
	for (let i = 0; i < passes; i++) {
		decoded = parser.parseFromString(decoded, 'text/html').documentElement.textContent
	}
	return decoded
}