Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @types/node-ical #98

Open
wants to merge 100 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
03723bf
Update ical.js: handle quoted param values
jjd314 May 22, 2014
f7c7dd2
Support exdates by returning an array with the parsed object.
jfrumar Aug 4, 2014
277579b
Only set timezone if we have a valid parsed date.
jfrumar Aug 4, 2014
97cd72e
Index VEVENTs by a guid instead of the external UID (which can isn't …
jfrumar Aug 7, 2014
7323815
Merge remote-tracking branch 'upstream/master'
jfrumar Oct 27, 2014
6470cca
Fix missing comma in package.json, and fix broken test.
jfrumar Oct 27, 2014
2521065
Return a date object even when there's no time value
jfrumar Feb 6, 2015
1aab437
Support importing dates that don't have a time component.
jfrumar Feb 6, 2015
c299840
changeѕ to get stuff personalized.
jens-maus Feb 17, 2017
8d9ed42
[++] parse same keys to an array / [fix] parseParams
tenbits Mar 6, 2014
f7eb9de
See peterbraden#46 version to 0.3.0
chernjie Sep 3, 2014
caf6d6f
fix tests
peterbraden Sep 3, 2014
4e205f0
bump
peterbraden Sep 3, 2014
4e8769e
travis node version
peterbraden Sep 3, 2014
f7dae87
no dev
peterbraden Sep 3, 2014
23e2a2f
Fixed #45: RRule doesn't honor start date
Sep 13, 2014
992ae19
bump master
peterbraden Apr 16, 2015
ed309cf
Document API fully
takkaria May 29, 2015
c939c89
Fix undefined 'cur' variable'
Jun 4, 2015
1408a10
Specify dtstart for rrule when dtstart comes later
ericlathrop Jul 2, 2015
ff5bf81
Preventing parsing from failing when not provided FREEBUSY dates
ndaversa Mar 9, 2016
81f8ad8
Fix Issue #58
nhubbard Apr 13, 2016
7ea2293
Add multiple versions to test on Travis
nhubbard Apr 13, 2016
16f3e50
Update Travis to remove Node 5
nhubbard Apr 13, 2016
d7227cf
0.5.0
peterbraden Apr 14, 2016
464052a
Fix #56 for categories in multiple lines
Apr 15, 2016
0517290
Fix 8 digit start dates.
MichMich Apr 23, 2016
78a82b8
Fix javascript month issue.
MichMich May 3, 2016
102a755
Fixes for Recurrence Rules
mbalfour Jul 16, 2016
6cb0d03
Added tests and maintained old code
mbalfour Jul 19, 2016
3b61793
Fix RECURRENCE-ID appearing before RRULE
mbalfour Sep 17, 2016
6b869df
Changed test to use a static IP address
mbalfour Sep 17, 2016
0dd5b49
Fixed the dates in the test
mbalfour Sep 17, 2016
2d88b05
Update request to 2.75.0
Powersource Oct 21, 2016
37e119f
changeѕ to get stuff personalized.
jens-maus Feb 17, 2017
c49e02c
applied fix solving test problem with empty categories.
jens-maus Feb 17, 2017
4ab13e3
added test case for quoted parameters
jens-maus Feb 17, 2017
c684f95
Merge branch 'jjd314-patch-2'
jens-maus Feb 17, 2017
0eab7a3
revision bump to honour the integration of the first PR.
jens-maus Feb 17, 2017
5f38e51
Merge remote-tracking branch 'jfrumar/master' into jfrumar-master
jens-maus Feb 17, 2017
0db9274
Update README.md
jens-maus Feb 17, 2017
77effa2
Update README.md
jens-maus Feb 17, 2017
3d074c6
lets add TZID before VALUE=DATE because that can also happen here.
jens-maus Feb 17, 2017
c0b6374
Merge branch 'master' of https://github.com/jens-maus/node-ical
jens-maus Feb 17, 2017
7c34ea0
revision bump
jens-maus Feb 17, 2017
2de2359
added fix where ev.start/ev.end could be returned as strings rather t…
jens-maus Feb 17, 2017
d88830b
revision bump
jens-maus Feb 17, 2017
df35fff
added .npmignore
jens-maus Feb 17, 2017
73f9f10
revision bump
jens-maus Feb 17, 2017
bf03850
added example.js
jens-maus Feb 17, 2017
d1e8f1e
Add asynchronous processing of OCS data, Update travis-ci, dependencies
Apollon77 Apr 13, 2018
4ba6dd4
Merge remote-tracking branch 'upstream/master'
jens-maus Apr 13, 2018
34d7e9f
Merge branch 'master' into make-async-release
jens-maus Apr 13, 2018
308fabc
Merge pull request #1 from Apollon77/make-async-release
jens-maus Apr 13, 2018
b6382d4
0.6.1 with performance optimizations (#2)
Apollon77 Apr 14, 2018
cf636df
Merge pull request #2 from Apollon77/async-opt-release
jens-maus Apr 14, 2018
a059cd2
fix error in Apple calendars where dateParam returns a string and toI…
Apollon77 Jun 4, 2018
307f8e6
fix
Apollon77 Jun 4, 2018
d8f7cf0
update all deps, change to new uid module
Apollon77 Jun 4, 2018
70d8ffe
fix deps
Apollon77 Jun 4, 2018
b3c8f21
Merge pull request #3 from Apollon77/master
jens-maus Jun 4, 2018
bba1c39
correct datatype
twonky4 Oct 9, 2018
72cfac1
Add missing semicolon in example 1 in README.md
ohnx Oct 10, 2018
d8b04a7
Merge remote-tracking branch 'upstream/master'
jens-maus Oct 10, 2018
cb33afc
updated travis ci by adding nodejs 10 and removing obsolete nodejs 4 …
jens-maus Oct 10, 2018
cff402c
Merge pull request #5 from ohnx/patch-1
jens-maus Oct 10, 2018
aa82a3e
Merge pull request #4 from twonky4/patch-1
jens-maus Oct 10, 2018
2c4304e
just another datatype correction
twonky4 Oct 12, 2018
befb0a2
Merge pull request #6 from twonky4/patch-1
jens-maus Oct 12, 2018
c8bd9c6
ignore time if type is date; add date type info
twonky4 Nov 18, 2018
1744540
Merge pull request #7 from twonky4/master
jens-maus Nov 18, 2018
c01b4d8
adapted .npmignore
jens-maus Feb 16, 2019
7c5bbc1
add timezone support and equality test
sedenardi Mar 1, 2019
0f579fb
fix tests for other zoned dates
sedenardi Mar 1, 2019
5df6ef5
Merge pull request #8 from sedenardi/dev-tzid
jens-maus Mar 1, 2019
e8ff7f8
Merge branch 'master' of https://github.com/jens-maus/node-ical
jens-maus Mar 1, 2019
8f38951
Merge remote-tracking branch 'upstream/master'
jens-maus Mar 1, 2019
b92752b
fix async tests and bump version of node-ical
jens-maus Mar 1, 2019
988bfd8
Added ESLint and Prettier
Oct 5, 2019
b99683e
Removed React support from ESLint
Oct 5, 2019
d492338
Rewrote node-ical.js public functions.
Oct 5, 2019
e01aaaa
Added typing info and moving node-ical.js to index.js
Oct 5, 2019
4224ea9
Reformatted ical.js and set up APIs to be backwards-compatible
Oct 5, 2019
12c2802
All tests pass and all code is correctly formatted and compatible
Oct 5, 2019
b88eb5a
Improved JSDoc for iCalEvent
Oct 5, 2019
a115727
Rewrote README to fix typos and add new API info
Oct 5, 2019
dd7bdfe
Added support for ical.objectHandlers / ical.handleObject / ical.pars…
Oct 5, 2019
2a06778
Added and applied ESLint rule no-var
Oct 9, 2019
9baa905
Removed warning comments generated by not using let/const
Oct 9, 2019
d26d3a9
Merge pull request #9 from jackm-xyz/refactor
jens-maus Oct 14, 2019
54b28f8
lets travis check nodejs 12 compatibility as well.
jens-maus Oct 14, 2019
230d1fe
Merge remote-tracking branch 'upstream/master'
jens-maus Oct 14, 2019
3ce830d
version bump to 0.10.0 to reflect API changes.
jens-maus Oct 14, 2019
c51e857
Add dependency on request types
Oct 17, 2019
3ca3e04
Add types for nodeIcal
Oct 17, 2019
67cb340
Add types entry in package.json
Oct 17, 2019
cb56073
Merge pull request #10 from Archcry/master
jens-maus Oct 17, 2019
821a766
fix some vulernability dependencies.
jens-maus May 17, 2020
8eb4b4b
add snyk badge
jens-maus May 17, 2020
84e2892
updated to latest changes applied to peterbradens' upstream branch. Just
jens-maus May 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
'env': {
'commonjs': true,
'es6': true,
'node': true
},
'globals': {
'Atomics': 'readonly',
'SharedArrayBuffer': 'readonly',
'Promise': 'readonly'
},
'parserOptions': {
'ecmaVersion': 2018
},
'extends': ['eslint:recommended', 'prettier'],
'plugins': ['prettier'],
'rules': {
'prettier/prettier': ['error'],
'no-var': 'error', 'prefer-const': 'warn'
}
};
13 changes: 13 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Gruntfile.js
tasks
test
test.js
example.js
*.ics
*.tgz
.travis.yml
.idea
.git
.gitignore
node_modules
appveyor.yml
10 changes: 10 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
printWidth: 120,
tabWidth: 4,
semi: true,
singleQuote: true,
trailingComma: 'es5',
quoteProps: 'consistent',
bracketSpacing: true,
endOfLine: 'lf'
};
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
language: node_js
node_js:
- "8.9"
install: npm install
- "6"
- "8"
- "10"
- "12"
install: npm install
25 changes: 24 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down Expand Up @@ -176,3 +175,27 @@

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright {yyyy} {name of copyright owner}

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
13 changes: 0 additions & 13 deletions NOTICE

This file was deleted.

199 changes: 199 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
# node-ical
[![Build Status](https://travis-ci.org/jens-maus/node-ical.png)](https://travis-ci.org/jens-maus/node-ical)
[![NPM version](http://img.shields.io/npm/v/node-ical.svg)](https://www.npmjs.com/package/node-ical)
[![Downloads](https://img.shields.io/npm/dm/node-ical.svg)](https://www.npmjs.com/package/node-ical)
[![Known Vulnerabilities](https://snyk.io/test/github/jens-maus/node-ical/badge.svg?targetFile=package.json)](https://snyk.io/test/github/jens-maus/node-ical?targetFile=package.json)

[![NPM](https://nodei.co/npm/node-ical.png?downloads=true)](https://nodei.co/npm/node-ical/)

A minimal iCalendar/ICS (http://tools.ietf.org/html/rfc5545) parser for Node.js. This module is a direct fork
of the ical.js module by Peter Braden (https://github.com/peterbraden/ical.js) which is primarily targeted
for parsing iCalender/ICS files in a pure JavaScript environment. (ex. within the browser itself) This node-ical
module however, primarily targets Node.js use and allows for more flexible APIs and interactions within a Node environment. (like filesystem access!)

## Install
node-ical is availble on npm:
```sh
npm install node-ical
```

## API
The API has now been broken into three sections:
- [sync](#sync)
- [async](#async)
- [autodetect](#autodetect)

`sync` provides synchronous API functions.
These are easy to use but can block the event loop and are not recommended for applications that need to serve content or handle events.

`async` provides proper asynchronous support for iCal parsing.
All functions will either return a promise for `async/await` or use a callback if one is provided.

`autodetect` provides a mix of both for backwards compatibility with older node-ical applications.

All API functions are documented using JSDoc in the [index.js](index.js) file.
This allows for IDE hinting!

### sync
```javascript
// import ical
const ical = require('node-ical');

// use the sync function parseFile() to parse this ics file
const events = ical.sync.parseFile('example-calendar.ics');
// loop through events and log them
for (const event of Object.values(events)) {
console.log(
'Summary: ' + event.summary +
'\nDescription: ' + event.description +
'\nStart Date: ' + event.start.toISOString() +
'\n'
);
};

// or just parse some iCalendar data directly
const directEvents = ical.sync.parseICS(`
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT
SUMMARY:Hey look! An example event!
DTSTART;TZID=America/New_York:20130802T103400
DTEND;TZID=America/New_York:20130802T110400
LOCATION:1000 Broadway Ave.\, Brooklyn
DESCRIPTION: Do something in NY.
STATUS:CONFIRMED
UID:7014-1567468800-1567555199@[email protected]
END:VEVENT
END:VCALENDAR
`);
// log the ids of these events
console.log(Object.keys(directEvents));
```

### async
```javascript
// import ical
const ical = require('node-ical');

// do stuff in an async function
;(async () => {
// load and parse this file without blocking the event loop
const events = await ical.async.parseFile('example-calendar.ics');

// you can also use the async lib to download and parse iCal from the web
const webEvents = await ical.async.fromURL('http://lanyrd.com/topics/nodejs/nodejs.ics');
// also you can pass options to request() (optional though!)
const headerWebEvents = await ical.async.fromURL(
'http://lanyrd.com/topics/nodejs/nodejs.ics',
{ headers: { 'User-Agent': 'API-Example / 1.0' } }
);

// parse iCal data without blocking the main loop for extra-large events
const directEvents = await ical.async.parseICS(`
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT
SUMMARY:Hey look! An example event!
DTSTART;TZID=America/New_York:20130802T103400
DTEND;TZID=America/New_York:20130802T110400
DESCRIPTION: Do something in NY.
UID:7014-1567468800-1567555199@[email protected]
END:VEVENT
END:VCALENDAR
`);
})()
.catch(console.error.bind());

// old fashioned callbacks cause why not

// parse a file with a callback
ical.async.parseFile('example-calendar.ics', function(err, data) {
if (err) {
console.error(err);
process.exit(1);
}
console.log(data);
});

// or a URL
ical.async.fromURL('http://lanyrd.com/topics/nodejs/nodejs.ics', function(err, data) { console.log(data); });

// or directly
ical.async.parseICS(`
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT
SUMMARY:Hey look! An example event!
DTSTART;TZID=America/New_York:20130802T103400
DTEND;TZID=America/New_York:20130802T110400
DESCRIPTION: Do something in NY.
UID:7014-1567468800-1567555199@[email protected]
END:VEVENT
END:VCALENDAR
`, function(err, data) { console.log(data); });
```

### autodetect
These are the old API examples, which still work and will be converted to the new API automatically.
Functions with callbacks provided will also have better performance over the older versions even if they use the old API.

Parses a string with ICS content in sync. This can block the event loop on big files.
```javascript
const ical = require('node-ical');
ical.parseICS(str);
```

Parses a string with ICS content in async to prevent the event loop from being blocked.
```javascript
const ical = require('node-ical');
ical.parseICS(str, function(err, data) {
if (err) console.log(err);
console.log(data);
});
```

Parses a string with an ICS file in sync. This can block the event loop on big files.
```javascript
const ical = require('node-ical');
const data = ical.parseFile(filename);
```

Parses a string with an ICS file in async to prevent event loop from being blocked.
```javascript
const ical = require('node-ical');
const data = ical.parseFile(filename, function(err, data) {
if (err) console.log(err);
console.log(data);
});
```

Reads in the specified iCal file from the URL, parses it and returns the parsed data.
```javascript
const ical = require('node-ical');
ical.fromURL(url, options, function(err, data) {
if (err) console.log(err);
console.log(data);
});
```

Use the request library to fetch the specified URL (```opts``` gets passed on to the ```request()``` call), and call the function with the result. (either an error or the data)

#### Example 1 - Print list of upcoming node conferences (see example.js) (parses the file synchronous)
```javascript
const ical = require('node-ical');
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

ical.fromURL('http://lanyrd.com/topics/nodejs/nodejs.ics', {}, function (err, data) {
for (let k in data) {
if (data.hasOwnProperty(k)) {
const ev = data[k];
if (data[k].type == 'VEVENT') {
console.log(`${ev.summary} is in ${ev.location} on the ${ev.start.getDate()} of ${months[ev.start.getMonth()]} at ${ev.start.toLocaleTimeString('en-GB')}`);
}
}
}
});
```
25 changes: 13 additions & 12 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
'use strict';
const ical = require('./index');

const ical = require('ical');
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

ical.fromURL('http://lanyrd.com/topics/nodejs/nodejs.ics', {}, function (err, data) {
for (let k in data) {
if (data.hasOwnProperty(k)) {
var ev = data[k];
if (data[k].type == 'VEVENT') {
console.log(`${ev.summary} is in ${ev.location} on the ${ev.start.getDate()} of ${months[ev.start.getMonth()]} at ${ev.start.toLocaleTimeString('en-GB')}`);

}
}
}
ical.fromURL('http://lanyrd.com/topics/nodejs/nodejs.ics', {}, function(err, data) {
for (const k in data) {
if (!{}.hasOwnProperty.call(data, k)) continue;
const ev = data[k];
if (data[k].type == 'VEVENT') {
console.log(
`${ev.summary} is in ${ev.location} on the ${ev.start.getDate()} of ${
months[ev.start.getMonth()]
} at ${ev.start.toLocaleTimeString('en-GB')}`
);
}
}
});
Loading