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