Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 27x 27x 4x 6x | /**
* Petites fonctions de texte partagées par la vue graphe (2D/3D).
*/
/**
* Tronque une valeur à `max` caractères, points de suspension compris.
* @param {*} value valeur à tronquer (convertie en chaîne)
* @param {number} max longueur maximale (>= 2)
* @returns {string}
*/
export function truncate(value, max) {
const str = String(value ?? '');
if (!Number.isFinite(max) || max < 2 || str.length <= max) return str;
return `${str.slice(0, max - 1)}…`;
}
/**
* Échappe le HTML d'une valeur destinée à un tooltip (`innerHTML`).
* Les libellés viennent de la KB : ils ne doivent jamais être interprétés comme du balisage.
* @param {*} value
* @returns {string}
*/
export function escapeHtml(value) {
return String(value ?? '')
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
|