Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
ical.js is a JavaScript library for parsing and manipulating iCalendar data. It allows you to create, parse, and manipulate iCalendar files, which are commonly used for calendar events and scheduling.
Parsing iCalendar Data
This feature allows you to parse iCalendar data from a string and extract information from it. In this example, we parse an iCalendar string and extract the summary of the first event.
const ICAL = require('ical.js');
const icalData = 'BEGIN:VCALENDAR\nVERSION:2.0\nBEGIN:VEVENT\nSUMMARY:Test Event\nDTSTART:20230301T120000Z\nDTEND:20230301T130000Z\nEND:VEVENT\nEND:VCALENDAR';
const jcalData = ICAL.parse(icalData);
const comp = new ICAL.Component(jcalData);
const vevent = comp.getFirstSubcomponent('vevent');
const summary = vevent.getFirstPropertyValue('summary');
console.log(summary); // Output: Test Event
Creating iCalendar Data
This feature allows you to create iCalendar data programmatically. In this example, we create a new event with a summary, start time, and end time, and then convert it to an iCalendar string.
const ICAL = require('ical.js');
const event = new ICAL.Component(['vcalendar', [], [
['vevent', [], [
['summary', {}, 'text', 'New Event'],
['dtstart', {}, 'date-time', '20230301T120000Z'],
['dtend', {}, 'date-time', '20230301T130000Z']
]]
]]);
const icalString = event.toString();
console.log(icalString);
Manipulating iCalendar Data
This feature allows you to manipulate existing iCalendar data. In this example, we parse an iCalendar string, update the summary of the first event, and then convert it back to an iCalendar string.
const ICAL = require('ical.js');
const icalData = 'BEGIN:VCALENDAR\nVERSION:2.0\nBEGIN:VEVENT\nSUMMARY:Test Event\nDTSTART:20230301T120000Z\nDTEND:20230301T130000Z\nEND:VEVENT\nEND:VCALENDAR';
const jcalData = ICAL.parse(icalData);
const comp = new ICAL.Component(jcalData);
const vevent = comp.getFirstSubcomponent('vevent');
vevent.updatePropertyWithValue('summary', 'Updated Event');
const updatedIcalString = comp.toString();
console.log(updatedIcalString);
The 'ical' package is a lightweight iCalendar parser for Node.js. It focuses on parsing iCalendar data and extracting information from it. Compared to ical.js, it is simpler and more focused on parsing rather than creating or manipulating iCalendar data.
The 'node-ical' package is a comprehensive iCalendar library for Node.js. It supports parsing, creating, and manipulating iCalendar data. It is similar to ical.js in terms of functionality but is designed specifically for Node.js environments.
The 'ical-generator' package is a library for generating iCalendar files in Node.js. It focuses on creating iCalendar data programmatically. Compared to ical.js, it is more specialized in generating iCalendar data rather than parsing or manipulating existing data.
This is a library to parse the formats defined in the following rfcs and their extensions:
The initial goal was to use it as a replacement for libical in the Mozilla Calendar Project, but the library has been written with the web in mind. This library enables you to do all sorts of cool experiments with calendar data and the web. Most algorithms here were taken from libical. If you are bugfixing this library, please check if the fix can be upstreamed to libical.
If you want to try out ICAL.js right now, there is a jsfiddle set up and ready to use.
The ICAL validator demonstrates how to use the library in a webpage, and helps verify iCalendar and jCal. Try the validator online
The recurrence tester calculates occurrences based on a RRULE. It can be used to aid in creating test cases for the recurrence iterator. Try the recurrence tester online.
ICAL.js has no dependencies and is written in modern JavaScript. You can install ICAL.js via npm, if you would like to use it in Node.js:
npm install ical.js
Then simply import it for use:
import ICAL from "ical.js";
If you are working with a browser, be aware this is an ES6 module:
<script type="module">
import ICAL from "https://unpkg.com/ical.js/dist/ical.min.js";
document.querySelector("button").addEventListener("click", () => {
ICAL.parse(document.getElementById("txt").value);
});
</script>
If you need to make use of a script tag, you can use the transpiled ES5 version:
<script src="https://unpkg.com/ical.js/dist/ical.es5.min.cjs"></script>
<textarea id="txt"></textarea>
<button onclick="ICAL.parse(document.getElementById('txt').value)"></button>
The browser examples above use the minified versions of the library, which is probably what you want. However, there are also unminified versions of ICAL.js available on unpkg.
https://unpkg.com/ical.js/dist/ical.js
https://unpkg.com/ical.js/dist/ical.es5.cjs
The stock ical.js does not register any timezones, due to the additional size it brings. If you'd
like to do timezone conversion, and the timezone definitions are not included in the respective ics
files, you'll need to use ical.timezones.js
or its minified counterpart.
This file is not included in the distribution since it pulls in IANA timezones that might change regularly. See the github actions on building your own timezones during CI, or grab a recent build from main.
For a few guides with code samples, please check out the wiki. If you prefer, full API documentation is available here. If you are missing anything, please don't hesitate to create an issue.
To contribute to ICAL.js you need to set up the development environment. A simple npm install
will
get you set up. If you would like to help out and would like to discuss any API changes, please feel
free to create an issue.
The following test suites are available
npm run test-unit # Node unit tests
npm run test-acceptance # Node acceptance tests
npm run test-performance # Performance comparison tests
npm run test-browser # Browser unit and acceptance tests
npm run test # Node unit and acceptance tests (This is fast and covers most aspects)
npm run test-all # All of the above
See the wiki for more details.
Code coverage is automatically generated for the node unit tests. You can view the coverage results online, or run them locally to make sure new code is covered.
To make sure all ICAL.js code uses a common style, please run the linters using npm run lint
.
Please make sure you fix any issues shown by this command before sending a pull request.
You can generate the documentation locally, this is also helpful to ensure the jsdoc you have
written is valid. To do so, run npm run jsdoc
. You will find the output in the docs/api/
subdirectory.
When you are done with your work, you can run npm run build
to create the single-file build for
use in the browser, including its minified counterpart and the source map.
ical.js is licensed under the Mozilla Public License, version 2.0.
FAQs
Javascript parser for ics (rfc5545) and vcard (rfc6350) data
The npm package ical.js receives a total of 97,118 weekly downloads. As such, ical.js popularity was classified as popular.
We found that ical.js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.