UNPKG

calendar-link

Version:

📅 Calendar link generator for popular services, like Google, Outlook, and Yahoo.

3 lines (2 loc) • 14.2 kB
!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?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)({}).hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},e.apply(null,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=6e4,e=36e5,n="millisecond",r="second",a="minute",i="hour",s="day",o="week",u="month",c="quarter",l="year",f="date",d="Invalid Date",h=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,$=/\[([^\]]+)]|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,m={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("_"),ordinal:function(t){var e=["th","st","nd","rd"],n=t%100;return"["+t+(e[(n-20)%10]||e[n]||e[0])+"]"}},v=function(t,e,n){var r=String(t);return!r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},y={s:v,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),a=n%60;return(e<=0?"+":"-")+v(r,2,"0")+":"+v(a,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()),a=e.clone().add(r,u),i=n-a<0,s=e.clone().add(r+(i?-1:1),u);return+(-(r+(n-a)/(i?a-s:s-a))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return{M:u,y:l,w:o,d:s,D:f,h:i,m:a,s:r,ms:n,Q:c}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},g="en",p={};p[g]=m;var D="$isDayjsObject",T=function(t){return t instanceof k||!(!t||!t[D])},M=function t(e,n,r){var a;if(!e)return g;if("string"==typeof e){var i=e.toLowerCase();p[i]&&(a=i),n&&(p[i]=n,a=i);var s=e.split("-");if(!a&&s.length>1)return t(s[0])}else{var o=e.name;p[o]=e,a=o}return!r&&a&&(g=a),a||!r&&g},S=function(t,e){if(T(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new k(n)},O=y;O.l=M,O.i=T,O.w=function(t,e){return S(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var k=function(){function m(t){this.$L=M(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[D]=!0}var v=m.prototype;return v.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(O.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(h);if(r){var a=r[2]-1||0,i=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],a,r[3]||1,r[4]||0,r[5]||0,r[6]||0,i)):new Date(r[1],a,r[3]||1,r[4]||0,r[5]||0,r[6]||0,i)}}return new Date(e)}(t),this.init()},v.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()},v.$utils=function(){return O},v.isValid=function(){return!(this.$d.toString()===d)},v.isSame=function(t,e){var n=S(t);return this.startOf(e)<=n&&n<=this.endOf(e)},v.isAfter=function(t,e){return S(t)<this.startOf(e)},v.isBefore=function(t,e){return this.endOf(e)<S(t)},v.$g=function(t,e,n){return O.u(t)?this[e]:this.set(n,t)},v.unix=function(){return Math.floor(this.valueOf()/1e3)},v.valueOf=function(){return this.$d.getTime()},v.startOf=function(t,e){var n=this,c=!!O.u(e)||e,d=O.p(t),h=function(t,e){var r=O.w(n.$u?Date.UTC(n.$y,e,t):new Date(n.$y,e,t),n);return c?r:r.endOf(s)},$=function(t,e){return O.w(n.toDate()[t].apply(n.toDate("s"),(c?[0,0,0,0]:[23,59,59,999]).slice(e)),n)},m=this.$W,v=this.$M,y=this.$D,g="set"+(this.$u?"UTC":"");switch(d){case l:return c?h(1,0):h(31,11);case u:return c?h(1,v):h(0,v+1);case o:var p=this.$locale().weekStart||0,D=(m<p?m+7:m)-p;return h(c?y-D:y+(6-D),v);case s:case f:return $(g+"Hours",0);case i:return $(g+"Minutes",1);case a:return $(g+"Seconds",2);case r:return $(g+"Milliseconds",3);default:return this.clone()}},v.endOf=function(t){return this.startOf(t,!1)},v.$set=function(t,e){var o,c=O.p(t),d="set"+(this.$u?"UTC":""),h=(o={},o[s]=d+"Date",o[f]=d+"Date",o[u]=d+"Month",o[l]=d+"FullYear",o[i]=d+"Hours",o[a]=d+"Minutes",o[r]=d+"Seconds",o[n]=d+"Milliseconds",o)[c],$=c===s?this.$D+(e-this.$W):e;if(c===u||c===l){var m=this.clone().set(f,1);m.$d[h]($),m.init(),this.$d=m.set(f,Math.min(this.$D,m.daysInMonth())).$d}else h&&this.$d[h]($);return this.init(),this},v.set=function(t,e){return this.clone().$set(t,e)},v.get=function(t){return this[O.p(t)]()},v.add=function(n,c){var f,d=this;n=Number(n);var h=O.p(c),$=function(t){var e=S(d);return O.w(e.date(e.date()+Math.round(t*n)),d)};if(h===u)return this.set(u,this.$M+n);if(h===l)return this.set(l,this.$y+n);if(h===s)return $(1);if(h===o)return $(7);var m=(f={},f[a]=t,f[i]=e,f[r]=1e3,f)[h]||1,v=this.$d.getTime()+n*m;return O.w(v,this)},v.subtract=function(t,e){return this.add(-1*t,e)},v.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||d;var r=t||"YYYY-MM-DDTHH:mm:ssZ",a=O.z(this),i=this.$H,s=this.$m,o=this.$M,u=n.weekdays,c=n.months,l=function(t,n,a,i){return t&&(t[n]||t(e,r))||a[n].slice(0,i)},f=function(t){return O.s(i%12||12,t,"0")},h=n.meridiem||function(t,e,n){var r=t<12?"AM":"PM";return n?r.toLowerCase():r};return r.replace($,function(t,r){return r||function(t){switch(t){case"YY":return String(e.$y).slice(-2);case"YYYY":return O.s(e.$y,4,"0");case"M":return o+1;case"MM":return O.s(o+1,2,"0");case"MMM":return l(n.monthsShort,o,c,3);case"MMMM":return l(c,o);case"D":return e.$D;case"DD":return O.s(e.$D,2,"0");case"d":return String(e.$W);case"dd":return l(n.weekdaysMin,e.$W,u,2);case"ddd":return l(n.weekdaysShort,e.$W,u,3);case"dddd":return u[e.$W];case"H":return String(i);case"HH":return O.s(i,2,"0");case"h":return f(1);case"hh":return f(2);case"a":return h(i,s,!0);case"A":return h(i,s,!1);case"m":return String(s);case"mm":return O.s(s,2,"0");case"s":return String(e.$s);case"ss":return O.s(e.$s,2,"0");case"SSS":return O.s(e.$ms,3,"0");case"Z":return a}return null}(t)||a.replace(":","")})},v.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},v.diff=function(n,f,d){var h,$=this,m=O.p(f),v=S(n),y=(v.utcOffset()-this.utcOffset())*t,g=this-v,p=function(){return O.m($,v)};switch(m){case l:h=p()/12;break;case u:h=p();break;case c:h=p()/3;break;case o:h=(g-y)/6048e5;break;case s:h=(g-y)/864e5;break;case i:h=g/e;break;case a:h=g/t;break;case r:h=g/1e3;break;default:h=g}return d?h:O.a(h)},v.daysInMonth=function(){return this.endOf(u).$D},v.$locale=function(){return p[this.$L]},v.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=M(t,e,!0);return r&&(n.$L=r),n},v.clone=function(){return O.w(this.$d,this)},v.toDate=function(){return new Date(this.valueOf())},v.toJSON=function(){return this.isValid()?this.toISOString():null},v.toISOString=function(){return this.$d.toISOString()},v.toString=function(){return this.$d.toUTCString()},m}(),b=k.prototype;return S.prototype=b,[["$ms",n],["$s",r],["$m",a],["$H",i],["$W",s],["$M",u],["$y",l],["$D",f]].forEach(function(t){b[t[1]]=function(e){return this.$g(e,t[0],t[1])}}),S.extend=function(t,e){return t.$i||(t(e,k,S),t.$i=!0),S},S.locale=M,S.isDayjs=T,S.unix=function(t){return S(1e3*t)},S.en=p[g],S.Ls=p,S.p={},S}()}),a=n(function(t,e){var n,r,a;t.exports=(n="minute",r=/[+-]\d\d(?::?\d\d)?/g,a=/([+-]|\d\d)/g,function(t,e,i){var s=e.prototype;i.utc=function(t){return new e({date:t,utc:!0,args:arguments})},s.utc=function(t){var e=i(this.toDate(),{locale:this.$L,utc:!0});return t?e.add(this.utcOffset(),n):e},s.local=function(){return i(this.toDate(),{locale:this.$L,utc:!1})};var o=s.parse;s.parse=function(t){t.utc&&(this.$u=!0),this.$utils().u(t.$offset)||(this.$offset=t.$offset),o.call(this,t)};var u=s.init;s.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 u.call(this)};var c=s.utcOffset;s.utcOffset=function(t,e){var i=this.$utils().u;if(i(t))return this.$u?0:i(this.$offset)?c.call(this):this.$offset;if("string"==typeof t&&(t=function(t){void 0===t&&(t="");var e=t.match(r);if(!e)return null;var n=(""+e[0]).match(a)||["-",0,0],i=60*+n[1]+ +n[2];return 0===i?0:"+"===n[0]?i:-i}(t),null===t))return this;var s=Math.abs(t)<=16?60*t:t;if(0===s)return this.utc(e);var o=this.clone();if(e)return o.$offset=s,o.$u=!1,o;var u=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();return(o=this.local().add(s+u,n)).$offset=s,o.$x.$localOffset=u,o};var l=s.format;s.format=function(t){return l.call(this,t||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":""))},s.valueOf=function(){var t=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*t},s.isUTC=function(){return!!this.$u},s.toISOString=function(){return this.toDate().toISOString()},s.toString=function(){return this.toDate().toUTCString()};var f=s.toDate;s.toDate=function(t){return"s"===t&&this.$offset?i(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():f.call(this)};var d=s.diff;s.diff=function(t,e,n){if(t&&this.$u===t.$u)return d.call(this,t,e,n);var r=this.local(),a=i(t).local();return d.call(r,a,e,n)}})}),i={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=i[e];return{start:t.startTime.format(r),end:n.format(r)}}r.extend(a);var u=function(t,e,n){return void 0===n&&(n=!0),e?r.utc(t):n?r(t).utc():r(t)},c=function(t,n){void 0===n&&(n=!0);var r=t.start,a=t.end,i=t.duration,s=function(t,e){if(null==t)return{};var n={};for(var r in t)if({}.hasOwnProperty.call(t,r)){if(-1!==e.indexOf(r))continue;n[r]=t[r]}return n}(t,["start","end","duration"]),o=u(r,t.allDay,n),c=a?u(a,t.allDay,n):function(){if(t.allDay)return o.add(1,"day");if(i&&2==i.length){var e=Number(i[0]);return o.add(e,i[1])}return o}();return e({},s,{startTime:o,endTime:c})};t.aol=function(t){var e=c(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=c,t.google=function(t){var e=c(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=c(t),n=(e.description||"").replace(/,/gm,",").replace(/;/gm,";").replace(/\r\n/gm,"\n").replace(/\n/gm,"\\n").replace(/(\\n)[\s\t]+/gm,"\\n"),a=(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"),u=s.start,l=s.end,f=r(new Date).utc().format(i.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:u},{key:"DTEND",value:l},{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:a},{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=c(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=c(t,!1),n=o(e,"dateTimeLocal"),r={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};return e.guests&&e.guests.length&&(r.to=e.guests.join()),"https://outlook.office.com/calendar/0/action/compose?"+s(r)},t.office365Mobile=function(t){var e=c(t,!1),n=o(e,"dateTimeLocal"),r={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};return e.guests&&e.guests.length&&(r.to=e.guests.join()),"https://outlook.office.com/calendar/0/deeplink/compose?"+s(r)},t.outlook=function(t){var e=c(t,!1),n=o(e,"dateTimeLocal"),r={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};return e.guests&&e.guests.length&&(r.to=e.guests.join()),"https://outlook.live.com/calendar/0/action/compose?"+s(r)},t.outlookMobile=function(t){var e=c(t,!1),n=o(e,"dateTimeLocal"),r={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};return e.guests&&e.guests.length&&(r.to=e.guests.join()),"https://outlook.live.com/calendar/0/deeplink/compose?"+s(r)},t.yahoo=function(t){var e=c(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