Giter Site home page Giter Site logo

ics-to-json's People

Contributors

cwlsn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ics-to-json's Issues

Convert timezone/location/time information

DTSTART;TZID=America/New_York:20130802T200000
DTEND;TZID=America/New_York:20130802T203000

is converted to

    startDate: '20130802T200000',
    endDate: '20130802T203000',

This datetime conversion:

  • is not ready for being used in js (e.g. converted to Date): new Date('20130802T200000') gives Invalid Date
  • loses the timezone information (TZID)

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

Array needs to be reset after each call

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(....```

Support values which span multiple lines

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, "");

Improve usage example

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' } ]

Support values which contain colon characters

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(/:(.*)/);

Improve error reporting for wrong usage

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".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.