import { formatDate } from '../format'; function formatSummary(release, summaryFormat) { return summaryFormat .map((group) => ({ ...group, segments: group.segments .filter((segment) => { if (!release[segment.prop]) { return false; } if (Array.isArray(release[segment.prop]) && release[segment.prop].length === 0) { return false; } return true; }) .map((segment) => { if (Array.isArray(release[segment.prop])) { return release[segment.prop].join(segment.delimiter || ', '); } if (segment.prop === 'date') { return formatDate(release[segment.prop], segment.format || 'YYYY-MM-DD'); } return release[segment.prop]; }), })) .filter((group) => group.segments.length > 0) .map((group) => `${group.bracket?.[0] || ''}${group.segments.join(group.delimiter || ' - ')}${group.bracket?.[1] || ''}`) .join(' '); } export default formatSummary;