diff --git a/package.json b/package.json index cffeb67a..846d4fff 100644 --- a/package.json +++ b/package.json @@ -117,6 +117,9 @@ "iarna-toml-esm": "^3.0.5", "ibantools": "^4.3.3", "js-base64": "^3.7.7", + "ical-generator": "^8.0.0", + "ical.js": "^2.1.0", + "js-base64": "^3.7.6", "json5": "^2.2.3", "jwt-decode": "^3.1.2", "libphonenumber-js": "^1.10.28", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cdf32cab..96875535 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -212,6 +212,12 @@ dependencies: ibantools: specifier: ^4.3.3 version: 4.3.3 + ical-generator: + specifier: ^8.0.0 + version: 8.0.1(@types/luxon@3.4.2)(@types/node@18.15.11)(luxon@3.5.0) + ical.js: + specifier: ^2.1.0 + version: 2.1.0 iconv-lite: specifier: ^0.6.3 version: 0.6.3 @@ -219,7 +225,7 @@ dependencies: specifier: ^3.1.3 version: 3.1.3 js-base64: - specifier: ^3.7.7 + specifier: ^3.7.6 version: 3.7.7 jsbarcode: specifier: ^3.11.6 @@ -3612,7 +3618,6 @@ packages: /@types/node@18.15.11: resolution: {integrity: sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==} - dev: true /@types/node@18.18.8: resolution: {integrity: sha512-OLGBaaK5V3VRBS1bAkMVP2/W9B+H8meUfl866OrMNQqt7wDgdpWPp5o6gmIc9pB+lIQHSq4ZL8ypeH1vPxcPaQ==} @@ -7392,6 +7397,49 @@ packages: resolution: {integrity: sha512-RUTlGuFj3cU/Qfu5YIrsIZjW34/VDgKOz5fDr64Mc4NWP9b2i48vQ39r5xCl1yyFQeyEG/lASstIQHAUX18rRA==} dev: false + /ical-generator@8.0.1(@types/luxon@3.4.2)(@types/node@18.15.11)(luxon@3.5.0): + resolution: {integrity: sha512-D7D0HPdjg8dEVTyN3QM95sioJj5/6TPj9wetrpt16tzszVgTIXHSSlreTsLuSSQpF61EdVxxTwYS9TVWr7vF0g==} + engines: {node: 18 || 20 || >=22.0.0} + peerDependencies: + '@touch4it/ical-timezones': '>=1.6.0' + '@types/luxon': '>= 1.26.0' + '@types/mocha': '>= 8.2.1' + '@types/node': '*' + dayjs: '>= 1.10.0' + luxon: '>= 1.26.0' + moment: '>= 2.29.0' + moment-timezone: '>= 0.5.33' + rrule: '>= 2.6.8' + peerDependenciesMeta: + '@touch4it/ical-timezones': + optional: true + '@types/luxon': + optional: true + '@types/mocha': + optional: true + '@types/node': + optional: true + dayjs: + optional: true + luxon: + optional: true + moment: + optional: true + moment-timezone: + optional: true + rrule: + optional: true + dependencies: + '@types/luxon': 3.4.2 + '@types/node': 18.15.11 + luxon: 3.5.0 + uuid-random: 1.3.2 + dev: false + + /ical.js@2.1.0: + resolution: {integrity: sha512-BOVfrH55xQ6kpS3muGvIXIg2l7p+eoe12/oS7R5yrO3TL/j/bLsR0PR+tYQESFbyTbvGgPHn9zQ6tI4FWyuSaQ==} + dev: false + /iconv-lite@0.6.3: resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==} engines: {node: '>=0.10.0'} @@ -10937,6 +10985,10 @@ packages: which-typed-array: 1.1.13 dev: true + /uuid-random@1.3.2: + resolution: {integrity: sha512-UOzej0Le/UgkbWEO8flm+0y+G+ljUon1QWTEZOq1rnMAsxo2+SckbiZdKzAHHlVh6gJqI1TjC/xwgR50MuCrBQ==} + dev: false + /uuid@10.0.0: resolution: {integrity: sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==} hasBin: true diff --git a/src/tools/ical-generator/ical-generator.vue b/src/tools/ical-generator/ical-generator.vue new file mode 100644 index 00000000..942df575 --- /dev/null +++ b/src/tools/ical-generator/ical-generator.vue @@ -0,0 +1,127 @@ + + + diff --git a/src/tools/ical-generator/index.ts b/src/tools/ical-generator/index.ts new file mode 100644 index 00000000..ef5bbc4c --- /dev/null +++ b/src/tools/ical-generator/index.ts @@ -0,0 +1,12 @@ +import { CalendarEvent } from '@vicons/tabler'; +import { defineTool } from '../tool'; + +export const tool = defineTool({ + name: 'ICAL Generator', + path: '/ical-generator', + description: 'Generate ICAL/ICS file from event infos', + keywords: ['ical', 'calendar', 'event', 'generator'], + component: () => import('./ical-generator.vue'), + icon: CalendarEvent, + createdAt: new Date('2024-08-15'), +}); diff --git a/src/tools/ical-merger/ical-merger.service.test.ts b/src/tools/ical-merger/ical-merger.service.test.ts new file mode 100644 index 00000000..6727aeb0 --- /dev/null +++ b/src/tools/ical-merger/ical-merger.service.test.ts @@ -0,0 +1,82 @@ +import { describe, expect, it } from 'vitest'; +import { mergeIcals } from './ical-merger.service'; + +describe('ical-merger', () => { + describe('mergeIcals', () => { + it('merge correctly', () => { + expect(mergeIcals([ +`BEGIN:VCALENDAR +PRODID:-//xyz Corp//NONSGML PDA Calendar Version 1.0//EN +VERSION:2.0 +BEGIN:VEVENT +DTSTAMP:19960704T120000Z +UID:uid1@example.com +ORGANIZER:mailto:jsmith@example.com +DTSTART:19960918T143000Z +DTEND:19960920T220000Z +STATUS:CONFIRMED +CATEGORIES:CONFERENCE +SUMMARY:Networld+Interop Conference +DESCRIPTION:Networld+Interop Conference + and Exhibit\\nAtlanta World Congress Center\\n + Atlanta\\, Georgia +END:VEVENT +END:VCALENDAR`, + `BEGIN:VCALENDAR +METHOD:xyz +VERSION:2.0 +PRODID:-//ABC Corporation//NONSGML My Product//EN +BEGIN:VEVENT +DTSTAMP:19970324T120000Z +SEQUENCE:0 +UID:uid3@example.com +ORGANIZER:mailto:jdoe@example.com +ATTENDEE;RSVP=TRUE:mailto:jsmith@example.com +DTSTART:19970324T123000Z +DTEND:19970324T210000Z +CATEGORIES:MEETING,PROJECT +CLASS:PUBLIC +SUMMARY:Calendaring Interoperability Planning Meeting +DESCRIPTION:Discuss how we can test c&s interoperability\\n + using iCalendar and other IETF standards. +LOCATION:LDB Lobby +ATTACH;FMTTYPE=application/postscript:ftp://example.com/pub/ + conf/bkgrnd.ps +END:VEVENT +END:VCALENDAR`, + ])).to.eq( +`BEGIN:VCALENDAR +PRODID:it-tools-ical-merger +VERSION:1.0 +BEGIN:VEVENT +DTSTAMP:19960704T120000Z +UID:uid1@example.com +ORGANIZER:mailto:jsmith@example.com +DTSTART:19960918T143000Z +DTEND:19960920T220000Z +STATUS:CONFIRMED +CATEGORIES:CONFERENCE +SUMMARY:Networld+Interop Conference +DESCRIPTION:Networld+Interop Conference and Exhibit\\nAtlanta World Congress + Center\\nAtlanta\\, Georgia +END:VEVENT +BEGIN:VEVENT +DTSTAMP:19970324T120000Z +SEQUENCE:0 +UID:uid3@example.com +ORGANIZER:mailto:jdoe@example.com +ATTENDEE;RSVP=TRUE:mailto:jsmith@example.com +DTSTART:19970324T123000Z +DTEND:19970324T210000Z +CATEGORIES:MEETING,PROJECT +CLASS:PUBLIC +SUMMARY:Calendaring Interoperability Planning Meeting +DESCRIPTION:Discuss how we can test c&s interoperability\\nusing iCalendar a + nd other IETF standards. +LOCATION:LDB Lobby +ATTACH;FMTTYPE=application/postscript:ftp://example.com/pub/conf/bkgrnd.ps +END:VEVENT +END:VCALENDAR`.replace(/\n/g, '\r\n')); + }); + }); +}); diff --git a/src/tools/ical-merger/ical-merger.service.ts b/src/tools/ical-merger/ical-merger.service.ts new file mode 100644 index 00000000..95a774b4 --- /dev/null +++ b/src/tools/ical-merger/ical-merger.service.ts @@ -0,0 +1,45 @@ +import ICAL from 'ical.js'; + +export function mergeIcals(inputs: Array, options: { + calname?: string + timezone?: string + caldesc?: string +} = {}) { + let calendar; + for (const input of inputs) { + try { + const jcal = ICAL.parse(input); + const cal = new ICAL.Component(jcal); + + if (!calendar) { + calendar = cal; + calendar.updatePropertyWithValue('prodid', 'it-tools-ical-merger'); + calendar.updatePropertyWithValue('version', '1.0'); + + if (options.calname) { + calendar.updatePropertyWithValue('x-wr-calname', options.calname); + } + if (options.timezone) { + calendar.updatePropertyWithValue('x-wr-timezone', options.timezone); + } + if (options.caldesc) { + calendar.updatePropertyWithValue('x-wr-caldesc', options.caldesc); + } + } + else { + for (const vevent of cal.getAllSubcomponents('vevent')) { + calendar.addSubcomponent(vevent); + } + } + } + catch (e) { + throw new Error(`Failed to merge: ${e}\n\nWith input: ${input}`); + } + } + + if (!calendar) { + throw new Error('No icals parsed successfully'); + } + + return calendar.toString(); +} diff --git a/src/tools/ical-merger/ical-merger.vue b/src/tools/ical-merger/ical-merger.vue new file mode 100644 index 00000000..23b9fd03 --- /dev/null +++ b/src/tools/ical-merger/ical-merger.vue @@ -0,0 +1,96 @@ + + + + + diff --git a/src/tools/ical-merger/index.ts b/src/tools/ical-merger/index.ts new file mode 100644 index 00000000..9bb8c232 --- /dev/null +++ b/src/tools/ical-merger/index.ts @@ -0,0 +1,12 @@ +import { CalendarPlus } from '@vicons/tabler'; +import { defineTool } from '../tool'; + +export const tool = defineTool({ + name: 'iCal Merger', + path: '/ical-merger', + description: 'Merge many iCal file to a single', + keywords: ['ical', 'ics', 'merger'], + component: () => import('./ical-merger.vue'), + icon: CalendarPlus, + createdAt: new Date('2024-08-15'), +}); diff --git a/src/tools/ical-parser/ical-parser.vue b/src/tools/ical-parser/ical-parser.vue new file mode 100644 index 00000000..236ddf74 --- /dev/null +++ b/src/tools/ical-parser/ical-parser.vue @@ -0,0 +1,96 @@ + + + + + diff --git a/src/tools/ical-parser/index.ts b/src/tools/ical-parser/index.ts new file mode 100644 index 00000000..58fdafcd --- /dev/null +++ b/src/tools/ical-parser/index.ts @@ -0,0 +1,12 @@ +import { CalendarEvent } from '@vicons/tabler'; +import { defineTool } from '../tool'; + +export const tool = defineTool({ + name: 'ICAL File Parser', + path: '/ical-parser', + description: 'Parse ICAL/ICS file to event display', + keywords: ['ical', 'ics', 'calendar', 'parser'], + component: () => import('./ical-parser.vue'), + icon: CalendarEvent, + createdAt: new Date('2024-08-15'), +}); diff --git a/src/tools/index.ts b/src/tools/index.ts index 4e1b049d..7ae29858 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -11,6 +11,7 @@ import { tool as emailParser } from './email-parser'; import { tool as outlookParser } from './outlook-parser'; import { tool as fileHasher } from './file-hasher'; import { tool as hexFileConverter } from './hex-file-converter'; +import { tool as icalMerger } from './ical-merger'; import { tool as cssXpathConverter } from './css-xpath-converter'; import { tool as cssSelectorsMemo } from './css-selectors-memo'; @@ -38,6 +39,8 @@ import { tool as durationCalculator } from './duration-calculator'; import { tool as folderStructureDiagram } from './folder-structure-diagram'; import { tool as hddCalculator } from './hdd-calculator'; import { tool as heicConverter } from './heic-converter'; +import { tool as icalParser } from './ical-parser'; +import { tool as icalGenerator } from './ical-generator'; import { tool as pdfSignatureChecker } from './pdf-signature-checker'; import { tool as numeronymGenerator } from './numeronym-generator'; import { tool as macAddressGenerator } from './mac-address-generator'; @@ -272,6 +275,9 @@ export const toolsByCategory: ToolCategory[] = [ asciiTextDrawer, pasteAsMarkdown, iso3166Searcher, + icalGenerator, + icalParser, + icalMerger, ], }, {