src/common/label.helper.ts
/**
* Formats a label given a date, number or string.
*
* @export
* @param {*} label
* @returns {string}
*/
export function formatLabel(label: any): string {
if (label instanceof Date) {
label = label.toLocaleDateString();
} else {
label = label.toLocaleString();
}
return label;
}
/**
* Escapes a label.
*
* @export
* @param {*} label
* @returns {string}
*/
export function escapeLabel(label: any): string {
return label.toLocaleString().replace(/[&'`"<>]/g, match => {
return {
'&': '&',
'\'': ''',
'`': '`',
'"': '"',
'<': '<',
'>': '>',
}[match];
});
}