cwlsn / ics-to-json Goto Github PK
View Code? Open in Web Editor NEW๐ Convert ICS calendars (eg. Google Calendar) to an opinionated JSON format.
๐ Convert ICS calendars (eg. Google Calendar) to an opinionated JSON format.
DTSTART;TZID=America/New_York:20130802T200000
DTEND;TZID=America/New_York:20130802T203000
is converted to
startDate: '20130802T200000',
endDate: '20130802T203000',
This datetime conversion:
new Date('20130802T200000')
gives Invalid Date
A better format might be: DTSTART;TZID=America/New_York:20130802T200000
is converted to
dtstart: {
original: "20130802T200000",
tzid: "America/New_York",
toISOString: "2019-08-06T08:58:13.614Z" // time is just an example
}```
* consider to preserve the original key name "DTSTART/dtstart" -> there is no reason to change all of them
* in any startDate is not a correct translation, because the key includes a time
Required for #8
Thanks for this easy to use utility function. I was able to successful incorporate it into my project to parse ics type files. I found one minor issue when using it. I had several files to parse and the array being returned with the JSON data was not cleared between calls so I needed to manually " clear the array after each call as follows
xs.length=0;
For your reference below is a segment of the actual chain of promises ( icsParser.default(xxx) is the call to your utility function)
icsParser.default(val1).then((xs:IIcsCalendarEvent[]) => {
evnts1=xs.map(x=>self.createCustomEvent(x,colors.blue));
xs.length=0; // code I needed to add to flush the array before the next call
return "astring";
}).then(parm1=>{
icsParser.default(val2).then((xs:IIcsCalendarEvent[]) => {
let evnts2=xs.map(x=>self.createCustomEvent(x,colors.yellow));
xs.length=0; // code I needed to add to flush the array before the next call
self.evnts=evnts1.concat(evnts2);
return "astring";
}).then(....```
Here is an axample of a valid value with spans two lines:
SUMMARY:Summer Kickball -
THURSDAY - 30 TEAMS
Any line which begins with a tab character should be concatenated onto the previous line. Currently only the first line is parsed and any preceding lines (beginning with tab characters) are ignored.
A simple solution is to just remove any newlines followed by a tab character.
icsData=icsData.replace(/(\r\n|\n|\r)\t/g, "");
Does this library support recurrent events? How does it manage them? Does it create more elements in the array? How about the recurrent events that never finishes? It cannot create infinite many events.
Here is the docs for the standard.
https://icalendar.org/iCalendar-RFC-5545/3-8-5-3-recurrence-rule.html
The current usage example requires support for import and includes a fetch, both of which do not work in all environments where this js package might be used.
A simpler example might be:
const icsToJson = require('ics-to-json').default
console.log(icsToJson(`
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT
SUMMARY:Access-A-Ride Pickup
DTSTART;TZID=America/New_York:20130802T103400
DTEND;TZID=America/New_York:20130802T110400
LOCATION:1000 Broadway Ave.\, Brooklyn
DESCRIPTION: Access-A-Ride trip to 900 Jay St.\, Brooklyn
STATUS:CONFIRMED
SEQUENCE:3
BEGIN:VALARM
TRIGGER:-PT10M
DESCRIPTION:Pickup Reminder
ACTION:DISPLAY
END:VALARM
END:VEVENT
BEGIN:VEVENT
SUMMARY:Access-A-Ride Pickup
DTSTART;TZID=America/New_York:20130802T200000
DTEND;TZID=America/New_York:20130802T203000
LOCATION:900 Jay St.\, Brooklyn
DESCRIPTION: Access-A-Ride trip to 1000 Broadway Ave.\, Brooklyn
STATUS:CONFIRMED
SEQUENCE:3
BEGIN:VALARM
TRIGGER:-PT10M
DESCRIPTION:Pickup Reminder
ACTION:DISPLAY
END:VALARM
END:VEVENT
END:VCALENDAR
`))
Result:
[ { summary: 'Access-A-Ride Pickup',
startDate: '20130802T103400',
endDate: '20130802T110400',
location: '1000 Broadway Ave., Brooklyn',
description: 'Access-A-Ride trip to 900 Jay St., Brooklyn' },
{ summary: 'Access-A-Ride Pickup',
startDate: '20130802T200000',
endDate: '20130802T203000',
location: '900 Jay St., Brooklyn',
description: 'Access-A-Ride trip to 1000 Broadway Ave., Brooklyn' } ]
The following is a valid description.
DESCRIPTION:Join us at the event! RSVP Here: https://example.com
Currently, the description will be parsed only up to the second colon, i.e. "Join us at the event! RSVP Here"
A solution is to us regex to split the string rather than splitting on any colon character.
const lineData = line.split(/:(.*)/);
const icsToJson = require('ics-to-json').default
icsToJson()
gives
TypeError: Cannot read property 'split' of undefined
at icsToJson (/home/runner/node_modules/ics-to-json/dist.js:32:23)
instead of something like "ics-to-json/icsToJson requires one string argument, no arguments where provided".
As per the comment in the readme/on https://www.npmjs.com/package/ics-to-json
The ability to do this necessarily implies the other upcoming feature: Include the rest of the keys from the ICS format
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.