Skip to content

Commit

Permalink
✨ Add Google link generator
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Mar 27, 2019
1 parent 2d2faf2 commit 5fb280f
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 2 deletions.
Empty file added index.test.ts
Empty file.
46 changes: 44 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
const a = "a";
import dayjs from "dayjs";
import { stringify } from "querystring";
import { CalendarEvent, Google } from "./interfaces";

export { a };
export const eventify = (event: CalendarEvent) => {
event.start = dayjs(event.start).toDate();
if (event.duration && event.duration.length && !event.end) {
const duration = Number(event.duration[0]);
const unit = event.duration[1];
event.end = dayjs(event.start)
.add(duration, unit)
.toDate();
}
return event;
};

export const google = (event: CalendarEvent) => {
event = eventify(event);
const startDate: string = dayjs(event.start)
.toISOString()
.replace(/-/g, "")
.replace(/:/g, "")
.replace(/\./g, "");
const endDate: string = dayjs(event.end)
.toISOString()
.replace(/-/g, "")
.replace(/:/g, "")
.replace(/\./g, "");
const details: Google = {
action: "TEMPLATE",
text: event.title,
details: event.description,
location: event.location,
trp: event.busy,
dates:
startDate.substring(0, startDate.length - 4) +
"Z/" +
endDate.substring(0, endDate.length - 4) +
"Z"
};
if (event.guests && event.guests.length) {
details.add = event.guests.join();
}
return `https://calendar.google.com/calendar/render${stringify(details)}`;
};
47 changes: 47 additions & 0 deletions interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import dayjs from "dayjs";

interface CalendarEvent {
title: string;
start: any;
end?: any;
duration?: [number, dayjs.UnitType];
description?: string;
location?: string;
busy?: boolean;
guests?: string[];
}

interface Google {
action: string;
text: string;
dates: string;
details?: string;
location?: string;
trp?: boolean;
sprop?: string;
add?: string;
src?: string;
recur?: string;
}

interface Outlook {
path: string;
rru: string;
startdt: string;
enddt: string;
subject: string;
allday?: boolean;
body?: string;
location?: string;
}

interface Yahoo {
v: number;
title: string;
st: string;
et: string;
desc?: string;
in_loc?: string;
}

export { CalendarEvent, Outlook, Yahoo, Google };
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,9 @@
"json",
"node"
]
},
"dependencies": {
"dayjs": "^1.8.11",
"query-string": "^6.4.2"
}
}
24 changes: 24 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,11 @@ date-fns@^1.23.0:
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-1.30.1.tgz#2e71bf0b119153dbb4cc4e88d9ea5acfb50dc05c"
integrity sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw==

dayjs@^1.8.11:
version "1.8.11"
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.8.11.tgz#1e0e681c9f1b6668d92dfe71289500ae0990529d"
integrity sha512-eBvWmKn52ax/TBYg7f+tzzqARPl0D0/NUmf5QrZ0Pp+/vFoTP3Q7y4t6p438+5NPN+t8y8Sps3Ed34OV8sNFBQ==

debug@^2.1.2, debug@^2.2.0, debug@^2.3.3:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
Expand Down Expand Up @@ -2945,6 +2950,15 @@ qs@~6.5.2:
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"
integrity sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==

query-string@^6.4.2:
version "6.4.2"
resolved "https://registry.yarnpkg.com/query-string/-/query-string-6.4.2.tgz#8be1dbd105306aebf86022144f575a29d516b713"
integrity sha512-DfJqAen17LfLA3rQ+H5S4uXphrF+ANU1lT2ijds4V/Tj4gZxA3gx5/tg1bz7kYCmwna7LyJNCYqO7jNRzo3aLw==
dependencies:
decode-uri-component "^0.2.0"
split-on-first "^1.0.0"
strict-uri-encode "^2.0.0"

rc@^1.2.7:
version "1.2.8"
resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.8.tgz#cd924bf5200a075b83c188cd6b9e211b7fc0d3ed"
Expand Down Expand Up @@ -3337,6 +3351,11 @@ spdx-license-ids@^3.0.0:
resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.3.tgz#81c0ce8f21474756148bbb5f3bfc0f36bf15d76e"
integrity sha512-uBIcIl3Ih6Phe3XHK1NqboJLdGfwr1UN3k6wSD1dZpmPsIkb8AGNbZYJ1fOBk834+Gxy8rpfDxrS6XLEMZMY2g==

split-on-first@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/split-on-first/-/split-on-first-1.0.0.tgz#648af4ce9a28fbcaadd43274455f298b55025fc6"
integrity sha512-mjA57TQtdWztVZ9THAjGNpgbuIrNfsNrGa5IyK94NoPaT4N14M+GI4jD7t4arLjFkYRQWdETC5RxFzLWouoB3A==

split-string@^3.0.1, split-string@^3.0.2:
version "3.1.0"
resolved "https://registry.yarnpkg.com/split-string/-/split-string-3.1.0.tgz#7cb09dda3a86585705c64b39a6466038682e8fe2"
Expand Down Expand Up @@ -3382,6 +3401,11 @@ stealthy-require@^1.1.1:
resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b"
integrity sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=

strict-uri-encode@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz#b9c7330c7042862f6b142dc274bbcc5866ce3546"
integrity sha1-ucczDHBChi9rFC3CdLvMWGbONUY=

string-length@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/string-length/-/string-length-2.0.0.tgz#d40dbb686a3ace960c1cffca562bf2c45f8363ed"
Expand Down

0 comments on commit 5fb280f

Please sign in to comment.