Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/testeurmaniak/icalendar_parser

Flutter package to parse iCalendar (.ics) files.
https://github.com/testeurmaniak/icalendar_parser

dart flutter ical-parser icalendar ics ics-files parser

Last synced: 12 days ago
JSON representation

Flutter package to parse iCalendar (.ics) files.

Awesome Lists containing this project

README

        

# icalendar_parser

[![Pub Version](https://img.shields.io/pub/v/icalendar_parser?color=blue&logo=dart)](https://pub.dev/packages/icalendar_parser)
[![Stars](https://img.shields.io/github/stars/TesteurManiak/icalendar_parser)](https://github.com/TesteurManiak/icalendar_parser/stargazers)
[![Dart](https://github.com/TesteurManiak/icalendar_parser/actions/workflows/dart.yml/badge.svg)](https://github.com/TesteurManiak/icalendar_parser/actions/workflows/dart.yml)
[![Coverage Status](https://coveralls.io/repos/github/TesteurManiak/icalendar_parser/badge.svg?branch=main)](https://coveralls.io/github/TesteurManiak/icalendar_parser?branch=main)

Package to parse iCalendar (.ics) files written in pure Dart.

Implementation of [AnyFetch's ics-parser](https://github.com/AnyFetch/ics-parser) in JavaScript.

## Getting Started

Add `icalendar_parser` to your pubspec.yaml:

```bash
icalendar_parser: any
```

## How to use

You can refer to the `example/` folder for a complete example implemented in Flutter.

## Constructor

### ICalendar.fromString

```dart
import 'package:flutter/services.dart' show rootBundle;
import 'package:icalendar_parser/icalendar_parser.dart';

final icsString = await rootBundle.loadString('assets/your_file.ics');
final iCalendar = ICalendar.fromString(icsString);
```

### ICalendar.fromLines

```dart
final icsLines = await File('your_file.ics').readAsLines();
final iCalendar = ICalendar.fromLines(lines);
```

## Other methods

### ICalendar.registerField

With this method you can add fields that are not already supported (check [Supported Properties](#supported-properties)) to the parsing and you can specify a custom `function` to parse its content :

```dart
ICalendar.registerField(field: 'TEST');

ICalendar.registerField(
field: 'TEST2',
function: (value, params, event, lastEvent) {
lastEvent['test2'] = 'test';
return lastEvent;
},
);
```

### ICalendar.unregisterField

With this method you can remove parsed fields to ignore them in your file :

```dart
ICalendar.unregisterField('TEST');
```

### ICalendar.toJson

Convert [ICalendar] object to a `Map` containing all its data, formatted into a valid JSON `Map` .

```dart
final icsObj = ICalendar.fromLines(File('assets/my_file.ics').readAsLinesSync());
print(jsonEncode(icsObj.toJson()));
```

**Input**

```
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
CALSCALE:GREGORIAN
METHOD:PUBLISH
BEGIN:VEVENT
CREATED:19960329T133000Z
UID:[email protected]
DTSTAMP:19970714T170000Z
ORGANIZER;CN=John Doe:MAILTO:[email protected]
DTSTART:19970714T170000Z
DTEND:19970715T035959Z
SUMMARY:Bastille Day Party
GEO:48.85299;2.36885
END:VEVENT
END:VCALENDAR
```

**Output**

```json
{
"version": "2.0",
"prodid": "-//hacksw/handcal//NONSGML v1.0//EN",
"calscale": "GREGORIAN",
"method": "PUBLISH",
"data": [
{
"type": "VEVENT",
"created": {
"dt": "19960329T133000Z"
},
"uid": "[email protected]",
"dtstamp": {
"dt": "19970714T170000Z"
},
"organizer": {
"name": "John Doe",
"mail": "[email protected]"
},
"dtstart": {
"dt": "19970714T170000Z"
},
"dtend": {
"dt": "19970715T035959Z"
},
"summary": "Bastille Day Party",
"geo": {
"latitude": 48.85299,
"longitude": 2.36885
}
}
]
}
```

## Supported Properties

- VERSION
- PRODID
- CALSCALE
- METHOD
- COMPONENT: BEGIN
- COMPONENT: END
- DTSTART
- DTEND
- DTSTAMP
- TRIGGER
- LAST-MODIFIED
- COMPLETED
- DUE
- UID
- SUMMARY
- DESCRIPTION
- LOCATION
- URL
- ORGANIZER
- GEO
- CATEGORIES
- ATTENDEE
- ACTION
- STATUS
- SEQUENCE
- REPEAT
- RRULE
- EXDATE
- CREATED

## Contributors





TesteurManiak


Guillaume Roux




LucaCoduriV


Luca




simonbengtsson


Simon Bengtsson




Levi-Lesches


Levi Lesches




jjchiw


Null




stevenboeckmans


Null