feat(utils): add fmtLocation to normalize ICS LOCATION strings for display
Strips RFC 5545 backslash-escapes (\n, \,, \;, \\) and collapses semicolons and newlines into comma-separated inline text.
This commit is contained in:
@@ -25,3 +25,25 @@ export function esc(str) {
|
|||||||
if (str == null) return '';
|
if (str == null) return '';
|
||||||
return String(str).replace(ESCAPE_RE, (ch) => ESCAPE_MAP[ch]);
|
return String(str).replace(ESCAPE_RE, (ch) => ESCAPE_MAP[ch]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalisiert einen iCalendar LOCATION-String fuer die Anzeige.
|
||||||
|
* Entfernt ICS-Backslash-Escapes (RFC 5545 §3.3.11) und fasst
|
||||||
|
* mehrzeilige Adressen zu einem einzeiligen String zusammen.
|
||||||
|
*
|
||||||
|
* @param {string|null|undefined} raw
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
export function fmtLocation(raw) {
|
||||||
|
if (!raw) return '';
|
||||||
|
return raw
|
||||||
|
.replace(/\\[Nn]/g, '\n') // \n / \N → newline
|
||||||
|
.replace(/\\,/g, ',') // \, → ,
|
||||||
|
.replace(/\\;/g, ';') // \; → ;
|
||||||
|
.replace(/\\\\/g, '\\') // \\ → \
|
||||||
|
.replace(/[\n\r;]+/g, ', ') // newlines / semicolons → ", "
|
||||||
|
.replace(/\s*,\s*/g, ', ') // normalize spaces around commas
|
||||||
|
.replace(/(?:,\s*){2,}/g, ', ') // collapse double commas
|
||||||
|
.replace(/ +/g, ' ')
|
||||||
|
.replace(/^[,\s]+|[,\s]+$/g, ''); // trim leading/trailing commas
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user