Skip to content

Commit

Permalink
➖ Remove query-string dependency (28% smaller bundle size) (#605)
Browse files Browse the repository at this point in the history
* Remove query-string dependency

* Update readme
  • Loading branch information
christianvuerings authored Aug 12, 2024
1 parent 4a7a902 commit 7a1e326
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 47 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ ics(event); // standard ICS file based on https://icalendar.org
- If you don't pass the start and end time in UTC, Google will convert it to UTC but Outlook won't, so it's a good idea to use UTC when passing dates and times
- There are some known issues in Office 365 because of which we can't generate a consistent link in all devices (#542)

## Compatibility

This package uses [URLSearchParams](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) (Node.js >= 10, 97%+ browsers), but if you need to include a polyfill, you can include [url-search-params-polyfill](https://www.npmjs.com/package/url-search-params-polyfill) first.

## License

MIT © [Anand Chowdhary](https://anandchowdhary.com/?utm_source=github&utm_medium=calendar-link&utm_campaign=readme)
47 changes: 3 additions & 44 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"typescript": "^4.0.3"
},
"dependencies": {
"dayjs": "^1.9.3",
"query-string": "^6.13.6"
"dayjs": "^1.9.3"
}
}
14 changes: 13 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
import { stringify } from "query-string";

import {
CalendarEvent,
Expand All @@ -16,6 +15,19 @@ import { TimeFormats } from "./utils";

dayjs.extend(utc);

function stringify(input: Record<string, any>): string {
const params = new URLSearchParams();
Object.keys(input)
.sort()
.forEach((key) => {
const value = input[key];
if (value != null) {
params.append(key, value);
}
});
return params.toString().replace(/\+/g, "%20");
}

function formatTimes(
{ startTime, endTime }: NormalizedCalendarEvent,
dateTimeFormat: keyof typeof TimeFormats
Expand Down

0 comments on commit 7a1e326

Please sign in to comment.