Skip to content

Commit

Permalink
Merge pull request #142 from Neuvernetzung/feat#141
Browse files Browse the repository at this point in the history
Dont fold lines twice on generateCalendar #141
  • Loading branch information
timheerwagen authored Jan 20, 2025
2 parents 82fe706 + 9340426 commit 4d10168
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/twelve-seals-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ts-ics": patch
---

Dont fold lines twice on generateCalendar #141
2 changes: 1 addition & 1 deletion packages/ts-ics/src/lib/generate/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const generateIcsCalendar = (calendar: VCalendar) => {

if (calendar.events && calendar.events.length > 0) {
calendar.events.forEach((event) => {
icsString += generateIcsEvent(event);
icsString += generateIcsEvent(event, { skipFormatLines: true });
});
}

Expand Down
9 changes: 8 additions & 1 deletion packages/ts-ics/src/lib/generate/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ import { getKeys } from "./utils/getKeys";
import { formatLines } from "./utils/formatLines";
import { escapeTextString } from "./utils/escapeText";

export const generateIcsEvent = (event: VEvent) => {
type GenerateIcsEventOptions = { skipFormatLines?: boolean };

export const generateIcsEvent = (
event: VEvent,
options?: GenerateIcsEventOptions
) => {
const eventKeys = getKeys(event);

let icsString = "";
Expand Down Expand Up @@ -108,5 +113,7 @@ export const generateIcsEvent = (event: VEvent) => {

icsString += getIcsEndLine("VEVENT");

if (options?.skipFormatLines) return icsString;

return formatLines(icsString);
};
32 changes: 32 additions & 0 deletions packages/ts-ics/tests/generate/calendar.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { CRLF_BREAK } from "@/constants";
import { generateIcsCalendar } from "@/lib";
import type { VCalendar, VEvent } from "@/types";

it("Long descriptions are correctly folded - gh#141", async () => {
const date = new Date(2025, 0, 19);

const event: VEvent = {
start: { date },
stamp: { date },
end: { date },
summary: "Title",
uid: "1",
description:
"WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
};

const calendar: VCalendar = {
prodId: "1",
version: "2.0",
events: [event],
};

const icsCalendar = generateIcsCalendar(calendar);

expect(icsCalendar.includes(` W${CRLF_BREAK}`)).toBeFalsy(); // Calendar should not be folded again after it was folded already in generateEvent
expect(
icsCalendar.includes(
`DESCRIPTION:WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW${CRLF_BREAK} WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW${CRLF_BREAK} WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW${CRLF_BREAK}`
)
).toBeTruthy();
});

0 comments on commit 4d10168

Please sign in to comment.