/** * @copyright Copyright (c) 2021 Richard Steinmetz * * @author Richard Steinmetz * * @license AGPL-3.0-or-later * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * */ /** * Remove the mailto prefix from a URI and return it * * @param {string} uri URI to remove the prefix from * @return {string} URI without a mailto prefix */ export function removeMailtoPrefix(uri) { if (typeof uri !== 'string') { return '' } if (uri.startsWith('mailto:')) { return uri.slice(7) } return uri } /** * Add the mailto prefix to a URI if it doesn't have one yet and return it * * @param {string} uri URI to add the prefix to * @return {string} URI with a mailto prefix */ export function addMailtoPrefix(uri) { if (typeof uri !== 'string') { return 'mailto:' } if (uri.startsWith('mailto:')) { return uri } return `mailto:${uri}` } /** * Get the display name of an organizer * * @param {?object} organizer Organizer object to extract a display name from * @return {string} Display name of given organizer */ export function organizerDisplayName(organizer) { if (!organizer) { return '' } if (organizer.commonName) { return organizer.commonName } return removeMailtoPrefix(organizer.uri) }