Skip to content

Commit

Permalink
feat: Remove save(), saveSync(), serve(), toBlob(), toURL()
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The `save()`, `saveSync()`, `serve()`, `toBlob()` and `toURL()` methods of the ICalCalendar class have been removed. Please use the `toString()` method to generate the ical string and proceed from there.

close #478
  • Loading branch information
sebbo2002 committed Oct 12, 2023
1 parent f29ff3f commit b6bea66
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 325 deletions.
66 changes: 0 additions & 66 deletions package-lock.json

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

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"@touch4it/ical-timezones": "^1.9.0",
"@types/luxon": "^3.3.2",
"@types/mocha": "^10.0.1",
"@types/node": "^20.6.3",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"c8": "^8.0.1",
Expand All @@ -34,7 +33,6 @@
"moment": "^2.29.4",
"moment-timezone": "^0.5.43",
"nyc": "^15.1.0",
"portfinder": "^1.0.32",
"rrule": "^2.7.2",
"semantic-release": "^21.1.2",
"semantic-release-license": "^1.0.2",
Expand Down Expand Up @@ -77,7 +75,6 @@
"@touch4it/ical-timezones": ">=1.6.0",
"@types/luxon": ">= 1.26.0",
"@types/mocha": ">= 8.2.1",
"@types/node": ">= 15.0.0",
"dayjs": ">= 1.10.0",
"luxon": ">= 1.26.0",
"moment": ">= 2.29.0",
Expand Down
88 changes: 0 additions & 88 deletions src/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
toDurationString
} from './tools.js';
import ICalEvent, {ICalEventData, ICalEventJSONData} from './event.js';
import {writeFile, writeFileSync, promises as fsPromises} from 'node:fs';
import {ServerResponse} from 'node:http';
import { ICalMomentDurationStub, ICalTimezone } from './types.js';


Expand Down Expand Up @@ -583,92 +581,6 @@ export default class ICalCalendar {
}


/**
* Save ical file using [`fs/promises`](https://nodejs.org/api/fs.html#fs_fspromises_writefile_file_data_options).
* Only works in node.js environments.
*
* ```javascript
* await calendar.save('./calendar.ical');
* ```
*/
save(path: string): Promise<void>;

/**
* Save ical file with [`fs.writeFile`](http://nodejs.org/api/fs.html#fs_fs_writefile_filename_data_options_callback).
* Only works in node.js environments.
*
* ```javascript
* calendar.save('./calendar.ical', err => {
* console.log(err);
* });
* ```
*/
save(path: string, cb?: (err: NodeJS.ErrnoException | null) => void): this;
save(path: string, cb?: (err: NodeJS.ErrnoException | null) => void): this | Promise<void> {
if (cb) {
writeFile(path, this.toString(), cb);
return this;
}

return fsPromises.writeFile(path, this.toString());
}


/**
* Save Calendar to disk synchronously using
* [fs.writeFileSync](http://nodejs.org/api/fs.html#fs_fs_writefilesync_filename_data_options).
* Only works in node.js environments.
*
* ```javascript
* calendar.saveSync('./calendar.ical');
* ```
*/
saveSync(path: string): this {
writeFileSync(path, this.toString());
return this;
}


/**
* Send calendar to the user when using HTTP using the passed `ServerResponse` object.
* Use second parameter `filename` to change the filename, which defaults to `'calendar.ics'`.
*
* @param response HTTP Response object which is used to send the calendar
* @param [filename = 'calendar.ics'] Filename of the calendar file
*/
serve(response: ServerResponse, filename = 'calendar.ics'): this {
response.writeHead(200, {
'Content-Type': 'text/calendar; charset=utf-8',
'Content-Disposition': `attachment; filename="${filename}"`
});

response.end(this.toString());
return this;
}


/**
* Generates a blob to use for downloads or to generate a download URL.
* Only supported in browsers supporting the Blob API.
*
* @since 1.9.0
*/
toBlob(): Blob {
return new Blob([this.toString()], {type: 'text/calendar'});
}


/**
* Returns a URL to download the ical file. Uses the Blob object internally,
* so it's only supported in browsers supporting the Blob API.
*
* @since 1.9.0
*/
toURL(): string {
return URL.createObjectURL(this.toBlob());
}


/**
* Set X-* attributes. Woun't filter double attributes,
* which are also added by another method (e.g. busystatus),
Expand Down
Loading

0 comments on commit b6bea66

Please sign in to comment.