Skip to content

Commit

Permalink
feat: update documentation (adamgibbons#226)
Browse files Browse the repository at this point in the history
Co-authored-by: mattplayer <[email protected]>
  • Loading branch information
mplayer78 and mattplayer authored Feb 5, 2023
1 parent 4dc64eb commit 0ffd273
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ The [iCalendar](http://tools.ietf.org/html/rfc5545) generator

## Example Usage

#### In node / CommonJS

1) Create an iCalendar event:

```javascript
Expand Down Expand Up @@ -194,6 +196,43 @@ console.log(ics.createEvents(events))
// END:VCALENDAR

```

#### Using ESModules & in the browser

```javascript
import { createEvent} from 'ics';

const event = {
...
}

async function handleDownload() {
const filename = 'ExampleEvent.ics'
const file = await new Promise((resolve, reject) => {
createEvent(event, (error, value) => {
if (error) {
reject(error)
}

resolve(new File([value], filename, { type: 'plain/text' }))
})
})
const url = URL.createObjectURL(file);

// trying to assign the file URL to a window could cause cross-site
// issues so this is a workaround using HTML5
const anchor = document.createElement('a');
anchor.href = url;
anchor.download = filename;

document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor);

URL.revokeObjectURL(url);
}
```

## API

### `createEvent(attributes[, callback])`
Expand Down

0 comments on commit 0ffd273

Please sign in to comment.