@ministryofjustice/hmpps-digital-prison-reporting-frontend
Version:
The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.
3 lines (2 loc) • 15.2 kB
JavaScript
var Yt=Object.create;var X=Object.defineProperty;var bt=Object.getOwnPropertyDescriptor;var St=Object.getOwnPropertyNames;var xt=Object.getPrototypeOf,kt=Object.prototype.hasOwnProperty;var nt=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports),Ot=(n,t)=>{for(var s in t)X(n,s,{get:t[s],enumerable:!0})},dt=(n,t,s,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of St(t))!kt.call(n,o)&&o!==s&&X(n,o,{get:()=>t[o],enumerable:!(c=bt(t,o))||c.enumerable});return n};var rt=(n,t,s)=>(s=n!=null?Yt(xt(n)):{},dt(t||!n||!n.__esModule?X(s,"default",{value:n,enumerable:!0}):s,n)),Ft=n=>dt(X({},"__esModule",{value:!0}),n);var lt=nt((at,st)=>{(function(n,t){typeof at=="object"&&typeof st<"u"?st.exports=t():typeof define=="function"&&define.amd?define(t):(n=typeof globalThis<"u"?globalThis:n||self).dayjs=t()})(at,function(){"use strict";var n=1e3,t=6e4,s=36e5,c="millisecond",o="second",d="minute",g="hour",Y="day",v="week",x="month",I="quarter",H="year",N="date",J="Invalid Date",h=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,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,w={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(u){var r=["th","st","nd","rd"],e=u%100;return"["+u+(r[(e-20)%10]||r[e]||r[0])+"]"}},y=function(u,r,e){var i=String(u);return!i||i.length>=r?u:""+Array(r+1-i.length).join(e)+u},B={s:y,z:function(u){var r=-u.utcOffset(),e=Math.abs(r),i=Math.floor(e/60),a=e%60;return(r<=0?"+":"-")+y(i,2,"0")+":"+y(a,2,"0")},m:function u(r,e){if(r.date()<e.date())return-u(e,r);var i=12*(e.year()-r.year())+(e.month()-r.month()),a=r.clone().add(i,x),f=e-a<0,l=r.clone().add(i+(f?-1:1),x);return+(-(i+(e-a)/(f?a-l:l-a))||0)},a:function(u){return u<0?Math.ceil(u)||0:Math.floor(u)},p:function(u){return{M:x,y:H,w:v,d:Y,D:N,h:g,m:d,s:o,ms:c,Q:I}[u]||String(u||"").toLowerCase().replace(/s$/,"")},u:function(u){return u===void 0}},O="en",T={};T[O]=w;var C="$isDayjsObject",_=function(u){return u instanceof F||!(!u||!u[C])},L=function u(r,e,i){var a;if(!r)return O;if(typeof r=="string"){var f=r.toLowerCase();T[f]&&(a=f),e&&(T[f]=e,a=f);var l=r.split("-");if(!a&&l.length>1)return u(l[0])}else{var m=r.name;T[m]=r,a=m}return!i&&a&&(O=a),a||!i&&O},p=function(u,r){if(_(u))return u.clone();var e=typeof r=="object"?r:{};return e.date=u,e.args=arguments,new F(e)},$=B;$.l=L,$.i=_,$.w=function(u,r){return p(u,{locale:r.$L,utc:r.$u,x:r.$x,$offset:r.$offset})};var F=function(){function u(e){this.$L=L(e.locale,null,!0),this.parse(e),this.$x=this.$x||e.x||{},this[C]=!0}var r=u.prototype;return r.parse=function(e){this.$d=function(i){var a=i.date,f=i.utc;if(a===null)return new Date(NaN);if($.u(a))return new Date;if(a instanceof Date)return new Date(a);if(typeof a=="string"&&!/Z$/i.test(a)){var l=a.match(h);if(l){var m=l[2]-1||0,M=(l[7]||"0").substring(0,3);return f?new Date(Date.UTC(l[1],m,l[3]||1,l[4]||0,l[5]||0,l[6]||0,M)):new Date(l[1],m,l[3]||1,l[4]||0,l[5]||0,l[6]||0,M)}}return new Date(a)}(e),this.init()},r.init=function(){var e=this.$d;this.$y=e.getFullYear(),this.$M=e.getMonth(),this.$D=e.getDate(),this.$W=e.getDay(),this.$H=e.getHours(),this.$m=e.getMinutes(),this.$s=e.getSeconds(),this.$ms=e.getMilliseconds()},r.$utils=function(){return $},r.isValid=function(){return this.$d.toString()!==J},r.isSame=function(e,i){var a=p(e);return this.startOf(i)<=a&&a<=this.endOf(i)},r.isAfter=function(e,i){return p(e)<this.startOf(i)},r.isBefore=function(e,i){return this.endOf(i)<p(e)},r.$g=function(e,i,a){return $.u(e)?this[i]:this.set(a,e)},r.unix=function(){return Math.floor(this.valueOf()/1e3)},r.valueOf=function(){return this.$d.getTime()},r.startOf=function(e,i){var a=this,f=!!$.u(i)||i,l=$.p(e),m=function(Z,k){var j=$.w(a.$u?Date.UTC(a.$y,k,Z):new Date(a.$y,k,Z),a);return f?j:j.endOf(Y)},M=function(Z,k){return $.w(a.toDate()[Z].apply(a.toDate("s"),(f?[0,0,0,0]:[23,59,59,999]).slice(k)),a)},b=this.$W,S=this.$M,R=this.$D,U="set"+(this.$u?"UTC":"");switch(l){case H:return f?m(1,0):m(31,11);case x:return f?m(1,S):m(0,S+1);case v:var W=this.$locale().weekStart||0,q=(b<W?b+7:b)-W;return m(f?R-q:R+(6-q),S);case Y:case N:return M(U+"Hours",0);case g:return M(U+"Minutes",1);case d:return M(U+"Seconds",2);case o:return M(U+"Milliseconds",3);default:return this.clone()}},r.endOf=function(e){return this.startOf(e,!1)},r.$set=function(e,i){var a,f=$.p(e),l="set"+(this.$u?"UTC":""),m=(a={},a[Y]=l+"Date",a[N]=l+"Date",a[x]=l+"Month",a[H]=l+"FullYear",a[g]=l+"Hours",a[d]=l+"Minutes",a[o]=l+"Seconds",a[c]=l+"Milliseconds",a)[f],M=f===Y?this.$D+(i-this.$W):i;if(f===x||f===H){var b=this.clone().set(N,1);b.$d[m](M),b.init(),this.$d=b.set(N,Math.min(this.$D,b.daysInMonth())).$d}else m&&this.$d[m](M);return this.init(),this},r.set=function(e,i){return this.clone().$set(e,i)},r.get=function(e){return this[$.p(e)]()},r.add=function(e,i){var a,f=this;e=Number(e);var l=$.p(i),m=function(S){var R=p(f);return $.w(R.date(R.date()+Math.round(S*e)),f)};if(l===x)return this.set(x,this.$M+e);if(l===H)return this.set(H,this.$y+e);if(l===Y)return m(1);if(l===v)return m(7);var M=(a={},a[d]=t,a[g]=s,a[o]=n,a)[l]||1,b=this.$d.getTime()+e*M;return $.w(b,this)},r.subtract=function(e,i){return this.add(-1*e,i)},r.format=function(e){var i=this,a=this.$locale();if(!this.isValid())return a.invalidDate||J;var f=e||"YYYY-MM-DDTHH:mm:ssZ",l=$.z(this),m=this.$H,M=this.$m,b=this.$M,S=a.weekdays,R=a.months,U=a.meridiem,W=function(k,j,E,z){return k&&(k[j]||k(i,f))||E[j].slice(0,z)},q=function(k){return $.s(m%12||12,k,"0")},Z=U||function(k,j,E){var z=k<12?"AM":"PM";return E?z.toLowerCase():z};return f.replace(D,function(k,j){return j||function(E){switch(E){case"YY":return String(i.$y).slice(-2);case"YYYY":return $.s(i.$y,4,"0");case"M":return b+1;case"MM":return $.s(b+1,2,"0");case"MMM":return W(a.monthsShort,b,R,3);case"MMMM":return W(R,b);case"D":return i.$D;case"DD":return $.s(i.$D,2,"0");case"d":return String(i.$W);case"dd":return W(a.weekdaysMin,i.$W,S,2);case"ddd":return W(a.weekdaysShort,i.$W,S,3);case"dddd":return S[i.$W];case"H":return String(m);case"HH":return $.s(m,2,"0");case"h":return q(1);case"hh":return q(2);case"a":return Z(m,M,!0);case"A":return Z(m,M,!1);case"m":return String(M);case"mm":return $.s(M,2,"0");case"s":return String(i.$s);case"ss":return $.s(i.$s,2,"0");case"SSS":return $.s(i.$ms,3,"0");case"Z":return l}return null}(k)||l.replace(":","")})},r.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},r.diff=function(e,i,a){var f,l=this,m=$.p(i),M=p(e),b=(M.utcOffset()-this.utcOffset())*t,S=this-M,R=function(){return $.m(l,M)};switch(m){case H:f=R()/12;break;case x:f=R();break;case I:f=R()/3;break;case v:f=(S-b)/6048e5;break;case Y:f=(S-b)/864e5;break;case g:f=S/s;break;case d:f=S/t;break;case o:f=S/n;break;default:f=S}return a?f:$.a(f)},r.daysInMonth=function(){return this.endOf(x).$D},r.$locale=function(){return T[this.$L]},r.locale=function(e,i){if(!e)return this.$L;var a=this.clone(),f=L(e,i,!0);return f&&(a.$L=f),a},r.clone=function(){return $.w(this.$d,this)},r.toDate=function(){return new Date(this.valueOf())},r.toJSON=function(){return this.isValid()?this.toISOString():null},r.toISOString=function(){return this.$d.toISOString()},r.toString=function(){return this.$d.toUTCString()},u}(),V=F.prototype;return p.prototype=V,[["$ms",c],["$s",o],["$m",d],["$H",g],["$W",Y],["$M",x],["$y",H],["$D",N]].forEach(function(u){V[u[1]]=function(r){return this.$g(r,u[0],u[1])}}),p.extend=function(u,r){return u.$i||(u(r,F,p),u.$i=!0),p},p.locale=L,p.isDayjs=_,p.unix=function(u){return p(1e3*u)},p.en=T[O],p.Ls=T,p.p={},p})});var ht=nt((it,ot)=>{(function(n,t){typeof it=="object"&&typeof ot<"u"?ot.exports=t():typeof define=="function"&&define.amd?define(t):(n=typeof globalThis<"u"?globalThis:n||self).dayjs_plugin_customParseFormat=t()})(it,function(){"use strict";var n={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},t=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|Q|YYYY|YY?|ww?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,s=/\d/,c=/\d\d/,o=/\d\d?/,d=/\d*[^-_:/,()\s\d]+/,g={},Y=function(h){return(h=+h)+(h>68?1900:2e3)},v=function(h){return function(D){this[h]=+D}},x=[/[+-]\d\d:?(\d\d)?|Z/,function(h){(this.zone||(this.zone={})).offset=function(D){if(!D||D==="Z")return 0;var w=D.match(/([+-]|\d\d)/g),y=60*w[1]+(+w[2]||0);return y===0?0:w[0]==="+"?-y:y}(h)}],I=function(h){var D=g[h];return D&&(D.indexOf?D:D.s.concat(D.f))},H=function(h,D){var w,y=g.meridiem;if(y){for(var B=1;B<=24;B+=1)if(h.indexOf(y(B,0,D))>-1){w=B>12;break}}else w=h===(D?"pm":"PM");return w},N={A:[d,function(h){this.afternoon=H(h,!1)}],a:[d,function(h){this.afternoon=H(h,!0)}],Q:[s,function(h){this.month=3*(h-1)+1}],S:[s,function(h){this.milliseconds=100*+h}],SS:[c,function(h){this.milliseconds=10*+h}],SSS:[/\d{3}/,function(h){this.milliseconds=+h}],s:[o,v("seconds")],ss:[o,v("seconds")],m:[o,v("minutes")],mm:[o,v("minutes")],H:[o,v("hours")],h:[o,v("hours")],HH:[o,v("hours")],hh:[o,v("hours")],D:[o,v("day")],DD:[c,v("day")],Do:[d,function(h){var D=g.ordinal,w=h.match(/\d+/);if(this.day=w[0],D)for(var y=1;y<=31;y+=1)D(y).replace(/\[|\]/g,"")===h&&(this.day=y)}],w:[o,v("week")],ww:[c,v("week")],M:[o,v("month")],MM:[c,v("month")],MMM:[d,function(h){var D=I("months"),w=(I("monthsShort")||D.map(function(y){return y.slice(0,3)})).indexOf(h)+1;if(w<1)throw new Error;this.month=w%12||w}],MMMM:[d,function(h){var D=I("months").indexOf(h)+1;if(D<1)throw new Error;this.month=D%12||D}],Y:[/[+-]?\d+/,v("year")],YY:[c,function(h){this.year=Y(h)}],YYYY:[/\d{4}/,v("year")],Z:x,ZZ:x};function J(h){var D,w;D=h,w=g&&g.formats;for(var y=(h=D.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,function(p,$,F){var V=F&&F.toUpperCase();return $||w[F]||n[F]||w[V].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(u,r,e){return r||e.slice(1)})})).match(t),B=y.length,O=0;O<B;O+=1){var T=y[O],C=N[T],_=C&&C[0],L=C&&C[1];y[O]=L?{regex:_,parser:L}:T.replace(/^\[|\]$/g,"")}return function(p){for(var $={},F=0,V=0;F<B;F+=1){var u=y[F];if(typeof u=="string")V+=u.length;else{var r=u.regex,e=u.parser,i=p.slice(V),a=r.exec(i)[0];e.call($,a),p=p.replace(a,"")}}return function(f){var l=f.afternoon;if(l!==void 0){var m=f.hours;l?m<12&&(f.hours+=12):m===12&&(f.hours=0),delete f.afternoon}}($),$}}return function(h,D,w){w.p.customParseFormat=!0,h&&h.parseTwoDigitYear&&(Y=h.parseTwoDigitYear);var y=D.prototype,B=y.parse;y.parse=function(O){var T=O.date,C=O.utc,_=O.args;this.$u=C;var L=_[1];if(typeof L=="string"){var p=_[2]===!0,$=_[3]===!0,F=p||$,V=_[2];$&&(V=_[2]),g=this.$locale(),!p&&V&&(g=w.Ls[V]),this.$d=function(i,a,f,l){try{if(["x","X"].indexOf(a)>-1)return new Date((a==="X"?1e3:1)*i);var m=J(a)(i),M=m.year,b=m.month,S=m.day,R=m.hours,U=m.minutes,W=m.seconds,q=m.milliseconds,Z=m.zone,k=m.week,j=new Date,E=S||(M||b?1:j.getDate()),z=M||j.getFullYear(),P=0;M&&!b||(P=b>0?b-1:j.getMonth());var Q,G=R||0,K=U||0,tt=W||0,et=q||0;return Z?new Date(Date.UTC(z,P,E,G,K,tt,et+60*Z.offset*1e3)):f?new Date(Date.UTC(z,P,E,G,K,tt,et)):(Q=new Date(z,P,E,G,K,tt,et),k&&(Q=l(Q).week(k).toDate()),Q)}catch{return new Date("")}}(T,L,C,w),this.init(),V&&V!==!0&&(this.$L=this.locale(V).$L),F&&T!=this.format(L)&&(this.$d=new Date("")),g={}}else if(L instanceof Array)for(var u=L.length,r=1;r<=u;r+=1){_[1]=L[r-1];var e=w.apply(this,_);if(e.isValid()){this.$d=e.$d,this.$L=e.$L,this.init();break}r===u&&(this.$d=new Date(""))}else B.call(this,O)}}})});var mt=nt((ut,ct)=>{(function(n,t){typeof ut=="object"&&typeof ct<"u"?ct.exports=t():typeof define=="function"&&define.amd?define(t):(n=typeof globalThis<"u"?globalThis:n||self).dayjs_plugin_isBetween=t()})(ut,function(){"use strict";return function(n,t,s){t.prototype.isBetween=function(c,o,d,g){var Y=s(c),v=s(o),x=(g=g||"()")[0]==="(",I=g[1]===")";return(x?this.isAfter(Y,d):!this.isBefore(Y,d))&&(I?this.isBefore(v,d):!this.isAfter(v,d))||(x?this.isBefore(Y,d):!this.isAfter(Y,d))&&(I?this.isAfter(v,d):!this.isBefore(v,d))}}})});var Zt={};Ot(Zt,{default:()=>Ct});module.exports=Ft(Zt);var A=rt(lt()),vt=rt(ht()),pt=rt(mt());var ft=(n,t,s)=>{let{min:c,max:o}=n,d;c?d=$t(c,t):d=t;let g;return o?g=Dt(o,s):g=s,{start:d,end:g}},$t=(n,t)=>{let s=new Date(n);return new Date(t)<s?n:t},Dt=(n,t)=>{let s=new Date(n);return new Date(t)>s?n:t},Lt=n=>{let{min:t,max:s,defaultValue:c}=n,o,d;t&&(o=t),s&&(d=s);let g=/^\d{1,4}-\d{1,2}-\d{2,2} - \d{1,4}-\d{1,2}-\d{1,2}$/,Y;return c&&c.match(g)?([o,d]=c.split(" - "),Y=ft(n,o,d)):c?Y=c:Y=ft(n,o,d),Y};function Vt(n){return n.start!==void 0||n.end!==void 0}var gt={compareMax:Dt,compareMin:$t,isDateRange:Vt,setDateRangeValuesWithinMinMax:ft,getStartAndEndValueFromDefinition:Lt};A.default.extend(vt.default);var Rt=(n,t,s,c)=>{A.default.extend(pt.default);let o=(0,A.default)(s),d=(0,A.default)(c),g=n?n.isBetween(o,d,"day","[]"):!0,Y=t?t.isBetween(o,d,"day","[]"):!0;return g&&Y},yt=n=>{let t,s;switch(n){case"none":t="",s="";break;case"yesterday":t=(0,A.default)(),s=t.subtract(1,"day");break;case"tomorrow":s=(0,A.default)(),t=s.add(1,"day");break;case"last-week":t=(0,A.default)(),s=t.subtract(1,"week");break;case"next-week":s=(0,A.default)(),t=s.add(1,"week");break;case"last-month":t=(0,A.default)(),s=t.subtract(1,"month");break;case"next-month":s=(0,A.default)(),t=s.add(1,"month");break;default:break}return{endDate:t,startDate:s}},Tt=(n,t,s)=>{let c=t.query[`${s}${n.name}.start`],o=t.query[`${s}${n.name}.end`],d=t.query[`${s}${n.name}.relative-duration`];return{start:c||n.min,end:o||n.max,...d&&{relative:d}}},_t=(n,t)=>{let s=t.split(".")[0],c=Object.keys(n.body).filter(d=>d.includes(s)).map(d=>({name:d,value:n.body[d]})),o={start:"",end:""};return c.forEach(d=>{d.name.includes("start")&&(o.start=d.value),d.name.includes("end")&&(o.end=d.value)}),{value:o,name:s}},At=(n,t)=>{let s={start:"",end:""},{start:c,end:o}=n.value;return c&&(s.start=(0,A.default)(c,"D/M/YYYY").format("YYYY-MM-DD").toString()),o&&(s.end=(0,A.default)(o,"D/M/YYYY").format("YYYY-MM-DD").toString()),{...t,value:s}},Mt=(n,t)=>{n||(n="1977-05-25"),t||(t="9999-01-01");let s=wt();return s.forEach(c=>{if(c.value){let{endDate:o,startDate:d}=yt(c.value);Rt(d,o,n,t)||(c.disabled=!0)}}),s.filter(c=>c.value!=="none").every(c=>c.value===null||c.disabled)&&(s=[]),s},jt=n=>{let s=wt().find(c=>c.value===n);return s?s.text:""},wt=()=>[{value:"none",text:"None"},{value:"yesterday",text:"Yesterday"},{value:"tomorrow",text:"Tomorrow"},{value:"last-week",text:"Last week"},{value:"next-week",text:"Next week"},{value:"last-month",text:"Last month"},{value:"next-month",text:"Next month"}],Ht=(n,t)=>{let s=gt.getStartAndEndValueFromDefinition(n),c=Mt(n.min,n.max);return{...t,min:n.min,max:n.max,relativeOptions:c,value:s}},Bt=(n,t,s)=>{let c=n.defaultValue.split(" - "),o;return c.length>=1&&(o=`${s}${t}.start=${c[0]}`,c.length>=2&&(o=`${o}&${s}${t}.end=${c[1]}`)),o},Ct={calcDates:yt,getRelativeDateOptions:Mt,getFilterFromDefinition:Ht,setValueFromRequest:Tt,getQueryFromDefinition:Bt,mapRelativeValue:jt,setDefaultValue:_t,setFilterValueFromDefault:At};
//# sourceMappingURL=utils.js.map