UNPKG

calendar-link

Version:

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

3 lines (2 loc) • 14 kB
function t(){return t=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},t.apply(null,arguments)}function e(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 n=e(function(t,e){t.exports=function(){var t=6e4,e=36e5,n="millisecond",r="second",a="minute",s="hour",i="day",o="week",u="month",c="quarter",l="year",d="date",f="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])+"]"}},y=function(t,e,n){var r=String(t);return!r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},g={s:y,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),a=n%60;return(e<=0?"+":"-")+y(r,2,"0")+":"+y(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),s=n-a<0,i=e.clone().add(r+(s?-1:1),u);return+(-(r+(n-a)/(s?a-i:i-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:i,D:d,h:s,m:a,s:r,ms:n,Q:c}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},v="en",p={};p[v]=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 v;if("string"==typeof e){var s=e.toLowerCase();p[s]&&(a=s),n&&(p[s]=n,a=s);var i=e.split("-");if(!a&&i.length>1)return t(i[0])}else{var o=e.name;p[o]=e,a=o}return!r&&a&&(v=a),a||!r&&v},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=g;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 y=m.prototype;return y.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,s=(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,s)):new Date(r[1],a,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)}}return new Date(e)}(t),this.init()},y.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()},y.$utils=function(){return O},y.isValid=function(){return!(this.$d.toString()===f)},y.isSame=function(t,e){var n=S(t);return this.startOf(e)<=n&&n<=this.endOf(e)},y.isAfter=function(t,e){return S(t)<this.startOf(e)},y.isBefore=function(t,e){return this.endOf(e)<S(t)},y.$g=function(t,e,n){return O.u(t)?this[e]:this.set(n,t)},y.unix=function(){return Math.floor(this.valueOf()/1e3)},y.valueOf=function(){return this.$d.getTime()},y.startOf=function(t,e){var n=this,c=!!O.u(e)||e,f=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(i)},$=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,y=this.$M,g=this.$D,v="set"+(this.$u?"UTC":"");switch(f){case l:return c?h(1,0):h(31,11);case u:return c?h(1,y):h(0,y+1);case o:var p=this.$locale().weekStart||0,D=(m<p?m+7:m)-p;return h(c?g-D:g+(6-D),y);case i:case d:return $(v+"Hours",0);case s:return $(v+"Minutes",1);case a:return $(v+"Seconds",2);case r:return $(v+"Milliseconds",3);default:return this.clone()}},y.endOf=function(t){return this.startOf(t,!1)},y.$set=function(t,e){var o,c=O.p(t),f="set"+(this.$u?"UTC":""),h=(o={},o[i]=f+"Date",o[d]=f+"Date",o[u]=f+"Month",o[l]=f+"FullYear",o[s]=f+"Hours",o[a]=f+"Minutes",o[r]=f+"Seconds",o[n]=f+"Milliseconds",o)[c],$=c===i?this.$D+(e-this.$W):e;if(c===u||c===l){var m=this.clone().set(d,1);m.$d[h]($),m.init(),this.$d=m.set(d,Math.min(this.$D,m.daysInMonth())).$d}else h&&this.$d[h]($);return this.init(),this},y.set=function(t,e){return this.clone().$set(t,e)},y.get=function(t){return this[O.p(t)]()},y.add=function(n,c){var d,f=this;n=Number(n);var h=O.p(c),$=function(t){var e=S(f);return O.w(e.date(e.date()+Math.round(t*n)),f)};if(h===u)return this.set(u,this.$M+n);if(h===l)return this.set(l,this.$y+n);if(h===i)return $(1);if(h===o)return $(7);var m=(d={},d[a]=t,d[s]=e,d[r]=1e3,d)[h]||1,y=this.$d.getTime()+n*m;return O.w(y,this)},y.subtract=function(t,e){return this.add(-1*t,e)},y.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||f;var r=t||"YYYY-MM-DDTHH:mm:ssZ",a=O.z(this),s=this.$H,i=this.$m,o=this.$M,u=n.weekdays,c=n.months,l=function(t,n,a,s){return t&&(t[n]||t(e,r))||a[n].slice(0,s)},d=function(t){return O.s(s%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(s);case"HH":return O.s(s,2,"0");case"h":return d(1);case"hh":return d(2);case"a":return h(s,i,!0);case"A":return h(s,i,!1);case"m":return String(i);case"mm":return O.s(i,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(":","")})},y.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},y.diff=function(n,d,f){var h,$=this,m=O.p(d),y=S(n),g=(y.utcOffset()-this.utcOffset())*t,v=this-y,p=function(){return O.m($,y)};switch(m){case l:h=p()/12;break;case u:h=p();break;case c:h=p()/3;break;case o:h=(v-g)/6048e5;break;case i:h=(v-g)/864e5;break;case s:h=v/e;break;case a:h=v/t;break;case r:h=v/1e3;break;default:h=v}return f?h:O.a(h)},y.daysInMonth=function(){return this.endOf(u).$D},y.$locale=function(){return p[this.$L]},y.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=M(t,e,!0);return r&&(n.$L=r),n},y.clone=function(){return O.w(this.$d,this)},y.toDate=function(){return new Date(this.valueOf())},y.toJSON=function(){return this.isValid()?this.toISOString():null},y.toISOString=function(){return this.$d.toISOString()},y.toString=function(){return this.$d.toUTCString()},m}(),b=k.prototype;return S.prototype=b,[["$ms",n],["$s",r],["$m",a],["$H",s],["$W",i],["$M",u],["$y",l],["$D",d]].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[v],S.Ls=p,S.p={},S}()}),r=e(function(t,e){var n,r,a;t.exports=(n="minute",r=/[+-]\d\d(?::?\d\d)?/g,a=/([+-]|\d\d)/g,function(t,e,s){var i=e.prototype;s.utc=function(t){return new e({date:t,utc:!0,args:arguments})},i.utc=function(t){var e=s(this.toDate(),{locale:this.$L,utc:!0});return t?e.add(this.utcOffset(),n):e},i.local=function(){return s(this.toDate(),{locale:this.$L,utc:!1})};var o=i.parse;i.parse=function(t){t.utc&&(this.$u=!0),this.$utils().u(t.$offset)||(this.$offset=t.$offset),o.call(this,t)};var u=i.init;i.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=i.utcOffset;i.utcOffset=function(t,e){var s=this.$utils().u;if(s(t))return this.$u?0:s(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],s=60*+n[1]+ +n[2];return 0===s?0:"+"===n[0]?s:-s}(t),null===t))return this;var i=Math.abs(t)<=16?60*t:t;if(0===i)return this.utc(e);var o=this.clone();if(e)return o.$offset=i,o.$u=!1,o;var u=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();return(o=this.local().add(i+u,n)).$offset=i,o.$x.$localOffset=u,o};var l=i.format;i.format=function(t){return l.call(this,t||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":""))},i.valueOf=function(){var t=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*t},i.isUTC=function(){return!!this.$u},i.toISOString=function(){return this.toDate().toISOString()},i.toString=function(){return this.toDate().toUTCString()};var d=i.toDate;i.toDate=function(t){return"s"===t&&this.$offset?s(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():d.call(this)};var f=i.diff;i.diff=function(t,e,n){if(t&&this.$u===t.$u)return f.call(this,t,e,n);var r=this.local(),a=s(t).local();return f.call(r,a,e,n)}})});const a={dateTimeLocal:"YYYY-MM-DD[T]HH:mm:ss",dateTimeUTC:"YYYYMMDD[T]HHmmss[Z]",allDay:"YYYYMMDD"};function s(t){const e=new URLSearchParams;return Object.keys(t).sort().forEach(n=>{const r=t[n];null!=r&&e.append(n,r)}),e.toString().replace(/\+/g,"%20")}function i({startTime:t,endTime:e},n){const r=a[n];return{start:t.format(r),end:e.format(r)}}n.extend(r);const o=(t,e,r=!0)=>e?n.utc(t):r?n(t).utc():n(t),u=(e,n=!0)=>{const{start:r,end:a,duration:s}=e,i=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}(e,["start","end","duration"]),u=o(r,e.allDay,n),c=a?o(a,e.allDay,n):(()=>{if(e.allDay)return u.add(1,"day");if(s&&2==s.length){const t=Number(s[0]);return u.add(t,s[1])}return u})();return t({},i,{startTime:u,endTime:c})},c=t=>{const e=u(t),{start:n,end:r}=i(e,e.allDay?"allDay":"dateTimeUTC"),a={action:"TEMPLATE",text:e.title,details:e.description,location:e.location,trp:e.busy,dates:n+"/"+r,recur:e.rRule?"RRULE:"+e.rRule:void 0};return e.guests&&e.guests.length&&(a.add=e.guests.join()),`https://calendar.google.com/calendar/render?${s(a)}`},l=t=>{const e=u(t,!1),{start:n,end:r}=i(e,"dateTimeLocal"),a={path:"/calendar/action/compose",rru:"addevent",startdt:n,enddt:r,subject:e.title,body:e.description,location:e.location,allday:e.allDay||!1};return e.guests&&e.guests.length&&(a.to=e.guests.join()),`https://outlook.live.com/calendar/0/action/compose?${s(a)}`},d=t=>{const e=u(t,!1),{start:n,end:r}=i(e,"dateTimeLocal"),a={path:"/calendar/action/compose",rru:"addevent",startdt:n,enddt:r,subject:e.title,body:e.description,location:e.location,allday:e.allDay||!1};return e.guests&&e.guests.length&&(a.to=e.guests.join()),`https://outlook.live.com/calendar/0/deeplink/compose?${s(a)}`},f=t=>{const e=u(t,!1),{start:n,end:r}=i(e,"dateTimeLocal"),a={path:"/calendar/action/compose",rru:"addevent",startdt:n,enddt:r,subject:e.title,body:e.description,location:e.location,allday:e.allDay||!1};return e.guests&&e.guests.length&&(a.to=e.guests.join()),`https://outlook.office.com/calendar/0/action/compose?${s(a)}`},h=t=>{const e=u(t,!1),{start:n,end:r}=i(e,"dateTimeLocal"),a={path:"/calendar/action/compose",rru:"addevent",startdt:n,enddt:r,subject:e.title,body:e.description,location:e.location,allday:e.allDay||!1};return e.guests&&e.guests.length&&(a.to=e.guests.join()),`https://outlook.office.com/calendar/0/deeplink/compose?${s(a)}`},$=t=>{const e=u(t),{start:n,end:r}=i(e,e.allDay?"allDay":"dateTimeUTC");return`https://calendar.yahoo.com/?${s({v:60,title:e.title,st:n,et:r,desc:e.description,in_loc:e.location,dur:!!e.allDay&&"allday"})}`},m=t=>{const e=u(t),{start:n,end:r}=i(e,e.allDay?"allDay":"dateTimeUTC");return`https://calendar.aol.com/?${s({v:60,title:e.title,st:n,et:r,desc:e.description,in_loc:e.location,dur:!!e.allDay&&"allday"})}`},y=t=>{const 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)}`},g=t=>{const e=u(t),r=(e.description||"").replace(/,/gm,",").replace(/;/gm,";").replace(/\r\n/gm,"\n").replace(/\n/gm,"\\n").replace(/(\\n)[\s\t]+/gm,"\\n"),s=(e.location||"").replace(/,/gm,",").replace(/;/gm,";").replace(/\r\n/gm,"\n").replace(/\n/gm,"\\n").replace(/(\\n)[\s\t]+/gm,"\\n"),{start:o,end:c}=i(e,e.allDay?"allDay":"dateTimeUTC"),l=n(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:o},{key:"DTEND",value:c},{key:"DTSTAMP",value:l},...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:r},{key:"LOCATION",value:s},{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"}];let f="";return d.forEach(t=>{if(t.value)if("ORGANIZER"==t.key){const e=t.value;f+=`${t.key};${encodeURIComponent(`CN=${e.name}:MAILTO:${e.email}\r\n`)}`}else f+=`${t.key}:${encodeURIComponent(`${t.value}\r\n`)}`}),`data:text/calendar;charset=utf8,${f}`};export{m as aol,u as eventify,c as google,g as ics,y as msTeams,f as office365,h as office365Mobile,l as outlook,d as outlookMobile,$ as yahoo}; //# sourceMappingURL=index.modern.mjs.map