Giter VIP home page Giter VIP logo

ical2json's Introduction

ical2json

A simple node package to convert iCal data (.ics file) to JSON format

Tests codecov

Getting started

Download and install from npm

npm install -g ical2json

To convert ics file to json

$ ical2json ./US-Holiday.ics

The json output will be written to a .json file in the same directory

./US-Holiday.json

To write the output to a separate directory, use the -o or --output-dir option

$ ical2json --output-dir ~/destination/directory ./US-Holiday.ics

File output:

{
  "VCALENDAR": [
    {
      "PRODID": "-//Calendar Labs//Calendar 1.0//EN",
      "VERSION": "2.0",
      "CALSCALE": "GREGORIAN",
      "METHOD": "PUBLISH",
      "X-WR-CALNAME": "Usa Holidays",
      "X-WR-TIMEZONE": "America/New_York",
      "VEVENT": [
        {
          "DTSTART;VALUE=DATE": "20130101",
          "DTEND;VALUE=DATE": "20130102",
          "DTSTAMP": "20111213T124028Z",
          "UID": "[email protected]",
          "CREATED": "20111213T123901Z",
          "DESCRIPTION": "Visit http",
          "LAST-MODIFIED": "20111213T123901Z",
          "LOCATION": "",
          "SEQUENCE": "0",
          "STATUS": "CONFIRMED",
          "SUMMARY": "New Year's Day",
          "TRANSP": "TRANSPARENT"
        },
        {
          "DTSTART;VALUE=DATE": "20130121",
          "DTEND;VALUE=DATE": "20130122",
          "DTSTAMP": "20111213T124028Z",
          "UID": "[email protected]",
          "CREATED": "20111213T123901Z",
          "DESCRIPTION": "Visit http",
          "LAST-MODIFIED": "20111213T123901Z",
          "LOCATION": "",
          "SEQUENCE": "0",
          "STATUS": "CONFIRMED",
          "SUMMARY": "M L King Day",
          "TRANSP": "TRANSPARENT"
        },
        {
          "DTSTART;VALUE=DATE": "20130214",
          "DTEND;VALUE=DATE": "20130215",
          "DTSTAMP": "20111213T124028Z",
          "UID": "[email protected]",
          "CREATED": "20111213T123901Z",
          "DESCRIPTION": "Visit http",
          "LAST-MODIFIED": "20111213T123901Z",
          "LOCATION": "",
          "SEQUENCE": "0",
          "STATUS": "CONFIRMED",
          "SUMMARY": "Valentine's Day",
          "TRANSP": "TRANSPARENT"
        }
      ]
    }
  ]
}

API

  Usage: ical2json [options] [FILES...]

  Options:
    -V, --version            output the version number
    -r, --revert             Revert JSON to ical
    -o, --output-dir <path>  Output directory
    -h, --help               display help for command

Programmatic API

var ical2json = require("ical2json");

// From ical to JSON
var output = ical2json.convert(icalData);

// From JSON to ical
var icalOutput = ical2json.revert(icalJson);

ical2json's People

Contributors

adrianlee44 avatar dependabot[bot] avatar ericlathrop avatar greenkeeper[bot] avatar jveldridge avatar lu-ks avatar sujaykathrotia 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  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  avatar

ical2json's Issues

Missing declaration file ical2json.d.ts in published NPM package?

I'm curious as to why the build/ical2json.d.ts isn't part of the published npm package for ical2json?

I realize your primary focus is having this as a stand-alone CLI (which works great, btw), but in my particular TypeScript project, I'm getting error ts(7016) Could not find a declaration file. It's probably popping up on my radar in part due to my tsconfig requirements, but with your package.json being explicit on the types, I would have thought that the file should be exported as part of the published npm package.

image

Attachments issue

It seems that the attachment XML is formed strangely, along the lines of:

ATTACH;VALUE=URI;FILENAME=example.jpg;FMTTYPE=image/jpeg;
 MANAGED-ID=123123123:https:
 //p47-caldav.icloud.com/long/path/to/example.jpg

So in JSON, the attachment is getting pulled into whatever field precedes it:

"SUMMARY": "Example summaryMANAGED-ID=123123123:https://p47-caldav.icloud.com/long/path/to/example.jpg

(This is occurring with an ics file downloaded from a shared apple calendar)

Cannot find module './utils'

I was using this tool successfully for quite a while. I made a script which automatically installs it in my docker container during start-up. However, since I upgraded my docker container to the latest openHAB4.2, I get following error when running ical2json.

Any tips how I can resolve that?

`
node:internal/modules/cjs/loader:1148
throw err;
^

Error: Cannot find module './utils'
Require stack:

  • /usr/lib/node_modules/ical2json/build/cli.js
  • /usr/lib/node_modules/ical2json/bin/ical2json
    at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
    at Module._load (node:internal/modules/cjs/loader:986:27)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at require (node:internal/modules/helpers:179:18)
    at Object. (/usr/lib/node_modules/ical2json/build/cli.js:29:17)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Module._load (node:internal/modules/cjs/loader:1024:12)
    at Module.require (node:internal/modules/cjs/loader:1233:19) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [
    '/usr/lib/node_modules/ical2json/build/cli.js',
    '/usr/lib/node_modules/ical2json/bin/ical2json'
    ]
    }

Node.js v20.15.1
`

React Native

Will this module work with RN? I imported it and I am getting the error:

"Unable to resolve module pathfrom/Users/user/Desktop/CGPSApp/node_modules/ical2json/index.js: Module does not exist in the module map

The module is clearly located at this path on my file system.

not reading VEVENTs

input:

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Teamup Solutions AG//Teamup Calendar//EN
METHOD:PUBLISH
X-WR-CALNAME:test calendar | Team member 2
X-WR-CALDESC:Team Member 2-2995801
X-PUBLISHED-TTL:PT15M
BEGIN:VTIMEZONE
TZID:Asia/Shanghai
TZURL:http://tzurl.org/zoneinfo-outlook/Asia/Shanghai
X-LIC-LOCATION:Asia/Shanghai
BEGIN:STANDARD
TZOFFSETFROM:+0800
TZOFFSETTO:+0800
TZNAME:CST
DTSTART:19700101T000000
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
UID:TU86734693
DTSTART;TZID=Asia/Shanghai:20170322T100000
SEQUENCE:0
TRANSP:OPAQUE
DTEND;TZID=Asia/Shanghai:20170322T110000
URL:https://teamup.com/event/show/key/etc
LOCATION:Not sure where
SUMMARY:Testing event
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=OPT-PARTICIPANT;PARTSTAT=ACCEPTED;CN=Happy 
 People;X-NUM-GUESTS=0:Happy People
CLASS:PUBLIC
DESCRIPTION:this is an ok event\, don't think to much
CATEGORIES:Team member 2
DTSTAMP:20170321T163132Z
CREATED:20170321T082755Z
LAST-MODIFIED:20170321T092344Z
X-TEAMUP-WHO:Happy People
END:VEVENT
BEGIN:VEVENT
UID:TU86929503
DTSTART;TZID=Asia/Shanghai:20170323T110000
SEQUENCE:0
TRANSP:OPAQUE
DTEND;TZID=Asia/Shanghai:20170323T120000
URL:https://teamup.com/event/show/key/etc
SUMMARY:test2
CLASS:PUBLIC
CATEGORIES:Team member 2
DTSTAMP:20170321T163132Z
CREATED:20170321T163118Z
END:VEVENT
END:VCALENDAR

output:

{
  "VCALENDAR": [
    {
      "VERSION": "2.0",
      "PRODID": "-//Teamup Solutions AG//Teamup Calendar//EN",
      "METHOD": "PUBLISH",
      "X-WR-CALNAME": "test calendar | Team member 2",
      "X-WR-CALDESC": "Team Member 2-2995801",
      "X-PUBLISHED-TTL": "PT15M",
      "VTIMEZONE": [
        {
          "TZID": "Asia/Shanghai",
          "TZURL": "http://tzurl.org/zoneinfo-outlook/Asia/Shanghai",
          "X-LIC-LOCATION": "Asia/Shanghai",
          "STANDARD": [
            {
              "TZOFFSETFROM": "+0800",
              "TZOFFSETTO": "+0800",
              "TZNAME": "CST",
              "DTSTART": "19700101T000000"
            }
          ]
        }
      ]
    }
  ]
}

Extra backslash being added everywhere.

The iCal file I am reading is escaping comma's, for instance \, and when that goes through ical2jasn it adds another backslash \\,. This extra backslash is undesirable.

Failing to parse extended TZID data

There is an TZID property in some calendars that makes the parser go haywire.
https://tools.ietf.org/html/rfc5545

BEGIN:VEVENT
UID:qTJ-3n1sAUwFl
SUMMARY:Luleå Hockey - Örebro Hockey 4 - 3 SO
DESCRIPTION:
LOCATION:Coop Norrbotten Arena
DTSTART;TZID="+02:00":20170916T180000
DTEND;TZID=Europe/Stockholm:20170916T203000
URL:http://biljett.luleahockey.se/Home/tickets/273/False?style=shl
GEO:65.597807;22.148331
END:VEVENT
{
  UID: 'qTJ-3n1sAUwFl',
  SUMMARY: 'Luleå Hockey - Örebro Hockey 4 - 3 SO',
  DESCRIPTION: '',
  LOCATION: 'Coop Norrbotten Arena',
  'DTSTART;TZID="+02': '00":20170916T180000',
  'DTEND;TZID=Europe/Stockholm': '20170916T203000',
  URL: 'http://biljett.luleahockey.se/Home/tickets/273/False?style=shl',
  GEO: '65.597807;22.148331'
}

no output

I followed the instructions and installed ical2json without errors.

When I run ical2json [filename] > c:/output.txt, the program runs without error and the output file is created, but it is empty. I am certain I have the proper path to my ics file and I know it has data in it.

Why is nothing happening?

Support client-side conversion

It would be cool if this library support browser usage. I've tried mocking this up for myself by taking the convert function out of index.js and removing all of the node specific code (eg fs etc), I find that it works like a charm. While this copy-pasta solution works for my use case, it would be particularly cool if this functionality was supported right out of the box.

Thanks for making this nice library!

NEW_LINE

NEW_LINE should read /\r\n?/ instead of /\n\r?/. Not sure if the "?" is necessary though.

No file produced on Raspberry Pi 3 B+

Hi there,

When I run the program to convert .ics to .json on my RPI, I get no json file, no error message, the console just starts a new line after a second or two.

If I just type in ical2json, the usage info comes up.

Any ideas what's going on?

Thanks,
Will

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.