UNPKG

@anoki/fse-marche-ui

Version:

FSE UI components library

3 lines (2 loc) 5.81 kB
"use strict";const T=require("./index.cjs229.js"),a=require("./index.cjs129.js"),M=require("./index.cjs124.js");function y(D,e){let r="";for(const t of D)t.literal?r+=t.val:r+=e(t.val);return r}const S={D:a.DATE_SHORT,DD:a.DATE_MED,DDD:a.DATE_FULL,DDDD:a.DATE_HUGE,t:a.TIME_SIMPLE,tt:a.TIME_WITH_SECONDS,ttt:a.TIME_WITH_SHORT_OFFSET,tttt:a.TIME_WITH_LONG_OFFSET,T:a.TIME_24_SIMPLE,TT:a.TIME_24_WITH_SECONDS,TTT:a.TIME_24_WITH_SHORT_OFFSET,TTTT:a.TIME_24_WITH_LONG_OFFSET,f:a.DATETIME_SHORT,ff:a.DATETIME_MED,fff:a.DATETIME_FULL,ffff:a.DATETIME_HUGE,F:a.DATETIME_SHORT_WITH_SECONDS,FF:a.DATETIME_MED_WITH_SECONDS,FFF:a.DATETIME_FULL_WITH_SECONDS,FFFF:a.DATETIME_HUGE_WITH_SECONDS};class f{static create(e,r={}){return new f(e,r)}static parseFormat(e){let r=null,t="",o=!1;const s=[];for(let m=0;m<e.length;m++){const c=e.charAt(m);c==="'"?(t.length>0&&s.push({literal:o||/^\s+$/.test(t),val:t}),r=null,t="",o=!o):o||c===r?t+=c:(t.length>0&&s.push({literal:/^\s+$/.test(t),val:t}),t=c,r=c)}return t.length>0&&s.push({literal:o||/^\s+$/.test(t),val:t}),s}static macroTokenToFormatOpts(e){return S[e]}constructor(e,r){this.opts=r,this.loc=e,this.systemLoc=null}formatWithSystemDefault(e,r){return this.systemLoc===null&&(this.systemLoc=this.loc.redefaultToSystem()),this.systemLoc.dtFormatter(e,{...this.opts,...r}).format()}dtFormatter(e,r={}){return this.loc.dtFormatter(e,{...this.opts,...r})}formatDateTime(e,r){return this.dtFormatter(e,r).format()}formatDateTimeParts(e,r){return this.dtFormatter(e,r).formatToParts()}formatInterval(e,r){return this.dtFormatter(e.start,r).dtf.formatRange(e.start.toJSDate(),e.end.toJSDate())}resolvedOptions(e,r){return this.dtFormatter(e,r).resolvedOptions()}num(e,r=0){if(this.opts.forceSimple)return M.padStart(e,r);const t={...this.opts};return r>0&&(t.padTo=r),this.loc.numberFormatter(t).format(e)}formatDateTimeFromString(e,r){const t=this.loc.listingMode()==="en",o=this.loc.outputCalendar&&this.loc.outputCalendar!=="gregory",s=(n,l)=>this.loc.extract(e,n,l),m=n=>e.isOffsetFixed&&e.offset===0&&n.allowZ?"Z":e.isValid?e.zone.formatOffset(e.ts,n.format):"",c=()=>t?T.meridiemForDateTime(e):s({hour:"numeric",hourCycle:"h12"},"dayperiod"),u=(n,l)=>t?T.monthForDateTime(e,n):s(l?{month:n}:{month:n,day:"numeric"},"month"),i=(n,l)=>t?T.weekdayForDateTime(e,n):s(l?{weekday:n}:{weekday:n,month:"long",day:"numeric"},"weekday"),h=n=>{const l=f.macroTokenToFormatOpts(n);return l?this.formatWithSystemDefault(e,l):n},E=n=>t?T.eraForDateTime(e,n):s({era:n},"era"),F=n=>{switch(n){case"S":return this.num(e.millisecond);case"u":case"SSS":return this.num(e.millisecond,3);case"s":return this.num(e.second);case"ss":return this.num(e.second,2);case"uu":return this.num(Math.floor(e.millisecond/10),2);case"uuu":return this.num(Math.floor(e.millisecond/100));case"m":return this.num(e.minute);case"mm":return this.num(e.minute,2);case"h":return this.num(e.hour%12===0?12:e.hour%12);case"hh":return this.num(e.hour%12===0?12:e.hour%12,2);case"H":return this.num(e.hour);case"HH":return this.num(e.hour,2);case"Z":return m({format:"narrow",allowZ:this.opts.allowZ});case"ZZ":return m({format:"short",allowZ:this.opts.allowZ});case"ZZZ":return m({format:"techie",allowZ:this.opts.allowZ});case"ZZZZ":return e.zone.offsetName(e.ts,{format:"short",locale:this.loc.locale});case"ZZZZZ":return e.zone.offsetName(e.ts,{format:"long",locale:this.loc.locale});case"z":return e.zoneName;case"a":return c();case"d":return o?s({day:"numeric"},"day"):this.num(e.day);case"dd":return o?s({day:"2-digit"},"day"):this.num(e.day,2);case"c":return this.num(e.weekday);case"ccc":return i("short",!0);case"cccc":return i("long",!0);case"ccccc":return i("narrow",!0);case"E":return this.num(e.weekday);case"EEE":return i("short",!1);case"EEEE":return i("long",!1);case"EEEEE":return i("narrow",!1);case"L":return o?s({month:"numeric",day:"numeric"},"month"):this.num(e.month);case"LL":return o?s({month:"2-digit",day:"numeric"},"month"):this.num(e.month,2);case"LLL":return u("short",!0);case"LLLL":return u("long",!0);case"LLLLL":return u("narrow",!0);case"M":return o?s({month:"numeric"},"month"):this.num(e.month);case"MM":return o?s({month:"2-digit"},"month"):this.num(e.month,2);case"MMM":return u("short",!1);case"MMMM":return u("long",!1);case"MMMMM":return u("narrow",!1);case"y":return o?s({year:"numeric"},"year"):this.num(e.year);case"yy":return o?s({year:"2-digit"},"year"):this.num(e.year.toString().slice(-2),2);case"yyyy":return o?s({year:"numeric"},"year"):this.num(e.year,4);case"yyyyyy":return o?s({year:"numeric"},"year"):this.num(e.year,6);case"G":return E("short");case"GG":return E("long");case"GGGGG":return E("narrow");case"kk":return this.num(e.weekYear.toString().slice(-2),2);case"kkkk":return this.num(e.weekYear,4);case"W":return this.num(e.weekNumber);case"WW":return this.num(e.weekNumber,2);case"n":return this.num(e.localWeekNumber);case"nn":return this.num(e.localWeekNumber,2);case"ii":return this.num(e.localWeekYear.toString().slice(-2),2);case"iiii":return this.num(e.localWeekYear,4);case"o":return this.num(e.ordinal);case"ooo":return this.num(e.ordinal,3);case"q":return this.num(e.quarter);case"qq":return this.num(e.quarter,2);case"X":return this.num(Math.floor(e.ts/1e3));case"x":return this.num(e.ts);default:return h(n)}};return y(f.parseFormat(r),F)}formatDurationFromString(e,r){const t=u=>{switch(u[0]){case"S":return"millisecond";case"s":return"second";case"m":return"minute";case"h":return"hour";case"d":return"day";case"w":return"week";case"M":return"month";case"y":return"year";default:return null}},o=u=>i=>{const h=t(i);return h?this.num(u.get(h),i.length):i},s=f.parseFormat(r),m=s.reduce((u,{literal:i,val:h})=>i?u:u.concat(h),[]),c=e.shiftTo(...m.map(t).filter(u=>u));return y(s,o(c))}}module.exports=f; //# sourceMappingURL=index.cjs121.js.map