Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
86 changes: 86 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
"description": "JavaScript/Node library to parse iCal (.ics) files with few dependencies",
"main": "index.js",
"scripts": {
"test": "mocha -s 50",
"start": "node index.js"
"test": "mocha -r ts-node/register -s 50 test/**/*.spec.ts",
"start": "ts-node src/index.ts"
},
"devDependencies": {
"@types/mocha": "^9.1.0",
"@types/node": "^15.0.1",
"axios": "^0.26.0",
"mocha": "^9.2.1"
"mocha": "^9.2.1",
"ts-node": "^9.1.1",
"typescript": "^4.2.4"
},
"author": "Chris Gilardi <[email protected]>",
"license": "MIT",
Expand Down
90 changes: 90 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import * as iCalDateParser from 'ical-date-parser';
import rrule, { RRule, RRuleSet, rrulestr } from 'rrule';
import * as fs from 'fs';
import { getDate, insert, Metadata, splitICSLines } from './lib/util';
import { join } from 'path';
import { createInterface } from 'readline';
import { ICalKey } from './lib/ical-key';
import { getEventsBetweenDates, getEventsOnDate } from './lib/parsed-event';

export const parseString = (ics: string) => {
const lines = splitICSLines(ics);
};

// let propertyKeySet = new Set<string>();


export const parseFile = (filePath: fs.PathLike) => {
console.log('reading', filePath);

const readStream = fs.createReadStream(filePath);

const readInterface = createInterface({
input: readStream,
terminal: false,
});

let obj: any = {};

readInterface.on('line', (line) => {
const parsed = parseLine(line);
if (parsed.property === 'begin') {
obj[parsed.value] = {};
}
});

// return new Promise((resolve, reject) => {
// readStream.on('end', () => {
// console.log('end');
// resolve();
// });
// });
};

type ICSProperty = 'begin'
| 'end'
| 'prodid'
| 'version'
| 'calscale'
| 'method'
| 'tzid'
| 'dtstart'
| 'dtend'
| 'rrule'
| string;

interface ParsedLineInfo {
property?: ICSProperty;
value?: string;
rawLine: string;
}


const parseLine = (line: string): ParsedLineInfo => {
line = line.toLowerCase();
let lineInfo: ParsedLineInfo = {
rawLine: line,
};

if (!line) {
return lineInfo;
}

const [property, value] = line.split(':');

lineInfo = {
...lineInfo,
property,
value
};

// if (!propertyKeySet.has(property) && !property.includes(' ')) {
// console.log(property);
// propertyKeySet.add(property);
// }

// console.log(lineInfo);
return lineInfo;
};

parseFile(join(__dirname, '..', 'test', 'ical', 'mine', 'test.ics'));
21 changes: 21 additions & 0 deletions src/lib/ical-key.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export enum ICalKey {
Rrule = 'RRULE',
Exdate = 'EXDATE',
Created = 'CREATED',
LastModified = 'LAST-MODIFIED',
Dtstamp = 'DTSTAMP',
Dtstart = 'DTSTART',
Dtend = 'DTEND',
Location = 'LOCATION',
Status = 'STATUS',
Summary = 'SUMMARY',
Description = 'DESCRIPTION',
Transp = 'TRANSP',
Sequence = 'SEQUENCE',
Organizer = 'ORGANIZER',
Uid = 'UID',
Attendee = 'ATTENDEE',
Value = 'VALUE',
Begin = 'BEGIN',
End = 'END',
}
Loading