calendar-link
Advanced tools
Comparing version 1.2.4 to 1.2.5
@@ -1,6 +0,7 @@ | ||
import { CalendarEvent } from "./interfaces"; | ||
export declare const eventify: (event: CalendarEvent) => CalendarEvent; | ||
export declare const google: (event: CalendarEvent) => string; | ||
export declare const outlook: (event: CalendarEvent) => string; | ||
export declare const yahoo: (event: CalendarEvent) => string; | ||
export declare const ics: (event: CalendarEvent) => string; | ||
import { CalendarEvent, NormalizedCalendarEvent } from "./interfaces"; | ||
export declare const eventify: (event: CalendarEvent) => NormalizedCalendarEvent; | ||
export declare const google: (calendarEvent: CalendarEvent) => string; | ||
export declare const outlook: (calendarEvent: CalendarEvent) => string; | ||
export declare const yahoo: (calendarEvent: CalendarEvent) => string; | ||
export declare const ics: (calendarEvent: CalendarEvent) => string; | ||
export { CalendarEvent }; |
"use strict"; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -11,29 +22,31 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
dayjs_1.default.extend(utc_1.default); | ||
function formatTimes({ allDay, startUtc, endUtc }, dateTimeFormat) { | ||
const format = utils_1.TimeFormats[allDay ? "allDay" : dateTimeFormat]; | ||
return { start: startUtc.format(format), end: endUtc.format(format) }; | ||
} | ||
exports.eventify = (event) => { | ||
event.start = dayjs_1.default(event.start).toDate(); | ||
if (event.end == null) { | ||
if (event.duration && event.duration.length) { | ||
const duration = Number(event.duration[0]); | ||
const unit = event.duration[1]; | ||
event.end = dayjs_1.default(event.start) | ||
.add(duration, unit) | ||
.toDate(); | ||
} | ||
if (event.allDay) { | ||
event.end = dayjs_1.default(event.start) | ||
.add(1, "day") | ||
.toDate(); | ||
} | ||
const { start, end, duration } = event, rest = __rest(event, ["start", "end", "duration"]); | ||
const startUtc = dayjs_1.default(start).utc(); | ||
const endUtc = end | ||
? dayjs_1.default(end).utc() | ||
: (() => { | ||
if (event.allDay) { | ||
return startUtc.add(1, "day"); | ||
} | ||
if (duration && duration.length == 2) { | ||
const value = Number(duration[0]); | ||
const unit = duration[1]; | ||
return startUtc.add(value, unit); | ||
} | ||
return dayjs_1.default().utc(); | ||
})(); | ||
if (!rest.url && typeof document == "object") { | ||
rest.url = document.URL; | ||
} | ||
return event; | ||
return Object.assign(Object.assign({}, rest), { startUtc, | ||
endUtc }); | ||
}; | ||
exports.google = (event) => { | ||
event = exports.eventify(event); | ||
const format = event.allDay ? utils_1.TimeFormats.allDay : utils_1.TimeFormats.dateTimeUTC; | ||
const start = dayjs_1.default(event.start) | ||
.utc() | ||
.format(format); | ||
const end = dayjs_1.default(event.end) | ||
.utc() | ||
.format(format); | ||
exports.google = (calendarEvent) => { | ||
const event = exports.eventify(calendarEvent); | ||
const { start, end } = formatTimes(event, "dateTimeUTC"); | ||
const details = { | ||
@@ -45,3 +58,3 @@ action: "TEMPLATE", | ||
trp: event.busy, | ||
dates: start + "/" + end | ||
dates: start + "/" + end, | ||
}; | ||
@@ -53,11 +66,5 @@ if (event.guests && event.guests.length) { | ||
}; | ||
exports.outlook = (event) => { | ||
event = exports.eventify(event); | ||
const format = event.allDay ? utils_1.TimeFormats.allDay : utils_1.TimeFormats.dateTime; | ||
const start = dayjs_1.default(event.start) | ||
.utc() | ||
.format(format); | ||
const end = dayjs_1.default(event.end) | ||
.utc() | ||
.format(format); | ||
exports.outlook = (calendarEvent) => { | ||
const event = exports.eventify(calendarEvent); | ||
const { start, end } = formatTimes(event, "dateTime"); | ||
const details = { | ||
@@ -70,15 +77,9 @@ path: "/calendar/action/compose", | ||
body: event.description, | ||
location: event.location | ||
location: event.location, | ||
}; | ||
return `https://outlook.live.com/owa/?${query_string_1.stringify(details)}`; | ||
return `https://outlook.live.com/calendar/0/deeplink/compose?${query_string_1.stringify(details)}`; | ||
}; | ||
exports.yahoo = (event) => { | ||
event = exports.eventify(event); | ||
const format = event.allDay ? utils_1.TimeFormats.allDay : utils_1.TimeFormats.dateTimeUTC; | ||
const start = dayjs_1.default(event.start) | ||
.utc() | ||
.format(format); | ||
const end = dayjs_1.default(event.end) | ||
.utc() | ||
.format(format); | ||
exports.yahoo = (calendarEvent) => { | ||
const event = exports.eventify(calendarEvent); | ||
const { start, end } = formatTimes(event, "dateTimeUTC"); | ||
const details = { | ||
@@ -90,66 +91,60 @@ v: 60, | ||
desc: event.description, | ||
in_loc: event.location | ||
in_loc: event.location, | ||
}; | ||
return `https://calendar.yahoo.com/?${query_string_1.stringify(details)}`; | ||
}; | ||
exports.ics = (event) => { | ||
event = exports.eventify(event); | ||
exports.ics = (calendarEvent) => { | ||
const event = exports.eventify(calendarEvent); | ||
const formattedDescription = (event.description || "") | ||
.replace(/\n/gm, "\\n") | ||
.replace(/(\\n)[\s\t]+/gm, "\\n"); | ||
const format = event.allDay ? utils_1.TimeFormats.allDay : utils_1.TimeFormats.dateTimeUTC; | ||
const start = dayjs_1.default(event.start) | ||
.utc() | ||
.format(format); | ||
const end = dayjs_1.default(event.end) | ||
.utc() | ||
.format(format); | ||
const { start, end } = formatTimes(event, "dateTimeUTC"); | ||
const calendarChunks = [ | ||
{ | ||
key: 'BEGIN', | ||
value: 'VCALENDAR' | ||
key: "BEGIN", | ||
value: "VCALENDAR", | ||
}, | ||
{ | ||
key: 'VERSION', | ||
value: '2.0' | ||
key: "VERSION", | ||
value: "2.0", | ||
}, | ||
{ | ||
key: 'BEGIN', | ||
value: 'VEVENT' | ||
key: "BEGIN", | ||
value: "VEVENT", | ||
}, | ||
{ | ||
key: 'URL', | ||
value: document.URL | ||
key: "URL", | ||
value: event.url, | ||
}, | ||
{ | ||
key: 'DTSTART', | ||
value: start | ||
key: "DTSTART", | ||
value: start, | ||
}, | ||
{ | ||
key: 'DTEND', | ||
value: end | ||
key: "DTEND", | ||
value: end, | ||
}, | ||
{ | ||
key: 'SUMMARY', | ||
value: event.title | ||
key: "SUMMARY", | ||
value: event.title, | ||
}, | ||
{ | ||
key: 'DESCRIPTION', | ||
value: formattedDescription | ||
key: "DESCRIPTION", | ||
value: formattedDescription, | ||
}, | ||
{ | ||
key: 'LOCATION', | ||
value: event.location | ||
key: "LOCATION", | ||
value: event.location, | ||
}, | ||
{ | ||
key: 'END', | ||
value: 'VEVENT' | ||
key: "END", | ||
value: "VEVENT", | ||
}, | ||
{ | ||
key: 'END', | ||
value: 'VCALENDAR' | ||
key: "END", | ||
value: "VCALENDAR", | ||
}, | ||
]; | ||
let calendarUrl = ''; | ||
calendarChunks.forEach(chunk => { | ||
let calendarUrl = ""; | ||
calendarChunks.forEach((chunk) => { | ||
if (chunk.value) { | ||
@@ -156,0 +151,0 @@ calendarUrl += `${chunk.key}:${encodeURIComponent(`${chunk.value}\n`)}`; |
@@ -12,3 +12,8 @@ import dayjs from "dayjs"; | ||
guests?: string[]; | ||
url?: string; | ||
} | ||
interface NormalizedCalendarEvent extends Omit<CalendarEvent, "start" | "end" | "duration"> { | ||
startUtc: dayjs.Dayjs; | ||
endUtc: dayjs.Dayjs; | ||
} | ||
interface Google { | ||
@@ -44,2 +49,2 @@ action: string; | ||
} | ||
export { CalendarEvent, Outlook, Yahoo, Google }; | ||
export { CalendarEvent, NormalizedCalendarEvent, Outlook, Yahoo, Google }; |
@@ -6,4 +6,4 @@ "use strict"; | ||
dateTimeUTC: "YYYYMMDD[T]HHmmss[Z]", | ||
allDay: "YYYYMMDD" | ||
allDay: "YYYYMMDD", | ||
}; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "calendar-link", | ||
"version": "1.2.4", | ||
"version": "1.2.5", | ||
"main": "dist/index.js", | ||
@@ -23,10 +23,10 @@ "files": [ | ||
"devDependencies": { | ||
"@types/jest": "^24.0.18", | ||
"concurrently": "^4.1.2", | ||
"coveralls": "^3.0.6", | ||
"@types/jest": "^25.2.1", | ||
"concurrently": "^5.1.0", | ||
"coveralls": "^3.0.11", | ||
"jest": "^24.5.0", | ||
"onchange": "^6.0.0", | ||
"prettier": "^1.18.2", | ||
"ts-jest": "^24.0.2", | ||
"typescript": "^3.6.2" | ||
"onchange": "^6.1.0", | ||
"prettier": "^2.0.4", | ||
"ts-jest": "^24.3.0", | ||
"typescript": "^3.8.3" | ||
}, | ||
@@ -50,5 +50,5 @@ "jest": { | ||
"dependencies": { | ||
"dayjs": "^1.8.16", | ||
"query-string": "^6.8.3" | ||
"dayjs": "^1.8.24", | ||
"query-string": "^6.12.1" | ||
} | ||
} |
@@ -11,3 +11,4 @@ # Calendar Link | ||
JavaScript library to generate an event link for Google Calendar, Yahoo! Calendar, Microsoft Outlook, etc. | ||
JavaScript library to generate an event link for Google Calendar, Yahoo! | ||
Calendar, Microsoft Outlook, etc. | ||
@@ -19,3 +20,3 @@ [![NPM](https://nodei.co/npm/calendar-link.png)](https://npm.im/calendar-link/) | ||
```js | ||
import { google, outlook, yahoo, ics } from "calendar-link" | ||
import { google, outlook, yahoo, ics } from "calendar-link"; | ||
@@ -26,3 +27,3 @@ // Set event as an object | ||
description: "Be there!", | ||
starts: "2019-12-29 18:00:00 +0100", | ||
start: "2019-12-29 18:00:00 +0100", | ||
duration: [3, "hour"] | ||
@@ -33,3 +34,3 @@ }; | ||
google(event); // https://calendar.google.com/calendar/render... | ||
outook(event); // https://outlook.live.com/owa/... | ||
outlook(event); // https://outlook.live.com/owa/... | ||
yahoo(event); // https://calendar.yahoo.com/?v=60&title=... | ||
@@ -42,3 +43,3 @@ ics(event); // standard ICS calendar base on https://icalendar.org/ | ||
| Property | Description | Allowed values | | ||
|------------------|-----------------------------|---------------------------------------------| | ||
| ---------------- | --------------------------- | ------------------------------------------- | | ||
| `title` 👍 | Event title | String | | ||
@@ -53,36 +54,48 @@ | `start` 👍 | Start time | JS Date / ISO 8601 string / Unix Timestamp | | ||
| `guests` 🤞 | Emails of other guests | Array of emails (String) | | ||
| `url` 🤞 | Calendar document URL | String | | ||
The `duration` field is ignored if `allDay` is used. | ||
The `url` field defaults to `document.URL` if a document global exists. | ||
#### Support key | ||
| Emoji | Meaning | | ||
| --- | --- | | ||
| 👍 | Required | | ||
| 🤙 | Any one is required | | ||
| 👌 | Supported but not required | | ||
| 🤞 | Not all calendars support | | ||
| Emoji | Meaning | | ||
| ----- | -------------------------- | | ||
| 👍 | Required | | ||
| 🤙 | Any one is required | | ||
| 👌 | Supported but not required | | ||
| 🤞 | Not all calendars support | | ||
## License | ||
MIT © [Anand Chowdhary](https://anandchowdhary.com/?utm_source=github&utm_medium=calendar-link&utm_campaign=readme) | ||
MIT © | ||
[Anand Chowdhary](https://anandchowdhary.com/?utm_source=github&utm_medium=calendar-link&utm_campaign=readme) | ||
## Contributors | ||
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): | ||
Thanks goes to these wonderful people | ||
([emoji key](https://allcontributors.org/docs/en/emoji-key)): | ||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> | ||
<!-- prettier-ignore --> | ||
<!-- prettier-ignore-start --> | ||
<!-- markdownlint-disable --> | ||
<table> | ||
<tr> | ||
<td align="center"><a href="https://anandchowdhary.com/?utm_source=github&utm_campaign=about-link"><img src="https://avatars3.githubusercontent.com/u/2841780?v=4" width="100px;" alt="Anand Chowdhary"/><br /><sub><b>Anand Chowdhary</b></sub></a><br /><a href="https://github.com/AnandChowdhary/calendar-link/commits?author=AnandChowdhary" title="Code">💻</a> <a href="https://github.com/AnandChowdhary/calendar-link/commits?author=AnandChowdhary" title="Documentation">📖</a></td> | ||
<td align="center"><a href="https://keybase.io/lachenmayer"><img src="https://avatars1.githubusercontent.com/u/38614?v=4" width="100px;" alt="Harry Lachenmayer"/><br /><sub><b>Harry Lachenmayer</b></sub></a><br /><a href="https://github.com/AnandChowdhary/calendar-link/commits?author=lachenmayer" title="Code">💻</a> <a href="https://github.com/AnandChowdhary/calendar-link/commits?author=lachenmayer" title="Documentation">📖</a></td> | ||
<td align="center"><a href="http://AlexImbrea.com"><img src="https://avatars2.githubusercontent.com/u/4534299?v=4" width="100px;" alt="Alexandru-Ionut Imbrea"/><br /><sub><b>Alexandru-Ionut Imbrea</b></sub></a><br /><a href="https://github.com/AnandChowdhary/calendar-link/commits?author=AlexImb" title="Code">💻</a></td> | ||
<td align="center"><a href="https://github.com/k4mr4n"><img src="https://avatars1.githubusercontent.com/u/5468009?v=4" width="100px;" alt="Kamran Gh"/><br /><sub><b>Kamran Gh</b></sub></a><br /><a href="https://github.com/AnandChowdhary/calendar-link/commits?author=k4mr4n" title="Code">💻</a></td> | ||
<td align="center"><a href="http://paulhebertdesigns.com"><img src="https://avatars3.githubusercontent.com/u/5798536?v=4" width="100px;" alt="Paul Hebert"/><br /><sub><b>Paul Hebert</b></sub></a><br /><a href="https://github.com/AnandChowdhary/calendar-link/issues?q=author%3APaul-Hebert" title="Bug reports">🐛</a> <a href="https://github.com/AnandChowdhary/calendar-link/commits?author=Paul-Hebert" title="Code">💻</a></td> | ||
<td align="center"><a href="https://anandchowdhary.com/?utm_source=github&utm_campaign=about-link"><img src="https://avatars3.githubusercontent.com/u/2841780?v=4" width="100px;" alt=""/><br /><sub><b>Anand Chowdhary</b></sub></a><br /><a href="https://github.com/AnandChowdhary/calendar-link/commits?author=AnandChowdhary" title="Code">💻</a> <a href="https://github.com/AnandChowdhary/calendar-link/commits?author=AnandChowdhary" title="Documentation">📖</a></td> | ||
<td align="center"><a href="https://keybase.io/lachenmayer"><img src="https://avatars1.githubusercontent.com/u/38614?v=4" width="100px;" alt=""/><br /><sub><b>Harry Lachenmayer</b></sub></a><br /><a href="https://github.com/AnandChowdhary/calendar-link/commits?author=lachenmayer" title="Code">💻</a> <a href="https://github.com/AnandChowdhary/calendar-link/commits?author=lachenmayer" title="Documentation">📖</a></td> | ||
<td align="center"><a href="http://AlexImbrea.com"><img src="https://avatars2.githubusercontent.com/u/4534299?v=4" width="100px;" alt=""/><br /><sub><b>Alexandru-Ionut Imbrea</b></sub></a><br /><a href="https://github.com/AnandChowdhary/calendar-link/commits?author=AlexImb" title="Code">💻</a></td> | ||
<td align="center"><a href="https://github.com/k4mr4n"><img src="https://avatars1.githubusercontent.com/u/5468009?v=4" width="100px;" alt=""/><br /><sub><b>Kamran Gh</b></sub></a><br /><a href="https://github.com/AnandChowdhary/calendar-link/commits?author=k4mr4n" title="Code">💻</a></td> | ||
<td align="center"><a href="http://paulhebertdesigns.com"><img src="https://avatars3.githubusercontent.com/u/5798536?v=4" width="100px;" alt=""/><br /><sub><b>Paul Hebert</b></sub></a><br /><a href="https://github.com/AnandChowdhary/calendar-link/issues?q=author%3APaul-Hebert" title="Bug reports">🐛</a> <a href="https://github.com/AnandChowdhary/calendar-link/commits?author=Paul-Hebert" title="Code">💻</a></td> | ||
<td align="center"><a href="https://github.com/omazin"><img src="https://avatars0.githubusercontent.com/u/53472807?v=4" width="100px;" alt=""/><br /><sub><b>Osman Mazinov</b></sub></a><br /><a href="https://github.com/AnandChowdhary/calendar-link/commits?author=omazin" title="Documentation">📖</a></td> | ||
<td align="center"><a href="https://bob.ippoli.to/"><img src="https://avatars0.githubusercontent.com/u/26596?v=4" width="100px;" alt=""/><br /><sub><b>Bob Ippolito</b></sub></a><br /><a href="https://github.com/AnandChowdhary/calendar-link/commits?author=etrepum" title="Code">💻</a> <a href="https://github.com/AnandChowdhary/calendar-link/commits?author=etrepum" title="Documentation">📖</a></td> | ||
</tr> | ||
</table> | ||
<!-- markdownlint-enable --> | ||
<!-- prettier-ignore-end --> | ||
<!-- ALL-CONTRIBUTORS-LIST:END --> | ||
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! | ||
This project follows the | ||
[all-contributors](https://github.com/all-contributors/all-contributors) | ||
specification. Contributions of any kind welcome! |
Sorry, the diff of this file is not supported yet
19925
219
96
Updateddayjs@^1.8.24
Updatedquery-string@^6.12.1