calendar-link
Version:
📅 Calendar link generator for popular services, like Google, Outlook, and Yahoo.
3 lines (2 loc) • 13 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t||self).calendarLink={})}(this,function(t){function e(){return e=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},e.apply(this,arguments)}function n(t){var e={exports:{}};return t(e,e.exports),e.exports}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var r=n(function(t,e){t.exports=function(){var t="millisecond",e="second",n="minute",r="hour",i="day",a="week",s="month",o="quarter",u="year",l="date",c=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,f=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,d={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_")},h=function(t,e,n){var r=String(t);return!r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},m={s:h,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),i=n%60;return(e<=0?"+":"-")+h(r,2,"0")+":"+h(i,2,"0")},m:function t(e,n){if(e.date()<n.date())return-t(n,e);var r=12*(n.year()-e.year())+(n.month()-e.month()),i=e.clone().add(r,s),a=n-i<0,o=e.clone().add(r+(a?-1:1),s);return+(-(r+(n-i)/(a?i-o:o-i))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(c){return{M:s,y:u,w:a,d:i,D:l,h:r,m:n,s:e,ms:t,Q:o}[c]||String(c||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},$="en",y={};y[$]=d;var v=function(t){return t instanceof T},p=function(t,e,n){var r;if(!t)return $;if("string"==typeof t)y[t]&&(r=t),e&&(y[t]=e,r=t);else{var i=t.name;y[i]=t,r=i}return!n&&r&&($=r),r||!n&&$},D=function(t,e){if(v(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new T(n)},g=m;g.l=p,g.i=v,g.w=function(t,e){return D(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var T=function(){function d(t){this.$L=p(t.locale,null,!0),this.parse(t)}var h=d.prototype;return h.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(g.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match(c);if(r){var i=r[2]-1||0,a=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,a)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,a)}}return new Date(e)}(t),this.$x=t.x||{},this.init()},h.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},h.$utils=function(){return g},h.isValid=function(){return!("Invalid Date"===this.$d.toString())},h.isSame=function(t,e){var n=D(t);return this.startOf(e)<=n&&n<=this.endOf(e)},h.isAfter=function(t,e){return D(t)<this.startOf(e)},h.isBefore=function(t,e){return this.endOf(e)<D(t)},h.$g=function(t,e,n){return g.u(t)?this[e]:this.set(n,t)},h.unix=function(){return Math.floor(this.valueOf()/1e3)},h.valueOf=function(){return this.$d.getTime()},h.startOf=function(t,o){var c=this,f=!!g.u(o)||o,d=g.p(t),h=function(t,e){var n=g.w(c.$u?Date.UTC(c.$y,e,t):new Date(c.$y,e,t),c);return f?n:n.endOf(i)},m=function(t,e){return g.w(c.toDate()[t].apply(c.toDate("s"),(f?[0,0,0,0]:[23,59,59,999]).slice(e)),c)},$=this.$W,y=this.$M,v=this.$D,p="set"+(this.$u?"UTC":"");switch(d){case u:return f?h(1,0):h(31,11);case s:return f?h(1,y):h(0,y+1);case a:var D=this.$locale().weekStart||0,T=($<D?$+7:$)-D;return h(f?v-T:v+(6-T),y);case i:case l:return m(p+"Hours",0);case r:return m(p+"Minutes",1);case n:return m(p+"Seconds",2);case e:return m(p+"Milliseconds",3);default:return this.clone()}},h.endOf=function(t){return this.startOf(t,!1)},h.$set=function(a,o){var c,f=g.p(a),d="set"+(this.$u?"UTC":""),h=(c={},c[i]=d+"Date",c[l]=d+"Date",c[s]=d+"Month",c[u]=d+"FullYear",c[r]=d+"Hours",c[n]=d+"Minutes",c[e]=d+"Seconds",c[t]=d+"Milliseconds",c)[f],m=f===i?this.$D+(o-this.$W):o;if(f===s||f===u){var $=this.clone().set(l,1);$.$d[h](m),$.init(),this.$d=$.set(l,Math.min(this.$D,$.daysInMonth())).$d}else h&&this.$d[h](m);return this.init(),this},h.set=function(t,e){return this.clone().$set(t,e)},h.get=function(t){return this[g.p(t)]()},h.add=function(t,o){var l,c=this;t=Number(t);var f=g.p(o),d=function(e){var n=D(c);return g.w(n.date(n.date()+Math.round(e*t)),c)};if(f===s)return this.set(s,this.$M+t);if(f===u)return this.set(u,this.$y+t);if(f===i)return d(1);if(f===a)return d(7);var h=(l={},l[n]=6e4,l[r]=36e5,l[e]=1e3,l)[f]||1,m=this.$d.getTime()+t*h;return g.w(m,this)},h.subtract=function(t,e){return this.add(-1*t,e)},h.format=function(t){var e=this;if(!this.isValid())return"Invalid Date";var n=t||"YYYY-MM-DDTHH:mm:ssZ",r=g.z(this),i=this.$locale(),a=this.$H,s=this.$m,o=this.$M,u=i.weekdays,l=i.months,c=function(t,r,i,a){return t&&(t[r]||t(e,n))||i[r].substr(0,a)},d=function(t){return g.s(a%12||12,t,"0")},h=i.meridiem||function(t,e,n){var r=t<12?"AM":"PM";return n?r.toLowerCase():r},m={YY:String(this.$y).slice(-2),YYYY:this.$y,M:o+1,MM:g.s(o+1,2,"0"),MMM:c(i.monthsShort,o,l,3),MMMM:c(l,o),D:this.$D,DD:g.s(this.$D,2,"0"),d:String(this.$W),dd:c(i.weekdaysMin,this.$W,u,2),ddd:c(i.weekdaysShort,this.$W,u,3),dddd:u[this.$W],H:String(a),HH:g.s(a,2,"0"),h:d(1),hh:d(2),a:h(a,s,!0),A:h(a,s,!1),m:String(s),mm:g.s(s,2,"0"),s:String(this.$s),ss:g.s(this.$s,2,"0"),SSS:g.s(this.$ms,3,"0"),Z:r};return n.replace(f,function(t,e){return e||m[t]||r.replace(":","")})},h.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},h.diff=function(t,l,c){var f,d=g.p(l),h=D(t),m=6e4*(h.utcOffset()-this.utcOffset()),$=this-h,y=g.m(this,h);return y=(f={},f[u]=y/12,f[s]=y,f[o]=y/3,f[a]=($-m)/6048e5,f[i]=($-m)/864e5,f[r]=$/36e5,f[n]=$/6e4,f[e]=$/1e3,f)[d]||$,c?y:g.a(y)},h.daysInMonth=function(){return this.endOf(s).$D},h.$locale=function(){return y[this.$L]},h.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=p(t,e,!0);return r&&(n.$L=r),n},h.clone=function(){return g.w(this.$d,this)},h.toDate=function(){return new Date(this.valueOf())},h.toJSON=function(){return this.isValid()?this.toISOString():null},h.toISOString=function(){return this.$d.toISOString()},h.toString=function(){return this.$d.toUTCString()},d}(),M=T.prototype;return D.prototype=M,[["$ms",t],["$s",e],["$m",n],["$H",r],["$W",i],["$M",s],["$y",u],["$D",l]].forEach(function(t){M[t[1]]=function(e){return this.$g(e,t[0],t[1])}}),D.extend=function(t,e){return t.$i||(t(e,T,D),t.$i=!0),D},D.locale=p,D.isDayjs=v,D.unix=function(t){return D(1e3*t)},D.en=y[$],D.Ls=y,D.p={},D}()}),i=n(function(t,e){t.exports=function(t,e,n){var r=e.prototype;n.utc=function(t){return new e({date:t,utc:!0,args:arguments})},r.utc=function(t){var e=n(this.toDate(),{locale:this.$L,utc:!0});return t?e.add(this.utcOffset(),"minute"):e},r.local=function(){return n(this.toDate(),{locale:this.$L,utc:!1})};var i=r.parse;r.parse=function(t){t.utc&&(this.$u=!0),this.$utils().u(t.$offset)||(this.$offset=t.$offset),i.call(this,t)};var a=r.init;r.init=function(){if(this.$u){var t=this.$d;this.$y=t.getUTCFullYear(),this.$M=t.getUTCMonth(),this.$D=t.getUTCDate(),this.$W=t.getUTCDay(),this.$H=t.getUTCHours(),this.$m=t.getUTCMinutes(),this.$s=t.getUTCSeconds(),this.$ms=t.getUTCMilliseconds()}else a.call(this)};var s=r.utcOffset;r.utcOffset=function(t,e){var n=this.$utils().u;if(n(t))return this.$u?0:n(this.$offset)?s.call(this):this.$offset;var r=Math.abs(t)<=16?60*t:t,i=this;if(e)return i.$offset=r,i.$u=0===t,i;if(0!==t){var a=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(i=this.local().add(r+a,"minute")).$offset=r,i.$x.$localOffset=a}else i=this.utc();return i};var o=r.format;r.format=function(t){return o.call(this,t||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":""))},r.valueOf=function(){var t=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||(new Date).getTimezoneOffset());return this.$d.valueOf()-6e4*t},r.isUTC=function(){return!!this.$u},r.toISOString=function(){return this.toDate().toISOString()},r.toString=function(){return this.toDate().toUTCString()};var u=r.toDate;r.toDate=function(t){return"s"===t&&this.$offset?n(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():u.call(this)};var l=r.diff;r.diff=function(t,e,r){if(t&&this.$u===t.$u)return l.call(this,t,e,r);var i=this.local(),a=n(t).local();return l.call(i,a,e,r)}}}),a={dateTimeLocal:"YYYY-MM-DD[T]HH:mm:ss",dateTimeUTC:"YYYYMMDD[T]HHmmss[Z]",allDay:"YYYYMMDD"};function s(t){var e=new URLSearchParams;return Object.keys(t).sort().forEach(function(n){var r=t[n];null!=r&&e.append(n,r)}),e.toString().replace(/\+/g,"%20")}function o(t,e){var n=t.endTime,r=a[e];return{start:t.startTime.format(r),end:n.format(r)}}r.extend(i);var u=function(t,n){void 0===n&&(n=!0);var i=t.start,a=t.end,s=t.duration,o=function(t,e){if(null==t)return{};var n,r,i={},a=Object.keys(t);for(r=0;r<a.length;r++)e.indexOf(n=a[r])>=0||(i[n]=t[n]);return i}(t,["start","end","duration"]),u=n?r(i).utc():r(i),l=a?n?r(a).utc():r(a):function(){if(t.allDay)return u.add(1,"day");if(s&&2==s.length){var e=Number(s[0]);return u.add(e,s[1])}return u}();return e({},o,{startTime:u,endTime:l})};t.aol=function(t){var e=u(t),n=o(e,e.allDay?"allDay":"dateTimeUTC");return"https://calendar.aol.com/?"+s({v:60,title:e.title,st:n.start,et:n.end,desc:e.description,in_loc:e.location,dur:!!e.allDay&&"allday"})},t.eventify=u,t.google=function(t){var e=u(t),n=o(e,e.allDay?"allDay":"dateTimeUTC"),r={action:"TEMPLATE",text:e.title,details:e.description,location:e.location,trp:e.busy,dates:n.start+"/"+n.end,recur:e.rRule?"RRULE:"+e.rRule:void 0};return e.guests&&e.guests.length&&(r.add=e.guests.join()),"https://calendar.google.com/calendar/render?"+s(r)},t.ics=function(t){var e=u(t),n=(e.description||"").replace(/,/gm,",").replace(/;/gm,";").replace(/\r\n/gm,"\n").replace(/\n/gm,"\\n").replace(/(\\n)[\s\t]+/gm,"\\n"),i=(e.location||"").replace(/,/gm,",").replace(/;/gm,";").replace(/\r\n/gm,"\n").replace(/\n/gm,"\\n").replace(/(\\n)[\s\t]+/gm,"\\n"),s=o(e,e.allDay?"allDay":"dateTimeUTC"),l=s.start,c=s.end,f=r(new Date).utc().format(a.dateTimeUTC),d=[{key:"BEGIN",value:"VCALENDAR"},{key:"VERSION",value:"2.0"},{key:"PRODID",value:"-//AnandChowdhary//calendar-link//EN"},{key:"BEGIN",value:"VEVENT"},{key:"URL",value:e.url},{key:"DTSTART",value:l},{key:"DTEND",value:c},{key:"DTSTAMP",value:f}].concat(e.allDay?[{key:"X-MICROSOFT-CDO-ALLDAYEVENT",value:"TRUE"},{key:"X-MICROSOFT-MSNCALENDAR-ALLDAYEVENT",value:"TRUE"}]:[],[{key:"RRULE",value:e.rRule},{key:"SUMMARY",value:e.title},{key:"DESCRIPTION",value:n},{key:"LOCATION",value:i},{key:"ORGANIZER",value:e.organizer},{key:"STATUS",value:e.status},{key:"UID",value:e.uid||Math.floor(1e5*Math.random()).toString().replace(".","")},{key:"END",value:"VEVENT"},{key:"END",value:"VCALENDAR"}]),h="";return d.forEach(function(t){if(t.value)if("ORGANIZER"==t.key){var e=t.value;h+=t.key+";"+encodeURIComponent("CN="+e.name+":MAILTO:"+e.email+"\r\n")}else h+=t.key+":"+encodeURIComponent(t.value+"\r\n")}),"data:text/calendar;charset=utf8,"+h},t.msTeams=function(t){var e=u(t),n={subject:e.title,content:e.description,startTime:e.startTime.toISOString(),endTime:e.endTime.toISOString()};return e.guests&&e.guests.length&&(n.attendees=e.guests.join()),"https://teams.microsoft.com/l/meeting/new?"+s(n)},t.office365=function(t){var e=u(t,!1),n=o(e,"dateTimeLocal");return"https://outlook.office.com/calendar/0/action/compose?"+s({path:"/calendar/action/compose",rru:"addevent",startdt:n.start,enddt:n.end,subject:e.title,body:e.description,location:e.location,allday:e.allDay||!1})},t.office365Mobile=function(t){var e=u(t,!1),n=o(e,"dateTimeLocal");return"https://outlook.office.com/calendar/0/deeplink/compose?"+s({path:"/calendar/action/compose",rru:"addevent",startdt:n.start,enddt:n.end,subject:e.title,body:e.description,location:e.location,allday:e.allDay||!1})},t.outlook=function(t){var e=u(t,!1),n=o(e,"dateTimeLocal");return"https://outlook.live.com/calendar/0/action/compose?"+s({path:"/calendar/action/compose",rru:"addevent",startdt:n.start,enddt:n.end,subject:e.title,body:e.description,location:e.location,allday:e.allDay||!1})},t.outlookMobile=function(t){var e=u(t,!1),n=o(e,"dateTimeLocal");return"https://outlook.live.com/calendar/0/deeplink/compose?"+s({path:"/calendar/action/compose",rru:"addevent",startdt:n.start,enddt:n.end,subject:e.title,body:e.description,location:e.location,allday:e.allDay||!1})},t.yahoo=function(t){var e=u(t),n=o(e,e.allDay?"allDay":"dateTimeUTC");return"https://calendar.yahoo.com/?"+s({v:60,title:e.title,st:n.start,et:n.end,desc:e.description,in_loc:e.location,dur:!!e.allDay&&"allday"})}});
//# sourceMappingURL=index.umd.js.map