@samline/date 2.1.1 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../node_modules/dayjs/dayjs.min.js","../../node_modules/dayjs/locale/de.js","../../node_modules/dayjs/locale/es-mx.js","../../node_modules/dayjs/locale/es.js","../../node_modules/dayjs/locale/fr.js","../../node_modules/dayjs/locale/it.js","../../node_modules/dayjs/locale/ja.js","../../node_modules/dayjs/locale/pt-br.js","../../node_modules/dayjs/locale/pt.js","../../node_modules/dayjs/plugin/customParseFormat.js","../../src/browser/preload-locales.ts","../../src/core/locales.ts","../../src/core/date.ts","../../src/browser/global.ts","../../src/browser/cdn.ts"],"sourcesContent":["!function(t,e){\"object\"==typeof exports&&\"undefined\"!=typeof module?module.exports=e():\"function\"==typeof define&&define.amd?define(e):(t=\"undefined\"!=typeof globalThis?globalThis:t||self).dayjs=e()}(this,(function(){\"use strict\";var t=1e3,e=6e4,n=36e5,r=\"millisecond\",i=\"second\",s=\"minute\",u=\"hour\",a=\"day\",o=\"week\",c=\"month\",f=\"quarter\",h=\"year\",d=\"date\",l=\"Invalid Date\",$=/^(\\d{4})[-/]?(\\d{1,2})?[-/]?(\\d{0,2})[Tt\\s]*(\\d{1,2})?:?(\\d{1,2})?:?(\\d{1,2})?[.:]?(\\d+)?$/,y=/\\[([^\\]]+)]|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])+\"]\"}},m=function(t,e,n){var r=String(t);return!r||r.length>=e?t:\"\"+Array(e+1-r.length).join(n)+t},v={s:m,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),i=n%60;return(e<=0?\"+\":\"-\")+m(r,2,\"0\")+\":\"+m(i,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()),i=e.clone().add(r,c),s=n-i<0,u=e.clone().add(r+(s?-1:1),c);return+(-(r+(n-i)/(s?i-u:u-i))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return{M:c,y:h,w:o,d:a,D:d,h:u,m:s,s:i,ms:r,Q:f}[t]||String(t||\"\").toLowerCase().replace(/s$/,\"\")},u:function(t){return void 0===t}},g=\"en\",D={};D[g]=M;var p=\"$isDayjsObject\",S=function(t){return t instanceof _||!(!t||!t[p])},w=function t(e,n,r){var i;if(!e)return g;if(\"string\"==typeof e){var s=e.toLowerCase();D[s]&&(i=s),n&&(D[s]=n,i=s);var u=e.split(\"-\");if(!i&&u.length>1)return t(u[0])}else{var a=e.name;D[a]=e,i=a}return!r&&i&&(g=i),i||!r&&g},O=function(t,e){if(S(t))return t.clone();var n=\"object\"==typeof e?e:{};return n.date=t,n.args=arguments,new _(n)},b=v;b.l=w,b.i=S,b.w=function(t,e){return O(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var _=function(){function M(t){this.$L=w(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[p]=!0}var m=M.prototype;return m.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(b.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($);if(r){var i=r[2]-1||0,s=(r[7]||\"0\").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)}}return new Date(e)}(t),this.init()},m.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()},m.$utils=function(){return b},m.isValid=function(){return!(this.$d.toString()===l)},m.isSame=function(t,e){var n=O(t);return this.startOf(e)<=n&&n<=this.endOf(e)},m.isAfter=function(t,e){return O(t)<this.startOf(e)},m.isBefore=function(t,e){return this.endOf(e)<O(t)},m.$g=function(t,e,n){return b.u(t)?this[e]:this.set(n,t)},m.unix=function(){return Math.floor(this.valueOf()/1e3)},m.valueOf=function(){return this.$d.getTime()},m.startOf=function(t,e){var n=this,r=!!b.u(e)||e,f=b.p(t),l=function(t,e){var i=b.w(n.$u?Date.UTC(n.$y,e,t):new Date(n.$y,e,t),n);return r?i:i.endOf(a)},$=function(t,e){return b.w(n.toDate()[t].apply(n.toDate(\"s\"),(r?[0,0,0,0]:[23,59,59,999]).slice(e)),n)},y=this.$W,M=this.$M,m=this.$D,v=\"set\"+(this.$u?\"UTC\":\"\");switch(f){case h:return r?l(1,0):l(31,11);case c:return r?l(1,M):l(0,M+1);case o:var g=this.$locale().weekStart||0,D=(y<g?y+7:y)-g;return l(r?m-D:m+(6-D),M);case a:case d:return $(v+\"Hours\",0);case u:return $(v+\"Minutes\",1);case s:return $(v+\"Seconds\",2);case i:return $(v+\"Milliseconds\",3);default:return this.clone()}},m.endOf=function(t){return this.startOf(t,!1)},m.$set=function(t,e){var n,o=b.p(t),f=\"set\"+(this.$u?\"UTC\":\"\"),l=(n={},n[a]=f+\"Date\",n[d]=f+\"Date\",n[c]=f+\"Month\",n[h]=f+\"FullYear\",n[u]=f+\"Hours\",n[s]=f+\"Minutes\",n[i]=f+\"Seconds\",n[r]=f+\"Milliseconds\",n)[o],$=o===a?this.$D+(e-this.$W):e;if(o===c||o===h){var y=this.clone().set(d,1);y.$d[l]($),y.init(),this.$d=y.set(d,Math.min(this.$D,y.daysInMonth())).$d}else l&&this.$d[l]($);return this.init(),this},m.set=function(t,e){return this.clone().$set(t,e)},m.get=function(t){return this[b.p(t)]()},m.add=function(r,f){var d,l=this;r=Number(r);var $=b.p(f),y=function(t){var e=O(l);return b.w(e.date(e.date()+Math.round(t*r)),l)};if($===c)return this.set(c,this.$M+r);if($===h)return this.set(h,this.$y+r);if($===a)return y(1);if($===o)return y(7);var M=(d={},d[s]=e,d[u]=n,d[i]=t,d)[$]||1,m=this.$d.getTime()+r*M;return b.w(m,this)},m.subtract=function(t,e){return this.add(-1*t,e)},m.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||l;var r=t||\"YYYY-MM-DDTHH:mm:ssZ\",i=b.z(this),s=this.$H,u=this.$m,a=this.$M,o=n.weekdays,c=n.months,f=n.meridiem,h=function(t,n,i,s){return t&&(t[n]||t(e,r))||i[n].slice(0,s)},d=function(t){return b.s(s%12||12,t,\"0\")},$=f||function(t,e,n){var r=t<12?\"AM\":\"PM\";return n?r.toLowerCase():r};return r.replace(y,(function(t,r){return r||function(t){switch(t){case\"YY\":return String(e.$y).slice(-2);case\"YYYY\":return b.s(e.$y,4,\"0\");case\"M\":return a+1;case\"MM\":return b.s(a+1,2,\"0\");case\"MMM\":return h(n.monthsShort,a,c,3);case\"MMMM\":return h(c,a);case\"D\":return e.$D;case\"DD\":return b.s(e.$D,2,\"0\");case\"d\":return String(e.$W);case\"dd\":return h(n.weekdaysMin,e.$W,o,2);case\"ddd\":return h(n.weekdaysShort,e.$W,o,3);case\"dddd\":return o[e.$W];case\"H\":return String(s);case\"HH\":return b.s(s,2,\"0\");case\"h\":return d(1);case\"hh\":return d(2);case\"a\":return $(s,u,!0);case\"A\":return $(s,u,!1);case\"m\":return String(u);case\"mm\":return b.s(u,2,\"0\");case\"s\":return String(e.$s);case\"ss\":return b.s(e.$s,2,\"0\");case\"SSS\":return b.s(e.$ms,3,\"0\");case\"Z\":return i}return null}(t)||i.replace(\":\",\"\")}))},m.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},m.diff=function(r,d,l){var $,y=this,M=b.p(d),m=O(r),v=(m.utcOffset()-this.utcOffset())*e,g=this-m,D=function(){return b.m(y,m)};switch(M){case h:$=D()/12;break;case c:$=D();break;case f:$=D()/3;break;case o:$=(g-v)/6048e5;break;case a:$=(g-v)/864e5;break;case u:$=g/n;break;case s:$=g/e;break;case i:$=g/t;break;default:$=g}return l?$:b.a($)},m.daysInMonth=function(){return this.endOf(c).$D},m.$locale=function(){return D[this.$L]},m.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=w(t,e,!0);return r&&(n.$L=r),n},m.clone=function(){return b.w(this.$d,this)},m.toDate=function(){return new Date(this.valueOf())},m.toJSON=function(){return this.isValid()?this.toISOString():null},m.toISOString=function(){return this.$d.toISOString()},m.toString=function(){return this.$d.toUTCString()},M}(),k=_.prototype;return O.prototype=k,[[\"$ms\",r],[\"$s\",i],[\"$m\",s],[\"$H\",u],[\"$W\",a],[\"$M\",c],[\"$y\",h],[\"$D\",d]].forEach((function(t){k[t[1]]=function(e){return this.$g(e,t[0],t[1])}})),O.extend=function(t,e){return t.$i||(t(e,_,O),t.$i=!0),O},O.locale=w,O.isDayjs=S,O.unix=function(t){return O(1e3*t)},O.en=D[g],O.Ls=D,O.p={},O}));","!function(e,n){\"object\"==typeof exports&&\"undefined\"!=typeof module?module.exports=n(require(\"dayjs\")):\"function\"==typeof define&&define.amd?define([\"dayjs\"],n):(e=\"undefined\"!=typeof globalThis?globalThis:e||self).dayjs_locale_de=n(e.dayjs)}(this,(function(e){\"use strict\";function n(e){return e&&\"object\"==typeof e&&\"default\"in e?e:{default:e}}var t=n(e),a={s:\"ein paar Sekunden\",m:[\"eine Minute\",\"einer Minute\"],mm:\"%d Minuten\",h:[\"eine Stunde\",\"einer Stunde\"],hh:\"%d Stunden\",d:[\"ein Tag\",\"einem Tag\"],dd:[\"%d Tage\",\"%d Tagen\"],M:[\"ein Monat\",\"einem Monat\"],MM:[\"%d Monate\",\"%d Monaten\"],y:[\"ein Jahr\",\"einem Jahr\"],yy:[\"%d Jahre\",\"%d Jahren\"]};function i(e,n,t){var i=a[t];return Array.isArray(i)&&(i=i[n?0:1]),i.replace(\"%d\",e)}var r={name:\"de\",weekdays:\"Sonntag_Montag_Dienstag_Mittwoch_Donnerstag_Freitag_Samstag\".split(\"_\"),weekdaysShort:\"So._Mo._Di._Mi._Do._Fr._Sa.\".split(\"_\"),weekdaysMin:\"So_Mo_Di_Mi_Do_Fr_Sa\".split(\"_\"),months:\"Januar_Februar_März_April_Mai_Juni_Juli_August_September_Oktober_November_Dezember\".split(\"_\"),monthsShort:\"Jan._Feb._März_Apr._Mai_Juni_Juli_Aug._Sept._Okt._Nov._Dez.\".split(\"_\"),ordinal:function(e){return e+\".\"},weekStart:1,yearStart:4,formats:{LTS:\"HH:mm:ss\",LT:\"HH:mm\",L:\"DD.MM.YYYY\",LL:\"D. MMMM YYYY\",LLL:\"D. MMMM YYYY HH:mm\",LLLL:\"dddd, D. MMMM YYYY HH:mm\"},relativeTime:{future:\"in %s\",past:\"vor %s\",s:i,m:i,mm:i,h:i,hh:i,d:i,dd:i,M:i,MM:i,y:i,yy:i}};return t.default.locale(r,null,!0),r}));","!function(e,o){\"object\"==typeof exports&&\"undefined\"!=typeof module?module.exports=o(require(\"dayjs\")):\"function\"==typeof define&&define.amd?define([\"dayjs\"],o):(e=\"undefined\"!=typeof globalThis?globalThis:e||self).dayjs_locale_es_mx=o(e.dayjs)}(this,(function(e){\"use strict\";function o(e){return e&&\"object\"==typeof e&&\"default\"in e?e:{default:e}}var s=o(e),d={name:\"es-mx\",weekdays:\"domingo_lunes_martes_miércoles_jueves_viernes_sábado\".split(\"_\"),weekdaysShort:\"dom._lun._mar._mié._jue._vie._sáb.\".split(\"_\"),weekdaysMin:\"do_lu_ma_mi_ju_vi_sá\".split(\"_\"),months:\"enero_febrero_marzo_abril_mayo_junio_julio_agosto_septiembre_octubre_noviembre_diciembre\".split(\"_\"),monthsShort:\"ene_feb_mar_abr_may_jun_jul_ago_sep_oct_nov_dic\".split(\"_\"),relativeTime:{future:\"en %s\",past:\"hace %s\",s:\"unos segundos\",m:\"un minuto\",mm:\"%d minutos\",h:\"una hora\",hh:\"%d horas\",d:\"un día\",dd:\"%d días\",M:\"un mes\",MM:\"%d meses\",y:\"un año\",yy:\"%d años\"},ordinal:function(e){return e+\"º\"},formats:{LT:\"H:mm\",LTS:\"H:mm:ss\",L:\"DD/MM/YYYY\",LL:\"D [de] MMMM [de] YYYY\",LLL:\"D [de] MMMM [de] YYYY H:mm\",LLLL:\"dddd, D [de] MMMM [de] YYYY H:mm\"}};return s.default.locale(d,null,!0),d}));","!function(e,o){\"object\"==typeof exports&&\"undefined\"!=typeof module?module.exports=o(require(\"dayjs\")):\"function\"==typeof define&&define.amd?define([\"dayjs\"],o):(e=\"undefined\"!=typeof globalThis?globalThis:e||self).dayjs_locale_es=o(e.dayjs)}(this,(function(e){\"use strict\";function o(e){return e&&\"object\"==typeof e&&\"default\"in e?e:{default:e}}var s=o(e),d={name:\"es\",monthsShort:\"ene_feb_mar_abr_may_jun_jul_ago_sep_oct_nov_dic\".split(\"_\"),weekdays:\"domingo_lunes_martes_miércoles_jueves_viernes_sábado\".split(\"_\"),weekdaysShort:\"dom._lun._mar._mié._jue._vie._sáb.\".split(\"_\"),weekdaysMin:\"do_lu_ma_mi_ju_vi_sá\".split(\"_\"),months:\"enero_febrero_marzo_abril_mayo_junio_julio_agosto_septiembre_octubre_noviembre_diciembre\".split(\"_\"),weekStart:1,formats:{LT:\"H:mm\",LTS:\"H:mm:ss\",L:\"DD/MM/YYYY\",LL:\"D [de] MMMM [de] YYYY\",LLL:\"D [de] MMMM [de] YYYY H:mm\",LLLL:\"dddd, D [de] MMMM [de] YYYY H:mm\"},relativeTime:{future:\"en %s\",past:\"hace %s\",s:\"unos segundos\",m:\"un minuto\",mm:\"%d minutos\",h:\"una hora\",hh:\"%d horas\",d:\"un día\",dd:\"%d días\",M:\"un mes\",MM:\"%d meses\",y:\"un año\",yy:\"%d años\"},ordinal:function(e){return e+\"º\"}};return s.default.locale(d,null,!0),d}));","!function(e,n){\"object\"==typeof exports&&\"undefined\"!=typeof module?module.exports=n(require(\"dayjs\")):\"function\"==typeof define&&define.amd?define([\"dayjs\"],n):(e=\"undefined\"!=typeof globalThis?globalThis:e||self).dayjs_locale_fr=n(e.dayjs)}(this,(function(e){\"use strict\";function n(e){return e&&\"object\"==typeof e&&\"default\"in e?e:{default:e}}var t=n(e),i={name:\"fr\",weekdays:\"dimanche_lundi_mardi_mercredi_jeudi_vendredi_samedi\".split(\"_\"),weekdaysShort:\"dim._lun._mar._mer._jeu._ven._sam.\".split(\"_\"),weekdaysMin:\"di_lu_ma_me_je_ve_sa\".split(\"_\"),months:\"janvier_février_mars_avril_mai_juin_juillet_août_septembre_octobre_novembre_décembre\".split(\"_\"),monthsShort:\"janv._févr._mars_avr._mai_juin_juil._août_sept._oct._nov._déc.\".split(\"_\"),weekStart:1,yearStart:4,formats:{LT:\"HH:mm\",LTS:\"HH:mm:ss\",L:\"DD/MM/YYYY\",LL:\"D MMMM YYYY\",LLL:\"D MMMM YYYY HH:mm\",LLLL:\"dddd D MMMM YYYY HH:mm\"},relativeTime:{future:\"dans %s\",past:\"il y a %s\",s:\"quelques secondes\",m:\"une minute\",mm:\"%d minutes\",h:\"une heure\",hh:\"%d heures\",d:\"un jour\",dd:\"%d jours\",M:\"un mois\",MM:\"%d mois\",y:\"un an\",yy:\"%d ans\"},ordinal:function(e){return\"\"+e+(1===e?\"er\":\"\")}};return t.default.locale(i,null,!0),i}));","!function(e,o){\"object\"==typeof exports&&\"undefined\"!=typeof module?module.exports=o(require(\"dayjs\")):\"function\"==typeof define&&define.amd?define([\"dayjs\"],o):(e=\"undefined\"!=typeof globalThis?globalThis:e||self).dayjs_locale_it=o(e.dayjs)}(this,(function(e){\"use strict\";function o(e){return e&&\"object\"==typeof e&&\"default\"in e?e:{default:e}}var t=o(e),n={name:\"it\",weekdays:\"domenica_lunedì_martedì_mercoledì_giovedì_venerdì_sabato\".split(\"_\"),weekdaysShort:\"dom_lun_mar_mer_gio_ven_sab\".split(\"_\"),weekdaysMin:\"do_lu_ma_me_gi_ve_sa\".split(\"_\"),months:\"gennaio_febbraio_marzo_aprile_maggio_giugno_luglio_agosto_settembre_ottobre_novembre_dicembre\".split(\"_\"),weekStart:1,monthsShort:\"gen_feb_mar_apr_mag_giu_lug_ago_set_ott_nov_dic\".split(\"_\"),formats:{LT:\"HH:mm\",LTS:\"HH:mm:ss\",L:\"DD/MM/YYYY\",LL:\"D MMMM YYYY\",LLL:\"D MMMM YYYY HH:mm\",LLLL:\"dddd D MMMM YYYY HH:mm\"},relativeTime:{future:\"tra %s\",past:\"%s fa\",s:\"qualche secondo\",m:\"un minuto\",mm:\"%d minuti\",h:\"un'ora\",hh:\"%d ore\",d:\"un giorno\",dd:\"%d giorni\",M:\"un mese\",MM:\"%d mesi\",y:\"un anno\",yy:\"%d anni\"},ordinal:function(e){return e+\"º\"}};return t.default.locale(n,null,!0),n}));","!function(e,_){\"object\"==typeof exports&&\"undefined\"!=typeof module?module.exports=_(require(\"dayjs\")):\"function\"==typeof define&&define.amd?define([\"dayjs\"],_):(e=\"undefined\"!=typeof globalThis?globalThis:e||self).dayjs_locale_ja=_(e.dayjs)}(this,(function(e){\"use strict\";function _(e){return e&&\"object\"==typeof e&&\"default\"in e?e:{default:e}}var t=_(e),d={name:\"ja\",weekdays:\"日曜日_月曜日_火曜日_水曜日_木曜日_金曜日_土曜日\".split(\"_\"),weekdaysShort:\"日_月_火_水_木_金_土\".split(\"_\"),weekdaysMin:\"日_月_火_水_木_金_土\".split(\"_\"),months:\"1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月\".split(\"_\"),monthsShort:\"1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月\".split(\"_\"),ordinal:function(e){return e+\"日\"},formats:{LT:\"HH:mm\",LTS:\"HH:mm:ss\",L:\"YYYY/MM/DD\",LL:\"YYYY年M月D日\",LLL:\"YYYY年M月D日 HH:mm\",LLLL:\"YYYY年M月D日 dddd HH:mm\",l:\"YYYY/MM/DD\",ll:\"YYYY年M月D日\",lll:\"YYYY年M月D日 HH:mm\",llll:\"YYYY年M月D日(ddd) HH:mm\"},meridiem:function(e){return e<12?\"午前\":\"午後\"},relativeTime:{future:\"%s後\",past:\"%s前\",s:\"数秒\",m:\"1分\",mm:\"%d分\",h:\"1時間\",hh:\"%d時間\",d:\"1日\",dd:\"%d日\",M:\"1ヶ月\",MM:\"%dヶ月\",y:\"1年\",yy:\"%d年\"}};return t.default.locale(d,null,!0),d}));","!function(e,o){\"object\"==typeof exports&&\"undefined\"!=typeof module?module.exports=o(require(\"dayjs\")):\"function\"==typeof define&&define.amd?define([\"dayjs\"],o):(e=\"undefined\"!=typeof globalThis?globalThis:e||self).dayjs_locale_pt_br=o(e.dayjs)}(this,(function(e){\"use strict\";function o(e){return e&&\"object\"==typeof e&&\"default\"in e?e:{default:e}}var a=o(e),s={name:\"pt-br\",weekdays:\"domingo_segunda-feira_terça-feira_quarta-feira_quinta-feira_sexta-feira_sábado\".split(\"_\"),weekdaysShort:\"dom_seg_ter_qua_qui_sex_sáb\".split(\"_\"),weekdaysMin:\"Do_2ª_3ª_4ª_5ª_6ª_Sá\".split(\"_\"),months:\"janeiro_fevereiro_março_abril_maio_junho_julho_agosto_setembro_outubro_novembro_dezembro\".split(\"_\"),monthsShort:\"jan_fev_mar_abr_mai_jun_jul_ago_set_out_nov_dez\".split(\"_\"),ordinal:function(e){return e+\"º\"},formats:{LT:\"HH:mm\",LTS:\"HH:mm:ss\",L:\"DD/MM/YYYY\",LL:\"D [de] MMMM [de] YYYY\",LLL:\"D [de] MMMM [de] YYYY [às] HH:mm\",LLLL:\"dddd, D [de] MMMM [de] YYYY [às] HH:mm\"},relativeTime:{future:\"em %s\",past:\"há %s\",s:\"poucos segundos\",m:\"um minuto\",mm:\"%d minutos\",h:\"uma hora\",hh:\"%d horas\",d:\"um dia\",dd:\"%d dias\",M:\"um mês\",MM:\"%d meses\",y:\"um ano\",yy:\"%d anos\"}};return a.default.locale(s,null,!0),s}));","!function(e,a){\"object\"==typeof exports&&\"undefined\"!=typeof module?module.exports=a(require(\"dayjs\")):\"function\"==typeof define&&define.amd?define([\"dayjs\"],a):(e=\"undefined\"!=typeof globalThis?globalThis:e||self).dayjs_locale_pt=a(e.dayjs)}(this,(function(e){\"use strict\";function a(e){return e&&\"object\"==typeof e&&\"default\"in e?e:{default:e}}var o=a(e),t={name:\"pt\",weekdays:\"domingo_segunda-feira_terça-feira_quarta-feira_quinta-feira_sexta-feira_sábado\".split(\"_\"),weekdaysShort:\"dom_seg_ter_qua_qui_sex_sab\".split(\"_\"),weekdaysMin:\"Do_2ª_3ª_4ª_5ª_6ª_Sa\".split(\"_\"),months:\"janeiro_fevereiro_março_abril_maio_junho_julho_agosto_setembro_outubro_novembro_dezembro\".split(\"_\"),monthsShort:\"jan_fev_mar_abr_mai_jun_jul_ago_set_out_nov_dez\".split(\"_\"),ordinal:function(e){return e+\"º\"},weekStart:1,yearStart:4,formats:{LT:\"HH:mm\",LTS:\"HH:mm:ss\",L:\"DD/MM/YYYY\",LL:\"D [de] MMMM [de] YYYY\",LLL:\"D [de] MMMM [de] YYYY [às] HH:mm\",LLLL:\"dddd, D [de] MMMM [de] YYYY [às] HH:mm\"},relativeTime:{future:\"em %s\",past:\"há %s\",s:\"alguns segundos\",m:\"um minuto\",mm:\"%d minutos\",h:\"uma hora\",hh:\"%d horas\",d:\"um dia\",dd:\"%d dias\",M:\"um mês\",MM:\"%d meses\",y:\"um ano\",yy:\"%d anos\"}};return o.default.locale(t,null,!0),t}));","!function(e,t){\"object\"==typeof exports&&\"undefined\"!=typeof module?module.exports=t():\"function\"==typeof define&&define.amd?define(t):(e=\"undefined\"!=typeof globalThis?globalThis:e||self).dayjs_plugin_customParseFormat=t()}(this,(function(){\"use strict\";var e={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,n=/\\d/,r=/\\d\\d/,i=/\\d\\d?/,o=/\\d*[^-_:/,()\\s\\d]+/,s={},a=function(e){return(e=+e)+(e>68?1900:2e3)};var f=function(e){return function(t){this[e]=+t}},h=[/[+-]\\d\\d:?(\\d\\d)?|Z/,function(e){(this.zone||(this.zone={})).offset=function(e){if(!e)return 0;if(\"Z\"===e)return 0;var t=e.match(/([+-]|\\d\\d)/g),n=60*t[1]+(+t[2]||0);return 0===n?0:\"+\"===t[0]?-n:n}(e)}],u=function(e){var t=s[e];return t&&(t.indexOf?t:t.s.concat(t.f))},d=function(e,t){var n,r=s.meridiem;if(r){for(var i=1;i<=24;i+=1)if(e.indexOf(r(i,0,t))>-1){n=i>12;break}}else n=e===(t?\"pm\":\"PM\");return n},c={A:[o,function(e){this.afternoon=d(e,!1)}],a:[o,function(e){this.afternoon=d(e,!0)}],Q:[n,function(e){this.month=3*(e-1)+1}],S:[n,function(e){this.milliseconds=100*+e}],SS:[r,function(e){this.milliseconds=10*+e}],SSS:[/\\d{3}/,function(e){this.milliseconds=+e}],s:[i,f(\"seconds\")],ss:[i,f(\"seconds\")],m:[i,f(\"minutes\")],mm:[i,f(\"minutes\")],H:[i,f(\"hours\")],h:[i,f(\"hours\")],HH:[i,f(\"hours\")],hh:[i,f(\"hours\")],D:[i,f(\"day\")],DD:[r,f(\"day\")],Do:[o,function(e){var t=s.ordinal,n=e.match(/\\d+/);if(this.day=n[0],t)for(var r=1;r<=31;r+=1)t(r).replace(/\\[|\\]/g,\"\")===e&&(this.day=r)}],w:[i,f(\"week\")],ww:[r,f(\"week\")],M:[i,f(\"month\")],MM:[r,f(\"month\")],MMM:[o,function(e){var t=u(\"months\"),n=(u(\"monthsShort\")||t.map((function(e){return e.slice(0,3)}))).indexOf(e)+1;if(n<1)throw new Error;this.month=n%12||n}],MMMM:[o,function(e){var t=u(\"months\").indexOf(e)+1;if(t<1)throw new Error;this.month=t%12||t}],Y:[/[+-]?\\d+/,f(\"year\")],YY:[r,function(e){this.year=a(e)}],YYYY:[/\\d{4}/,f(\"year\")],Z:h,ZZ:h};function l(n){var r,i;r=n,i=s&&s.formats;for(var o=(n=r.replace(/(\\[[^\\]]+])|(LTS?|l{1,4}|L{1,4})/g,(function(t,n,r){var o=r&&r.toUpperCase();return n||i[r]||e[r]||i[o].replace(/(\\[[^\\]]+])|(MMMM|MM|DD|dddd)/g,(function(e,t,n){return t||n.slice(1)}))}))).match(t),a=o.length,f=0;f<a;f+=1){var h=o[f],u=c[h],d=u&&u[0],l=u&&u[1];o[f]=l?{regex:d,parser:l}:h.replace(/^\\[|\\]$/g,\"\")}return function(e){for(var t={},n=0,r=0;n<a;n+=1){var i=o[n];if(\"string\"==typeof i)r+=i.length;else{var s=i.regex,f=i.parser,h=e.slice(r),u=s.exec(h)[0];f.call(t,u),e=e.replace(u,\"\")}}return function(e){var t=e.afternoon;if(void 0!==t){var n=e.hours;t?n<12&&(e.hours+=12):12===n&&(e.hours=0),delete e.afternoon}}(t),t}}return function(e,t,n){n.p.customParseFormat=!0,e&&e.parseTwoDigitYear&&(a=e.parseTwoDigitYear);var r=t.prototype,i=r.parse;r.parse=function(e){var t=e.date,r=e.utc,o=e.args;this.$u=r;var a=o[1];if(\"string\"==typeof a){var f=!0===o[2],h=!0===o[3],u=f||h,d=o[2];h&&(d=o[2]),s=this.$locale(),!f&&d&&(s=n.Ls[d]),this.$d=function(e,t,n,r){try{if([\"x\",\"X\"].indexOf(t)>-1)return new Date((\"X\"===t?1e3:1)*e);var i=l(t)(e),o=i.year,s=i.month,a=i.day,f=i.hours,h=i.minutes,u=i.seconds,d=i.milliseconds,c=i.zone,m=i.week,M=new Date,Y=a||(o||s?1:M.getDate()),p=o||M.getFullYear(),v=0;o&&!s||(v=s>0?s-1:M.getMonth());var D,w=f||0,g=h||0,y=u||0,L=d||0;return c?new Date(Date.UTC(p,v,Y,w,g,y,L+60*c.offset*1e3)):n?new Date(Date.UTC(p,v,Y,w,g,y,L)):(D=new Date(p,v,Y,w,g,y,L),m&&(D=r(D).week(m).toDate()),D)}catch(e){return new Date(\"\")}}(t,a,r,n),this.init(),d&&!0!==d&&(this.$L=this.locale(d).$L),u&&t!=this.format(a)&&(this.$d=new Date(\"\")),s={}}else if(a instanceof Array)for(var c=a.length,m=1;m<=c;m+=1){o[1]=a[m-1];var M=n.apply(this,o);if(M.isValid()){this.$d=M.$d,this.$L=M.$L,this.init();break}m===c&&(this.$d=new Date(\"\"))}else i.call(this,e)}}}));","import 'dayjs/locale/de.js'\nimport 'dayjs/locale/es-mx.js'\nimport 'dayjs/locale/es.js'\nimport 'dayjs/locale/fr.js'\nimport 'dayjs/locale/it.js'\nimport 'dayjs/locale/ja.js'\nimport 'dayjs/locale/pt-br.js'\nimport 'dayjs/locale/pt.js'\n\nimport { markLocaleAsLoaded } from '../core/locales.js'\n\nmarkLocaleAsLoaded('de')\nmarkLocaleAsLoaded('es')\nmarkLocaleAsLoaded('es-mx')\nmarkLocaleAsLoaded('fr')\nmarkLocaleAsLoaded('it')\nmarkLocaleAsLoaded('ja')\nmarkLocaleAsLoaded('pt')\nmarkLocaleAsLoaded('pt-br')\n\nexport const browserLocalesReady = true","export const SUPPORTED_LOCALES = [\n 'en',\n 'es',\n 'es-mx',\n 'fr',\n 'pt',\n 'pt-br',\n 'de',\n 'it',\n 'ja'\n] as const\n\nexport type SupportedLocale = (typeof SUPPORTED_LOCALES)[number]\nexport type LocaleInput = string\n\nconst loadedLocales = new Set<SupportedLocale>(['en'])\n\nconst localeLoaders: Record<SupportedLocale, (() => Promise<unknown>) | null> = {\n en: null,\n es: () => import('dayjs/locale/es.js'),\n 'es-mx': () => import('dayjs/locale/es-mx.js'),\n fr: () => import('dayjs/locale/fr.js'),\n pt: () => import('dayjs/locale/pt.js'),\n 'pt-br': () => import('dayjs/locale/pt-br.js'),\n de: () => import('dayjs/locale/de.js'),\n it: () => import('dayjs/locale/it.js'),\n ja: () => import('dayjs/locale/ja.js')\n}\n\nconst normalizeLocale = (locale: string): string => {\n return locale.trim().toLowerCase().replace(/_/g, '-')\n}\n\nconst asSupportedLocale = (locale: string): SupportedLocale | null => {\n if (!SUPPORTED_LOCALES.includes(locale as SupportedLocale)) {\n return null\n }\n\n return locale as SupportedLocale\n}\n\nexport const isSupportedLocale = (locale: string): boolean => {\n return resolveLocale(locale) !== null\n}\n\nexport const resolveLocale = (locale: LocaleInput): SupportedLocale | null => {\n const normalizedLocale = normalizeLocale(locale)\n const exactLocale = asSupportedLocale(normalizedLocale)\n\n if (exactLocale) {\n return exactLocale\n }\n\n const [baseLocale] = normalizedLocale.split('-')\n\n if (!baseLocale) {\n return null\n }\n\n return asSupportedLocale(baseLocale)\n}\n\nexport const markLocaleAsLoaded = (locale: SupportedLocale): void => {\n loadedLocales.add(locale)\n}\n\nexport const ensureLocaleLoaded = async (locale: SupportedLocale): Promise<void> => {\n if (loadedLocales.has(locale)) {\n return\n }\n\n const load = localeLoaders[locale]\n\n if (!load) {\n loadedLocales.add(locale)\n return\n }\n\n await load()\n loadedLocales.add(locale)\n}\n","import customParseFormat from 'dayjs/plugin/customParseFormat.js'\nimport dayjs from 'dayjs'\nimport type { Dayjs } from 'dayjs'\n\nimport { ensureLocaleLoaded, resolveLocale, SUPPORTED_LOCALES, type LocaleInput, type SupportedLocale } from './locales.js'\n\ndayjs.extend(customParseFormat)\ndayjs.locale('en')\n\nexport type DateValue = string | number | Date\n\ntype DateInputOptions = {\n input?: string | readonly string[]\n locale?: LocaleInput\n strict?: boolean\n}\n\nexport type DateParsingOptions = DateInputOptions & {\n date: DateValue\n}\n\nexport type GetDateOptions = DateInputOptions & {\n date?: DateValue\n output?: string\n invalid?: string\n}\n\nexport type DateFormatterConfig = {\n locale?: LocaleInput\n strict?: boolean\n invalid?: string\n}\n\ntype ResolvedDateFormatterConfig = {\n locale: SupportedLocale\n strict: boolean\n invalid: string\n}\n\nexport type DateFormatter = {\n getDate: (props?: GetDateOptions) => string\n parseDate: (props: DateParsingOptions) => ParseDateResult\n isValidDate: (props: DateParsingOptions) => boolean\n getSupportedLocales: () => readonly SupportedLocale[]\n getCurrentLocale: () => SupportedLocale\n setLocale: (locale: LocaleInput) => Promise<void>\n ready: Promise<void>\n}\n\nexport type ParseDateSuccess = {\n isValid: true\n locale: SupportedLocale\n date: Date\n iso: string\n timestamp: number\n format: (output?: string) => string\n}\n\nexport type ParseDateFailure = {\n isValid: false\n locale: SupportedLocale\n date: null\n iso: null\n timestamp: null\n error: string\n}\n\nexport type ParseDateResult = ParseDateSuccess | ParseDateFailure\n\nconst DEFAULT_FORMAT = 'YYYY-MM-DD'\nconst DEFAULT_LOCALE: SupportedLocale = 'en'\nconst DEFAULT_INVALID_DATE = 'Invalid Date'\nconst DEFAULT_STRICT = true\n\nconst createResolvedConfig = (\n locale: SupportedLocale,\n config?: DateFormatterConfig\n): ResolvedDateFormatterConfig => ({\n locale,\n strict: config?.strict ?? DEFAULT_STRICT,\n invalid: config?.invalid ?? DEFAULT_INVALID_DATE\n})\n\nconst getInvalidDateText = (config?: DateFormatterConfig, props?: GetDateOptions): string => {\n return props?.invalid ?? config?.invalid ?? DEFAULT_INVALID_DATE\n}\n\nconst getTargetLocale = (currentLocale: SupportedLocale, props?: GetDateOptions): SupportedLocale => {\n if (!props?.locale) {\n return currentLocale\n }\n\n return resolveLocaleOrThrow(props.locale)\n}\n\nconst getHelperLocale = <T extends { locale?: LocaleInput }>(\n config?: DateFormatterConfig,\n props?: T\n): SupportedLocale => {\n if (props?.locale) {\n return resolveLocaleOrThrow(props.locale)\n }\n\n if (config?.locale) {\n return resolveLocaleOrThrow(config.locale)\n }\n\n return DEFAULT_LOCALE\n}\n\nconst parseDateValue = (\n value: DateValue,\n input: DateParsingOptions['input'],\n locale: SupportedLocale,\n strict: boolean\n): Dayjs => {\n if (!input) {\n return dayjs(value).locale(locale)\n }\n\n if (typeof input === 'string') {\n return dayjs(value, input, locale, strict).locale(locale)\n }\n\n return dayjs(value, [...input], locale, strict).locale(locale)\n}\n\nconst createFormatterParseDate = (getConfig: () => ResolvedDateFormatterConfig) => {\n return (props: DateParsingOptions): ParseDateResult => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const parsed = parseDateValue(props.date, props.input, locale, props.strict ?? config.strict)\n\n if (!parsed.isValid()) {\n return {\n isValid: false,\n locale,\n date: null,\n iso: null,\n timestamp: null,\n error: getInvalidDateText(config, props)\n }\n }\n\n return {\n isValid: true,\n locale,\n date: parsed.toDate(),\n iso: parsed.toISOString(),\n timestamp: parsed.valueOf(),\n format: (output = DEFAULT_FORMAT) => parsed.format(output)\n }\n }\n}\n\nconst createFormatterIsValidDate = (parseDate: (props: DateParsingOptions) => ParseDateResult) => {\n return (props: DateParsingOptions): boolean => parseDate(props).isValid\n}\n\nconst createFormatterGetDate = (getConfig: () => ResolvedDateFormatterConfig) => {\n const parseDate = createFormatterParseDate(getConfig)\n\n return (props?: GetDateOptions): string => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const output = props?.output ?? DEFAULT_FORMAT\n\n if (!props) {\n return dayjs().locale(locale).format(DEFAULT_FORMAT)\n }\n\n if (props.date === undefined) {\n return dayjs().locale(locale).format(output)\n }\n\n const parsed = parseDate({\n date: props.date,\n input: props.input,\n locale: props.locale,\n strict: props.strict\n })\n\n if (!parsed.isValid) {\n return props.invalid ?? parsed.error\n }\n\n return parsed.format(output)\n }\n}\n\nfunction resolveLocaleOrThrow(locale: LocaleInput): SupportedLocale {\n const resolvedLocale = resolveLocale(locale)\n\n if (!resolvedLocale) {\n throw new Error(\n `Unsupported locale: ${locale}. The package tries an exact locale match first and then falls back to the base locale.`\n )\n }\n\n return resolvedLocale\n}\n\nexport const getSupportedLocales = (): readonly SupportedLocale[] => SUPPORTED_LOCALES\n\nexport const getDate = async (props?: GetDateOptions, config?: DateFormatterConfig): Promise<string> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.getDate(props)\n}\n\nexport const parseDate = async (\n props: DateParsingOptions,\n config?: DateFormatterConfig\n): Promise<ParseDateResult> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.parseDate(props)\n}\n\nexport const isValidDate = async (\n props: DateParsingOptions,\n config?: DateFormatterConfig\n): Promise<boolean> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.isValidDate(props)\n}\n\nexport const createDateFormatter = (config?: DateFormatterConfig): DateFormatter => {\n let currentLocale = config?.locale ? resolveLocaleOrThrow(config.locale) : DEFAULT_LOCALE\n\n const getConfig = (): ResolvedDateFormatterConfig => createResolvedConfig(currentLocale, config)\n\n const ready = ensureLocaleLoaded(currentLocale)\n const parseDate = createFormatterParseDate(getConfig)\n\n return {\n getDate: createFormatterGetDate(getConfig),\n parseDate,\n isValidDate: createFormatterIsValidDate(parseDate),\n getSupportedLocales,\n getCurrentLocale: () => currentLocale,\n setLocale: async (locale: LocaleInput) => {\n const resolvedLocale = resolveLocaleOrThrow(locale)\n\n await ensureLocaleLoaded(resolvedLocale)\n currentLocale = resolvedLocale\n },\n ready\n }\n}\n","import {\n createDateFormatter,\n getDate,\n getSupportedLocales,\n isSupportedLocale,\n isValidDate,\n parseDate,\n resolveLocale\n} from '../index.js'\n\nexport const DateKit = {\n createDateFormatter,\n getDate,\n getSupportedLocales,\n isSupportedLocale,\n parseDate,\n isValidDate,\n resolveLocale\n}\n\ndeclare global {\n interface Window {\n DateKit: typeof DateKit\n }\n}\n\nif (typeof window !== 'undefined') {\n window.DateKit = DateKit\n}\n","import { browserLocalesReady } from './preload-locales.js'\nimport { DateKit } from './global.js'\n\nif (!browserLocalesReady) {\n\tthrow new Error('Browser locales failed to preload')\n}\n\nif (typeof globalThis !== 'undefined') {\n\t;(globalThis as typeof globalThis & { DateKit?: typeof DateKit }).DateKit = DateKit\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,QAAC,SAAS,GAAE,GAAE;AAAC,oBAAU,OAAO,WAAS,eAAa,OAAO,SAAO,OAAO,UAAQ,EAAE,IAAE,cAAY,OAAO,UAAQ,OAAO,MAAI,OAAO,CAAC,KAAG,IAAE,eAAa,OAAO,aAAW,aAAW,KAAG,MAAM,QAAM,EAAE;AAAA,MAAC,GAAE,UAAM,WAAU;AAAC;AAAa,YAAI,IAAE,KAAI,IAAE,KAAI,IAAE,MAAK,IAAE,eAAc,IAAE,UAAS,IAAE,UAAS,IAAE,QAAO,IAAE,OAAM,IAAE,QAAO,IAAE,SAAQ,IAAE,WAAU,IAAE,QAAO,IAAE,QAAO,IAAE,gBAAe,IAAE,8FAA6F,IAAE,uFAAsF,IAAE,EAAC,MAAK,MAAK,UAAS,2DAA2D,MAAM,GAAG,GAAE,QAAO,wFAAwF,MAAM,GAAG,GAAE,SAAQ,SAASA,IAAE;AAAC,cAAIC,KAAE,CAAC,MAAK,MAAK,MAAK,IAAI,GAAEC,KAAEF,KAAE;AAAI,iBAAM,MAAIA,MAAGC,IAAGC,KAAE,MAAI,EAAE,KAAGD,GAAEC,EAAC,KAAGD,GAAE,CAAC,KAAG;AAAA,QAAG,EAAC,GAAE,IAAE,SAASD,IAAEC,IAAEC,IAAE;AAAC,cAAIC,KAAE,OAAOH,EAAC;AAAE,iBAAM,CAACG,MAAGA,GAAE,UAAQF,KAAED,KAAE,KAAG,MAAMC,KAAE,IAAEE,GAAE,MAAM,EAAE,KAAKD,EAAC,IAAEF;AAAA,QAAC,GAAE,IAAE,EAAC,GAAE,GAAE,GAAE,SAASA,IAA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MAAM,IAAI;AAE3E,UAAM,YAAY,MAAmC,qBAAqB,eAAe,MAAM;AAE/F,UAAM,QAAQ,mBAAmB,aAAa;AAC9C,UAAMA,aAAY,yBAAyB,SAAS;AAEpD,WAAO;AAAA,MACL,SAAS,uBAAuB,SAAS;AAAA,MACzC,WAAAA;AAAA,MACA,aAAa,2BAA2BA,UAAS;AAAA,MACjD;AAAA,MACA,kBAAkB,MAAM;AAAA,MACxB,WAAW,OAAO,WAAwB;AACxC,cAAM,iBAAiB,qBAAqB,MAAM;AAElD,cAAM,mBAAmB,cAAc;AACvC,wBAAgB;AAAA,MAClB;AAAA,MACA;AAAA,IACF;AAAA,EACF;;;ACzPO,MAAM,UAAU;AAAA,IACrB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAQA,MAAI,OAAO,WAAW,aAAa;AACjC,WAAO,UAAU;AAAA,EACnB;;;ACzBA,MAAI,CAAC,qBAAqB;AACzB,UAAM,IAAI,MAAM,mCAAmC;AAAA,EACpD;AAEA,MAAI,OAAO,eAAe,aAAa;AACtC;AAAC,IAAC,WAAgE,UAAU;AAAA,EAC7E;","names":["t","e","n","r","i","s","u","a","M","m","f","l","$","y","v","g","D","o","d","c","h","e","n","t","i","e","e","e","e","e","e","e","e","t","n","r","i","o","a","f","h","u","d","l","s","c","m","M","dayjs","customParseFormat","parseDate"]}
@@ -14,6 +14,7 @@ var SUPPORTED_LOCALES = [
14
14
  "it",
15
15
  "ja"
16
16
  ];
17
+ var loadedLocales = /* @__PURE__ */ new Set(["en"]);
17
18
  var localeLoaders = {
18
19
  en: null,
19
20
  es: () => import("dayjs/locale/es.js"),
@@ -50,11 +51,16 @@ var resolveLocale = (locale) => {
50
51
  return asSupportedLocale(baseLocale);
51
52
  };
52
53
  var ensureLocaleLoaded = async (locale) => {
54
+ if (loadedLocales.has(locale)) {
55
+ return;
56
+ }
53
57
  const load = localeLoaders[locale];
54
58
  if (!load) {
59
+ loadedLocales.add(locale);
55
60
  return;
56
61
  }
57
62
  await load();
63
+ loadedLocales.add(locale);
58
64
  };
59
65
 
60
66
  // src/core/date.ts
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/date.ts","../../src/core/locales.ts","../../src/browser/global.ts"],"sourcesContent":["import customParseFormat from 'dayjs/plugin/customParseFormat.js'\nimport dayjs from 'dayjs'\nimport type { Dayjs } from 'dayjs'\n\nimport { ensureLocaleLoaded, resolveLocale, SUPPORTED_LOCALES, type LocaleInput, type SupportedLocale } from './locales.js'\n\ndayjs.extend(customParseFormat)\ndayjs.locale('en')\n\nexport type DateValue = string | number | Date\n\ntype DateInputOptions = {\n input?: string | readonly string[]\n locale?: LocaleInput\n strict?: boolean\n}\n\nexport type DateParsingOptions = DateInputOptions & {\n date: DateValue\n}\n\nexport type GetDateOptions = DateInputOptions & {\n date?: DateValue\n output?: string\n invalid?: string\n}\n\nexport type DateFormatterConfig = {\n locale?: LocaleInput\n strict?: boolean\n invalid?: string\n}\n\ntype ResolvedDateFormatterConfig = {\n locale: SupportedLocale\n strict: boolean\n invalid: string\n}\n\nexport type DateFormatter = {\n getDate: (props?: GetDateOptions) => string\n parseDate: (props: DateParsingOptions) => ParseDateResult\n isValidDate: (props: DateParsingOptions) => boolean\n getSupportedLocales: () => readonly SupportedLocale[]\n getCurrentLocale: () => SupportedLocale\n setLocale: (locale: LocaleInput) => Promise<void>\n ready: Promise<void>\n}\n\nexport type ParseDateSuccess = {\n isValid: true\n locale: SupportedLocale\n date: Date\n iso: string\n timestamp: number\n format: (output?: string) => string\n}\n\nexport type ParseDateFailure = {\n isValid: false\n locale: SupportedLocale\n date: null\n iso: null\n timestamp: null\n error: string\n}\n\nexport type ParseDateResult = ParseDateSuccess | ParseDateFailure\n\nconst DEFAULT_FORMAT = 'YYYY-MM-DD'\nconst DEFAULT_LOCALE: SupportedLocale = 'en'\nconst DEFAULT_INVALID_DATE = 'Invalid Date'\nconst DEFAULT_STRICT = true\n\nconst createResolvedConfig = (\n locale: SupportedLocale,\n config?: DateFormatterConfig\n): ResolvedDateFormatterConfig => ({\n locale,\n strict: config?.strict ?? DEFAULT_STRICT,\n invalid: config?.invalid ?? DEFAULT_INVALID_DATE\n})\n\nconst getInvalidDateText = (config?: DateFormatterConfig, props?: GetDateOptions): string => {\n return props?.invalid ?? config?.invalid ?? DEFAULT_INVALID_DATE\n}\n\nconst getTargetLocale = (currentLocale: SupportedLocale, props?: GetDateOptions): SupportedLocale => {\n if (!props?.locale) {\n return currentLocale\n }\n\n return resolveLocaleOrThrow(props.locale)\n}\n\nconst getHelperLocale = <T extends { locale?: LocaleInput }>(\n config?: DateFormatterConfig,\n props?: T\n): SupportedLocale => {\n if (props?.locale) {\n return resolveLocaleOrThrow(props.locale)\n }\n\n if (config?.locale) {\n return resolveLocaleOrThrow(config.locale)\n }\n\n return DEFAULT_LOCALE\n}\n\nconst parseDateValue = (\n value: DateValue,\n input: DateParsingOptions['input'],\n locale: SupportedLocale,\n strict: boolean\n): Dayjs => {\n if (!input) {\n return dayjs(value).locale(locale)\n }\n\n if (typeof input === 'string') {\n return dayjs(value, input, locale, strict).locale(locale)\n }\n\n return dayjs(value, [...input], locale, strict).locale(locale)\n}\n\nconst createFormatterParseDate = (getConfig: () => ResolvedDateFormatterConfig) => {\n return (props: DateParsingOptions): ParseDateResult => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const parsed = parseDateValue(props.date, props.input, locale, props.strict ?? config.strict)\n\n if (!parsed.isValid()) {\n return {\n isValid: false,\n locale,\n date: null,\n iso: null,\n timestamp: null,\n error: getInvalidDateText(config, props)\n }\n }\n\n return {\n isValid: true,\n locale,\n date: parsed.toDate(),\n iso: parsed.toISOString(),\n timestamp: parsed.valueOf(),\n format: (output = DEFAULT_FORMAT) => parsed.format(output)\n }\n }\n}\n\nconst createFormatterIsValidDate = (parseDate: (props: DateParsingOptions) => ParseDateResult) => {\n return (props: DateParsingOptions): boolean => parseDate(props).isValid\n}\n\nconst createFormatterGetDate = (getConfig: () => ResolvedDateFormatterConfig) => {\n const parseDate = createFormatterParseDate(getConfig)\n\n return (props?: GetDateOptions): string => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const output = props?.output ?? DEFAULT_FORMAT\n\n if (!props) {\n return dayjs().locale(locale).format(DEFAULT_FORMAT)\n }\n\n if (props.date === undefined) {\n return dayjs().locale(locale).format(output)\n }\n\n const parsed = parseDate({\n date: props.date,\n input: props.input,\n locale: props.locale,\n strict: props.strict\n })\n\n if (!parsed.isValid) {\n return props.invalid ?? parsed.error\n }\n\n return parsed.format(output)\n }\n}\n\nfunction resolveLocaleOrThrow(locale: LocaleInput): SupportedLocale {\n const resolvedLocale = resolveLocale(locale)\n\n if (!resolvedLocale) {\n throw new Error(\n `Unsupported locale: ${locale}. The package tries an exact locale match first and then falls back to the base locale.`\n )\n }\n\n return resolvedLocale\n}\n\nexport const getSupportedLocales = (): readonly SupportedLocale[] => SUPPORTED_LOCALES\n\nexport const getDate = async (props?: GetDateOptions, config?: DateFormatterConfig): Promise<string> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.getDate(props)\n}\n\nexport const parseDate = async (\n props: DateParsingOptions,\n config?: DateFormatterConfig\n): Promise<ParseDateResult> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.parseDate(props)\n}\n\nexport const isValidDate = async (\n props: DateParsingOptions,\n config?: DateFormatterConfig\n): Promise<boolean> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.isValidDate(props)\n}\n\nexport const createDateFormatter = (config?: DateFormatterConfig): DateFormatter => {\n let currentLocale = config?.locale ? resolveLocaleOrThrow(config.locale) : DEFAULT_LOCALE\n\n const getConfig = (): ResolvedDateFormatterConfig => createResolvedConfig(currentLocale, config)\n\n const ready = ensureLocaleLoaded(currentLocale)\n const parseDate = createFormatterParseDate(getConfig)\n\n return {\n getDate: createFormatterGetDate(getConfig),\n parseDate,\n isValidDate: createFormatterIsValidDate(parseDate),\n getSupportedLocales,\n getCurrentLocale: () => currentLocale,\n setLocale: async (locale: LocaleInput) => {\n const resolvedLocale = resolveLocaleOrThrow(locale)\n\n await ensureLocaleLoaded(resolvedLocale)\n currentLocale = resolvedLocale\n },\n ready\n }\n}\n","export const SUPPORTED_LOCALES = [\n 'en',\n 'es',\n 'es-mx',\n 'fr',\n 'pt',\n 'pt-br',\n 'de',\n 'it',\n 'ja'\n] as const\n\nexport type SupportedLocale = (typeof SUPPORTED_LOCALES)[number]\nexport type LocaleInput = string\n\nconst localeLoaders: Record<SupportedLocale, (() => Promise<unknown>) | null> = {\n en: null,\n es: () => import('dayjs/locale/es.js'),\n 'es-mx': () => import('dayjs/locale/es-mx.js'),\n fr: () => import('dayjs/locale/fr.js'),\n pt: () => import('dayjs/locale/pt.js'),\n 'pt-br': () => import('dayjs/locale/pt-br.js'),\n de: () => import('dayjs/locale/de.js'),\n it: () => import('dayjs/locale/it.js'),\n ja: () => import('dayjs/locale/ja.js')\n}\n\nconst normalizeLocale = (locale: string): string => {\n return locale.trim().toLowerCase().replace(/_/g, '-')\n}\n\nconst asSupportedLocale = (locale: string): SupportedLocale | null => {\n if (!SUPPORTED_LOCALES.includes(locale as SupportedLocale)) {\n return null\n }\n\n return locale as SupportedLocale\n}\n\nexport const isSupportedLocale = (locale: string): boolean => {\n return resolveLocale(locale) !== null\n}\n\nexport const resolveLocale = (locale: LocaleInput): SupportedLocale | null => {\n const normalizedLocale = normalizeLocale(locale)\n const exactLocale = asSupportedLocale(normalizedLocale)\n\n if (exactLocale) {\n return exactLocale\n }\n\n const [baseLocale] = normalizedLocale.split('-')\n\n if (!baseLocale) {\n return null\n }\n\n return asSupportedLocale(baseLocale)\n}\n\nexport const ensureLocaleLoaded = async (locale: SupportedLocale): Promise<void> => {\n const load = localeLoaders[locale]\n\n if (!load) {\n return\n }\n\n await load()\n}\n","import {\n createDateFormatter,\n getDate,\n getSupportedLocales,\n isSupportedLocale,\n isValidDate,\n parseDate,\n resolveLocale\n} from '../index.js'\n\nexport const DateKit = {\n createDateFormatter,\n getDate,\n getSupportedLocales,\n isSupportedLocale,\n parseDate,\n isValidDate,\n resolveLocale\n}\n\ndeclare global {\n interface Window {\n DateKit: typeof DateKit\n }\n}\n\nif (typeof window !== 'undefined') {\n window.DateKit = DateKit\n}\n"],"mappings":";AAAA,OAAO,uBAAuB;AAC9B,OAAO,WAAW;;;ACDX,IAAM,oBAAoB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAKA,IAAM,gBAA0E;AAAA,EAC9E,IAAI;AAAA,EACJ,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,SAAS,MAAM,OAAO,uBAAuB;AAAA,EAC7C,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,SAAS,MAAM,OAAO,uBAAuB;AAAA,EAC7C,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AACvC;AAEA,IAAM,kBAAkB,CAAC,WAA2B;AAClD,SAAO,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,MAAM,GAAG;AACtD;AAEA,IAAM,oBAAoB,CAAC,WAA2C;AACpE,MAAI,CAAC,kBAAkB,SAAS,MAAyB,GAAG;AAC1D,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,IAAM,oBAAoB,CAAC,WAA4B;AAC5D,SAAO,cAAc,MAAM,MAAM;AACnC;AAEO,IAAM,gBAAgB,CAAC,WAAgD;AAC5E,QAAM,mBAAmB,gBAAgB,MAAM;AAC/C,QAAM,cAAc,kBAAkB,gBAAgB;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ACA,aAAa,2BAA2BA,UAAS;AAAA,IACjD;AAAA,IACA,kBAAkB,MAAM;AAAA,IACxB,WAAW,OAAO,WAAwB;AACxC,YAAM,iBAAiB,qBAAqB,MAAM;AAElD,YAAM,mBAAmB,cAAc;AACvC,sBAAgB;AAAA,IAClB;AAAA,IACA;AAAA,EACF;AACF;;;AEzPO,IAAM,UAAU;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAQA,IAAI,OAAO,WAAW,aAAa;AACjC,SAAO,UAAU;AACnB;","names":["parseDate"]}
1
+ {"version":3,"sources":["../../src/core/date.ts","../../src/core/locales.ts","../../src/browser/global.ts"],"sourcesContent":["import customParseFormat from 'dayjs/plugin/customParseFormat.js'\nimport dayjs from 'dayjs'\nimport type { Dayjs } from 'dayjs'\n\nimport { ensureLocaleLoaded, resolveLocale, SUPPORTED_LOCALES, type LocaleInput, type SupportedLocale } from './locales.js'\n\ndayjs.extend(customParseFormat)\ndayjs.locale('en')\n\nexport type DateValue = string | number | Date\n\ntype DateInputOptions = {\n input?: string | readonly string[]\n locale?: LocaleInput\n strict?: boolean\n}\n\nexport type DateParsingOptions = DateInputOptions & {\n date: DateValue\n}\n\nexport type GetDateOptions = DateInputOptions & {\n date?: DateValue\n output?: string\n invalid?: string\n}\n\nexport type DateFormatterConfig = {\n locale?: LocaleInput\n strict?: boolean\n invalid?: string\n}\n\ntype ResolvedDateFormatterConfig = {\n locale: SupportedLocale\n strict: boolean\n invalid: string\n}\n\nexport type DateFormatter = {\n getDate: (props?: GetDateOptions) => string\n parseDate: (props: DateParsingOptions) => ParseDateResult\n isValidDate: (props: DateParsingOptions) => boolean\n getSupportedLocales: () => readonly SupportedLocale[]\n getCurrentLocale: () => SupportedLocale\n setLocale: (locale: LocaleInput) => Promise<void>\n ready: Promise<void>\n}\n\nexport type ParseDateSuccess = {\n isValid: true\n locale: SupportedLocale\n date: Date\n iso: string\n timestamp: number\n format: (output?: string) => string\n}\n\nexport type ParseDateFailure = {\n isValid: false\n locale: SupportedLocale\n date: null\n iso: null\n timestamp: null\n error: string\n}\n\nexport type ParseDateResult = ParseDateSuccess | ParseDateFailure\n\nconst DEFAULT_FORMAT = 'YYYY-MM-DD'\nconst DEFAULT_LOCALE: SupportedLocale = 'en'\nconst DEFAULT_INVALID_DATE = 'Invalid Date'\nconst DEFAULT_STRICT = true\n\nconst createResolvedConfig = (\n locale: SupportedLocale,\n config?: DateFormatterConfig\n): ResolvedDateFormatterConfig => ({\n locale,\n strict: config?.strict ?? DEFAULT_STRICT,\n invalid: config?.invalid ?? DEFAULT_INVALID_DATE\n})\n\nconst getInvalidDateText = (config?: DateFormatterConfig, props?: GetDateOptions): string => {\n return props?.invalid ?? config?.invalid ?? DEFAULT_INVALID_DATE\n}\n\nconst getTargetLocale = (currentLocale: SupportedLocale, props?: GetDateOptions): SupportedLocale => {\n if (!props?.locale) {\n return currentLocale\n }\n\n return resolveLocaleOrThrow(props.locale)\n}\n\nconst getHelperLocale = <T extends { locale?: LocaleInput }>(\n config?: DateFormatterConfig,\n props?: T\n): SupportedLocale => {\n if (props?.locale) {\n return resolveLocaleOrThrow(props.locale)\n }\n\n if (config?.locale) {\n return resolveLocaleOrThrow(config.locale)\n }\n\n return DEFAULT_LOCALE\n}\n\nconst parseDateValue = (\n value: DateValue,\n input: DateParsingOptions['input'],\n locale: SupportedLocale,\n strict: boolean\n): Dayjs => {\n if (!input) {\n return dayjs(value).locale(locale)\n }\n\n if (typeof input === 'string') {\n return dayjs(value, input, locale, strict).locale(locale)\n }\n\n return dayjs(value, [...input], locale, strict).locale(locale)\n}\n\nconst createFormatterParseDate = (getConfig: () => ResolvedDateFormatterConfig) => {\n return (props: DateParsingOptions): ParseDateResult => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const parsed = parseDateValue(props.date, props.input, locale, props.strict ?? config.strict)\n\n if (!parsed.isValid()) {\n return {\n isValid: false,\n locale,\n date: null,\n iso: null,\n timestamp: null,\n error: getInvalidDateText(config, props)\n }\n }\n\n return {\n isValid: true,\n locale,\n date: parsed.toDate(),\n iso: parsed.toISOString(),\n timestamp: parsed.valueOf(),\n format: (output = DEFAULT_FORMAT) => parsed.format(output)\n }\n }\n}\n\nconst createFormatterIsValidDate = (parseDate: (props: DateParsingOptions) => ParseDateResult) => {\n return (props: DateParsingOptions): boolean => parseDate(props).isValid\n}\n\nconst createFormatterGetDate = (getConfig: () => ResolvedDateFormatterConfig) => {\n const parseDate = createFormatterParseDate(getConfig)\n\n return (props?: GetDateOptions): string => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const output = props?.output ?? DEFAULT_FORMAT\n\n if (!props) {\n return dayjs().locale(locale).format(DEFAULT_FORMAT)\n }\n\n if (props.date === undefined) {\n return dayjs().locale(locale).format(output)\n }\n\n const parsed = parseDate({\n date: props.date,\n input: props.input,\n locale: props.locale,\n strict: props.strict\n })\n\n if (!parsed.isValid) {\n return props.invalid ?? parsed.error\n }\n\n return parsed.format(output)\n }\n}\n\nfunction resolveLocaleOrThrow(locale: LocaleInput): SupportedLocale {\n const resolvedLocale = resolveLocale(locale)\n\n if (!resolvedLocale) {\n throw new Error(\n `Unsupported locale: ${locale}. The package tries an exact locale match first and then falls back to the base locale.`\n )\n }\n\n return resolvedLocale\n}\n\nexport const getSupportedLocales = (): readonly SupportedLocale[] => SUPPORTED_LOCALES\n\nexport const getDate = async (props?: GetDateOptions, config?: DateFormatterConfig): Promise<string> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.getDate(props)\n}\n\nexport const parseDate = async (\n props: DateParsingOptions,\n config?: DateFormatterConfig\n): Promise<ParseDateResult> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.parseDate(props)\n}\n\nexport const isValidDate = async (\n props: DateParsingOptions,\n config?: DateFormatterConfig\n): Promise<boolean> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.isValidDate(props)\n}\n\nexport const createDateFormatter = (config?: DateFormatterConfig): DateFormatter => {\n let currentLocale = config?.locale ? resolveLocaleOrThrow(config.locale) : DEFAULT_LOCALE\n\n const getConfig = (): ResolvedDateFormatterConfig => createResolvedConfig(currentLocale, config)\n\n const ready = ensureLocaleLoaded(currentLocale)\n const parseDate = createFormatterParseDate(getConfig)\n\n return {\n getDate: createFormatterGetDate(getConfig),\n parseDate,\n isValidDate: createFormatterIsValidDate(parseDate),\n getSupportedLocales,\n getCurrentLocale: () => currentLocale,\n setLocale: async (locale: LocaleInput) => {\n const resolvedLocale = resolveLocaleOrThrow(locale)\n\n await ensureLocaleLoaded(resolvedLocale)\n currentLocale = resolvedLocale\n },\n ready\n }\n}\n","export const SUPPORTED_LOCALES = [\n 'en',\n 'es',\n 'es-mx',\n 'fr',\n 'pt',\n 'pt-br',\n 'de',\n 'it',\n 'ja'\n] as const\n\nexport type SupportedLocale = (typeof SUPPORTED_LOCALES)[number]\nexport type LocaleInput = string\n\nconst loadedLocales = new Set<SupportedLocale>(['en'])\n\nconst localeLoaders: Record<SupportedLocale, (() => Promise<unknown>) | null> = {\n en: null,\n es: () => import('dayjs/locale/es.js'),\n 'es-mx': () => import('dayjs/locale/es-mx.js'),\n fr: () => import('dayjs/locale/fr.js'),\n pt: () => import('dayjs/locale/pt.js'),\n 'pt-br': () => import('dayjs/locale/pt-br.js'),\n de: () => import('dayjs/locale/de.js'),\n it: () => import('dayjs/locale/it.js'),\n ja: () => import('dayjs/locale/ja.js')\n}\n\nconst normalizeLocale = (locale: string): string => {\n return locale.trim().toLowerCase().replace(/_/g, '-')\n}\n\nconst asSupportedLocale = (locale: string): SupportedLocale | null => {\n if (!SUPPORTED_LOCALES.includes(locale as SupportedLocale)) {\n return null\n }\n\n return locale as SupportedLocale\n}\n\nexport const isSupportedLocale = (locale: string): boolean => {\n return resolveLocale(locale) !== null\n}\n\nexport const resolveLocale = (locale: LocaleInput): SupportedLocale | null => {\n const normalizedLocale = normalizeLocale(locale)\n const exactLocale = asSupportedLocale(normalizedLocale)\n\n if (exactLocale) {\n return exactLocale\n }\n\n const [baseLocale] = normalizedLocale.split('-')\n\n if (!baseLocale) {\n return null\n }\n\n return asSupportedLocale(baseLocale)\n}\n\nexport const markLocaleAsLoaded = (locale: SupportedLocale): void => {\n loadedLocales.add(locale)\n}\n\nexport const ensureLocaleLoaded = async (locale: SupportedLocale): Promise<void> => {\n if (loadedLocales.has(locale)) {\n return\n }\n\n const load = localeLoaders[locale]\n\n if (!load) {\n loadedLocales.add(locale)\n return\n }\n\n await load()\n loadedLocales.add(locale)\n}\n","import {\n createDateFormatter,\n getDate,\n getSupportedLocales,\n isSupportedLocale,\n isValidDate,\n parseDate,\n resolveLocale\n} from '../index.js'\n\nexport const DateKit = {\n createDateFormatter,\n getDate,\n getSupportedLocales,\n isSupportedLocale,\n parseDate,\n isValidDate,\n resolveLocale\n}\n\ndeclare global {\n interface Window {\n DateKit: typeof DateKit\n }\n}\n\nif (typeof window !== 'undefined') {\n window.DateKit = DateKit\n}\n"],"mappings":";AAAA,OAAO,uBAAuB;AAC9B,OAAO,WAAW;;;ACDX,IAAM,oBAAoB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAKA,IAAM,gBAAgB,oBAAI,IAAqB,CAAC,IAAI,CAAC;AAErD,IAAM,gBAA0E;AAAA,EAC9E,IAAI;AAAA,EACJ,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,SAAS,MAAM,OAAO,uBAAuB;AAAA,EAC7C,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,SAAS,MAAM,OAAO,uBAAuB;AAAA,EAC7C,IAAI,MAAM,OAAO,oBAAoB;A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AC5C,QAAM,YAAY,oBAAoB,EAAE,GAAG,QAAQ,OAAO,CAAC;AAE3D,QAAM,UAAU;AAEhB,SAAO,UAAU,UAAU,KAAK;AAClC;AAEO,IAAM,cAAc,OACzB,OACA,WACqB;AACrB,QAAM,SAAS,gBAAgB,QAAQ,KAAK;AAC5C,QAAM,YAAY,oBAAoB,EAAE,GAAG,QAAQ,OAAO,CAAC;AAE3D,QAAM,UAAU;AAEhB,SAAO,UAAU,YAAY,KAAK;AACpC;AAEO,IAAM,sBAAsB,CAAC,WAAgD;AAClF,MAAI,gBAAgB,QAAQ,SAAS,qBAAqB,OAAO,MAAM,IAAI;AAE3E,QAAM,YAAY,MAAmC,qBAAqB,eAAe,MAAM;AAE/F,QAAM,QAAQ,mBAAmB,aAAa;AAC9C,QAAMA,aAAY,yBAAyB,SAAS;AAEpD,SAAO;AAAA,IACL,SAAS,uBAAuB,SAAS;AAAA,IACzC,WAAAA;AAAA,IACA,aAAa,2BAA2BA,UAAS;AAAA,IACjD;AAAA,IACA,kBAAkB,MAAM;AAAA,IACxB,WAAW,OAAO,WAAwB;AACxC,YAAM,iBAAiB,qBAAqB,MAAM;AAElD,YAAM,mBAAmB,cAAc;AACvC,sBAAgB;AAAA,IAClB;AAAA,IACA;AAAA,EACF;AACF;;;AEzPO,IAAM,UAAU;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAQA,IAAI,OAAO,WAAW,aAAa;AACjC,SAAO,UAAU;AACnB;","names":["parseDate"]}
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ var SUPPORTED_LOCALES = [
14
14
  "it",
15
15
  "ja"
16
16
  ];
17
+ var loadedLocales = /* @__PURE__ */ new Set(["en"]);
17
18
  var localeLoaders = {
18
19
  en: null,
19
20
  es: () => import("dayjs/locale/es.js"),
@@ -50,11 +51,16 @@ var resolveLocale = (locale) => {
50
51
  return asSupportedLocale(baseLocale);
51
52
  };
52
53
  var ensureLocaleLoaded = async (locale) => {
54
+ if (loadedLocales.has(locale)) {
55
+ return;
56
+ }
53
57
  const load = localeLoaders[locale];
54
58
  if (!load) {
59
+ loadedLocales.add(locale);
55
60
  return;
56
61
  }
57
62
  await load();
63
+ loadedLocales.add(locale);
58
64
  };
59
65
 
60
66
  // src/core/date.ts
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/core/date.ts","../src/core/locales.ts"],"sourcesContent":["import customParseFormat from 'dayjs/plugin/customParseFormat.js'\nimport dayjs from 'dayjs'\nimport type { Dayjs } from 'dayjs'\n\nimport { ensureLocaleLoaded, resolveLocale, SUPPORTED_LOCALES, type LocaleInput, type SupportedLocale } from './locales.js'\n\ndayjs.extend(customParseFormat)\ndayjs.locale('en')\n\nexport type DateValue = string | number | Date\n\ntype DateInputOptions = {\n input?: string | readonly string[]\n locale?: LocaleInput\n strict?: boolean\n}\n\nexport type DateParsingOptions = DateInputOptions & {\n date: DateValue\n}\n\nexport type GetDateOptions = DateInputOptions & {\n date?: DateValue\n output?: string\n invalid?: string\n}\n\nexport type DateFormatterConfig = {\n locale?: LocaleInput\n strict?: boolean\n invalid?: string\n}\n\ntype ResolvedDateFormatterConfig = {\n locale: SupportedLocale\n strict: boolean\n invalid: string\n}\n\nexport type DateFormatter = {\n getDate: (props?: GetDateOptions) => string\n parseDate: (props: DateParsingOptions) => ParseDateResult\n isValidDate: (props: DateParsingOptions) => boolean\n getSupportedLocales: () => readonly SupportedLocale[]\n getCurrentLocale: () => SupportedLocale\n setLocale: (locale: LocaleInput) => Promise<void>\n ready: Promise<void>\n}\n\nexport type ParseDateSuccess = {\n isValid: true\n locale: SupportedLocale\n date: Date\n iso: string\n timestamp: number\n format: (output?: string) => string\n}\n\nexport type ParseDateFailure = {\n isValid: false\n locale: SupportedLocale\n date: null\n iso: null\n timestamp: null\n error: string\n}\n\nexport type ParseDateResult = ParseDateSuccess | ParseDateFailure\n\nconst DEFAULT_FORMAT = 'YYYY-MM-DD'\nconst DEFAULT_LOCALE: SupportedLocale = 'en'\nconst DEFAULT_INVALID_DATE = 'Invalid Date'\nconst DEFAULT_STRICT = true\n\nconst createResolvedConfig = (\n locale: SupportedLocale,\n config?: DateFormatterConfig\n): ResolvedDateFormatterConfig => ({\n locale,\n strict: config?.strict ?? DEFAULT_STRICT,\n invalid: config?.invalid ?? DEFAULT_INVALID_DATE\n})\n\nconst getInvalidDateText = (config?: DateFormatterConfig, props?: GetDateOptions): string => {\n return props?.invalid ?? config?.invalid ?? DEFAULT_INVALID_DATE\n}\n\nconst getTargetLocale = (currentLocale: SupportedLocale, props?: GetDateOptions): SupportedLocale => {\n if (!props?.locale) {\n return currentLocale\n }\n\n return resolveLocaleOrThrow(props.locale)\n}\n\nconst getHelperLocale = <T extends { locale?: LocaleInput }>(\n config?: DateFormatterConfig,\n props?: T\n): SupportedLocale => {\n if (props?.locale) {\n return resolveLocaleOrThrow(props.locale)\n }\n\n if (config?.locale) {\n return resolveLocaleOrThrow(config.locale)\n }\n\n return DEFAULT_LOCALE\n}\n\nconst parseDateValue = (\n value: DateValue,\n input: DateParsingOptions['input'],\n locale: SupportedLocale,\n strict: boolean\n): Dayjs => {\n if (!input) {\n return dayjs(value).locale(locale)\n }\n\n if (typeof input === 'string') {\n return dayjs(value, input, locale, strict).locale(locale)\n }\n\n return dayjs(value, [...input], locale, strict).locale(locale)\n}\n\nconst createFormatterParseDate = (getConfig: () => ResolvedDateFormatterConfig) => {\n return (props: DateParsingOptions): ParseDateResult => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const parsed = parseDateValue(props.date, props.input, locale, props.strict ?? config.strict)\n\n if (!parsed.isValid()) {\n return {\n isValid: false,\n locale,\n date: null,\n iso: null,\n timestamp: null,\n error: getInvalidDateText(config, props)\n }\n }\n\n return {\n isValid: true,\n locale,\n date: parsed.toDate(),\n iso: parsed.toISOString(),\n timestamp: parsed.valueOf(),\n format: (output = DEFAULT_FORMAT) => parsed.format(output)\n }\n }\n}\n\nconst createFormatterIsValidDate = (parseDate: (props: DateParsingOptions) => ParseDateResult) => {\n return (props: DateParsingOptions): boolean => parseDate(props).isValid\n}\n\nconst createFormatterGetDate = (getConfig: () => ResolvedDateFormatterConfig) => {\n const parseDate = createFormatterParseDate(getConfig)\n\n return (props?: GetDateOptions): string => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const output = props?.output ?? DEFAULT_FORMAT\n\n if (!props) {\n return dayjs().locale(locale).format(DEFAULT_FORMAT)\n }\n\n if (props.date === undefined) {\n return dayjs().locale(locale).format(output)\n }\n\n const parsed = parseDate({\n date: props.date,\n input: props.input,\n locale: props.locale,\n strict: props.strict\n })\n\n if (!parsed.isValid) {\n return props.invalid ?? parsed.error\n }\n\n return parsed.format(output)\n }\n}\n\nfunction resolveLocaleOrThrow(locale: LocaleInput): SupportedLocale {\n const resolvedLocale = resolveLocale(locale)\n\n if (!resolvedLocale) {\n throw new Error(\n `Unsupported locale: ${locale}. The package tries an exact locale match first and then falls back to the base locale.`\n )\n }\n\n return resolvedLocale\n}\n\nexport const getSupportedLocales = (): readonly SupportedLocale[] => SUPPORTED_LOCALES\n\nexport const getDate = async (props?: GetDateOptions, config?: DateFormatterConfig): Promise<string> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.getDate(props)\n}\n\nexport const parseDate = async (\n props: DateParsingOptions,\n config?: DateFormatterConfig\n): Promise<ParseDateResult> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.parseDate(props)\n}\n\nexport const isValidDate = async (\n props: DateParsingOptions,\n config?: DateFormatterConfig\n): Promise<boolean> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.isValidDate(props)\n}\n\nexport const createDateFormatter = (config?: DateFormatterConfig): DateFormatter => {\n let currentLocale = config?.locale ? resolveLocaleOrThrow(config.locale) : DEFAULT_LOCALE\n\n const getConfig = (): ResolvedDateFormatterConfig => createResolvedConfig(currentLocale, config)\n\n const ready = ensureLocaleLoaded(currentLocale)\n const parseDate = createFormatterParseDate(getConfig)\n\n return {\n getDate: createFormatterGetDate(getConfig),\n parseDate,\n isValidDate: createFormatterIsValidDate(parseDate),\n getSupportedLocales,\n getCurrentLocale: () => currentLocale,\n setLocale: async (locale: LocaleInput) => {\n const resolvedLocale = resolveLocaleOrThrow(locale)\n\n await ensureLocaleLoaded(resolvedLocale)\n currentLocale = resolvedLocale\n },\n ready\n }\n}\n","export const SUPPORTED_LOCALES = [\n 'en',\n 'es',\n 'es-mx',\n 'fr',\n 'pt',\n 'pt-br',\n 'de',\n 'it',\n 'ja'\n] as const\n\nexport type SupportedLocale = (typeof SUPPORTED_LOCALES)[number]\nexport type LocaleInput = string\n\nconst localeLoaders: Record<SupportedLocale, (() => Promise<unknown>) | null> = {\n en: null,\n es: () => import('dayjs/locale/es.js'),\n 'es-mx': () => import('dayjs/locale/es-mx.js'),\n fr: () => import('dayjs/locale/fr.js'),\n pt: () => import('dayjs/locale/pt.js'),\n 'pt-br': () => import('dayjs/locale/pt-br.js'),\n de: () => import('dayjs/locale/de.js'),\n it: () => import('dayjs/locale/it.js'),\n ja: () => import('dayjs/locale/ja.js')\n}\n\nconst normalizeLocale = (locale: string): string => {\n return locale.trim().toLowerCase().replace(/_/g, '-')\n}\n\nconst asSupportedLocale = (locale: string): SupportedLocale | null => {\n if (!SUPPORTED_LOCALES.includes(locale as SupportedLocale)) {\n return null\n }\n\n return locale as SupportedLocale\n}\n\nexport const isSupportedLocale = (locale: string): boolean => {\n return resolveLocale(locale) !== null\n}\n\nexport const resolveLocale = (locale: LocaleInput): SupportedLocale | null => {\n const normalizedLocale = normalizeLocale(locale)\n const exactLocale = asSupportedLocale(normalizedLocale)\n\n if (exactLocale) {\n return exactLocale\n }\n\n const [baseLocale] = normalizedLocale.split('-')\n\n if (!baseLocale) {\n return null\n }\n\n return asSupportedLocale(baseLocale)\n}\n\nexport const ensureLocaleLoaded = async (locale: SupportedLocale): Promise<void> => {\n const load = localeLoaders[locale]\n\n if (!load) {\n return\n }\n\n await load()\n}\n"],"mappings":";AAAA,OAAO,uBAAuB;AAC9B,OAAO,WAAW;;;ACDX,IAAM,oBAAoB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAKA,IAAM,gBAA0E;AAAA,EAC9E,IAAI;AAAA,EACJ,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,SAAS,MAAM,OAAO,uBAAuB;AAAA,EAC7C,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,SAAS,MAAM,OAAO,uBAAuB;AAAA,EAC7C,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AACvC;AAEA,IAAM,kBAAkB,CAAC,WAA2B;AAClD,SAAO,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,MAAM,GAAG;AACtD;AAEA,IAAM,oBAAoB,CAAC,WAA2C;AACpE,MAAI,CAAC,kBAAkB,SAAS,MAAyB,GAAG;AAC1D,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,IAAM,oBAAoB,CAAC,WAA4B;AAC5D,SAAO,cAAc,MAAM,MAAM;AACnC;AAEO,IAAM,gBAAgB,CAAC,WAAgD;AAC5E,QAAM,mBAAmB,gBAAgB,MAAM;AAC/C,QAAM,cAAc,kBAAkB,gBAAgB;AAEtD,MAAI,aAAa;AACf,WAAO;AAAA,EACT;AAEA,QAAM,CAAC,UAAU,IAAI,iBAAiB,MAAM,GAAG;AAE/C,MAAI,CAAC,YAAY;AACf,WAAO;AAAA,EACT;AAEA,SAAO,kBAAkB,UAA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BAAgB;AAAA,IAClB;AAAA,IACA;AAAA,EACF;AACF;","names":["parseDate"]}
1
+ {"version":3,"sources":["../src/core/date.ts","../src/core/locales.ts"],"sourcesContent":["import customParseFormat from 'dayjs/plugin/customParseFormat.js'\nimport dayjs from 'dayjs'\nimport type { Dayjs } from 'dayjs'\n\nimport { ensureLocaleLoaded, resolveLocale, SUPPORTED_LOCALES, type LocaleInput, type SupportedLocale } from './locales.js'\n\ndayjs.extend(customParseFormat)\ndayjs.locale('en')\n\nexport type DateValue = string | number | Date\n\ntype DateInputOptions = {\n input?: string | readonly string[]\n locale?: LocaleInput\n strict?: boolean\n}\n\nexport type DateParsingOptions = DateInputOptions & {\n date: DateValue\n}\n\nexport type GetDateOptions = DateInputOptions & {\n date?: DateValue\n output?: string\n invalid?: string\n}\n\nexport type DateFormatterConfig = {\n locale?: LocaleInput\n strict?: boolean\n invalid?: string\n}\n\ntype ResolvedDateFormatterConfig = {\n locale: SupportedLocale\n strict: boolean\n invalid: string\n}\n\nexport type DateFormatter = {\n getDate: (props?: GetDateOptions) => string\n parseDate: (props: DateParsingOptions) => ParseDateResult\n isValidDate: (props: DateParsingOptions) => boolean\n getSupportedLocales: () => readonly SupportedLocale[]\n getCurrentLocale: () => SupportedLocale\n setLocale: (locale: LocaleInput) => Promise<void>\n ready: Promise<void>\n}\n\nexport type ParseDateSuccess = {\n isValid: true\n locale: SupportedLocale\n date: Date\n iso: string\n timestamp: number\n format: (output?: string) => string\n}\n\nexport type ParseDateFailure = {\n isValid: false\n locale: SupportedLocale\n date: null\n iso: null\n timestamp: null\n error: string\n}\n\nexport type ParseDateResult = ParseDateSuccess | ParseDateFailure\n\nconst DEFAULT_FORMAT = 'YYYY-MM-DD'\nconst DEFAULT_LOCALE: SupportedLocale = 'en'\nconst DEFAULT_INVALID_DATE = 'Invalid Date'\nconst DEFAULT_STRICT = true\n\nconst createResolvedConfig = (\n locale: SupportedLocale,\n config?: DateFormatterConfig\n): ResolvedDateFormatterConfig => ({\n locale,\n strict: config?.strict ?? DEFAULT_STRICT,\n invalid: config?.invalid ?? DEFAULT_INVALID_DATE\n})\n\nconst getInvalidDateText = (config?: DateFormatterConfig, props?: GetDateOptions): string => {\n return props?.invalid ?? config?.invalid ?? DEFAULT_INVALID_DATE\n}\n\nconst getTargetLocale = (currentLocale: SupportedLocale, props?: GetDateOptions): SupportedLocale => {\n if (!props?.locale) {\n return currentLocale\n }\n\n return resolveLocaleOrThrow(props.locale)\n}\n\nconst getHelperLocale = <T extends { locale?: LocaleInput }>(\n config?: DateFormatterConfig,\n props?: T\n): SupportedLocale => {\n if (props?.locale) {\n return resolveLocaleOrThrow(props.locale)\n }\n\n if (config?.locale) {\n return resolveLocaleOrThrow(config.locale)\n }\n\n return DEFAULT_LOCALE\n}\n\nconst parseDateValue = (\n value: DateValue,\n input: DateParsingOptions['input'],\n locale: SupportedLocale,\n strict: boolean\n): Dayjs => {\n if (!input) {\n return dayjs(value).locale(locale)\n }\n\n if (typeof input === 'string') {\n return dayjs(value, input, locale, strict).locale(locale)\n }\n\n return dayjs(value, [...input], locale, strict).locale(locale)\n}\n\nconst createFormatterParseDate = (getConfig: () => ResolvedDateFormatterConfig) => {\n return (props: DateParsingOptions): ParseDateResult => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const parsed = parseDateValue(props.date, props.input, locale, props.strict ?? config.strict)\n\n if (!parsed.isValid()) {\n return {\n isValid: false,\n locale,\n date: null,\n iso: null,\n timestamp: null,\n error: getInvalidDateText(config, props)\n }\n }\n\n return {\n isValid: true,\n locale,\n date: parsed.toDate(),\n iso: parsed.toISOString(),\n timestamp: parsed.valueOf(),\n format: (output = DEFAULT_FORMAT) => parsed.format(output)\n }\n }\n}\n\nconst createFormatterIsValidDate = (parseDate: (props: DateParsingOptions) => ParseDateResult) => {\n return (props: DateParsingOptions): boolean => parseDate(props).isValid\n}\n\nconst createFormatterGetDate = (getConfig: () => ResolvedDateFormatterConfig) => {\n const parseDate = createFormatterParseDate(getConfig)\n\n return (props?: GetDateOptions): string => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const output = props?.output ?? DEFAULT_FORMAT\n\n if (!props) {\n return dayjs().locale(locale).format(DEFAULT_FORMAT)\n }\n\n if (props.date === undefined) {\n return dayjs().locale(locale).format(output)\n }\n\n const parsed = parseDate({\n date: props.date,\n input: props.input,\n locale: props.locale,\n strict: props.strict\n })\n\n if (!parsed.isValid) {\n return props.invalid ?? parsed.error\n }\n\n return parsed.format(output)\n }\n}\n\nfunction resolveLocaleOrThrow(locale: LocaleInput): SupportedLocale {\n const resolvedLocale = resolveLocale(locale)\n\n if (!resolvedLocale) {\n throw new Error(\n `Unsupported locale: ${locale}. The package tries an exact locale match first and then falls back to the base locale.`\n )\n }\n\n return resolvedLocale\n}\n\nexport const getSupportedLocales = (): readonly SupportedLocale[] => SUPPORTED_LOCALES\n\nexport const getDate = async (props?: GetDateOptions, config?: DateFormatterConfig): Promise<string> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.getDate(props)\n}\n\nexport const parseDate = async (\n props: DateParsingOptions,\n config?: DateFormatterConfig\n): Promise<ParseDateResult> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.parseDate(props)\n}\n\nexport const isValidDate = async (\n props: DateParsingOptions,\n config?: DateFormatterConfig\n): Promise<boolean> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.isValidDate(props)\n}\n\nexport const createDateFormatter = (config?: DateFormatterConfig): DateFormatter => {\n let currentLocale = config?.locale ? resolveLocaleOrThrow(config.locale) : DEFAULT_LOCALE\n\n const getConfig = (): ResolvedDateFormatterConfig => createResolvedConfig(currentLocale, config)\n\n const ready = ensureLocaleLoaded(currentLocale)\n const parseDate = createFormatterParseDate(getConfig)\n\n return {\n getDate: createFormatterGetDate(getConfig),\n parseDate,\n isValidDate: createFormatterIsValidDate(parseDate),\n getSupportedLocales,\n getCurrentLocale: () => currentLocale,\n setLocale: async (locale: LocaleInput) => {\n const resolvedLocale = resolveLocaleOrThrow(locale)\n\n await ensureLocaleLoaded(resolvedLocale)\n currentLocale = resolvedLocale\n },\n ready\n }\n}\n","export const SUPPORTED_LOCALES = [\n 'en',\n 'es',\n 'es-mx',\n 'fr',\n 'pt',\n 'pt-br',\n 'de',\n 'it',\n 'ja'\n] as const\n\nexport type SupportedLocale = (typeof SUPPORTED_LOCALES)[number]\nexport type LocaleInput = string\n\nconst loadedLocales = new Set<SupportedLocale>(['en'])\n\nconst localeLoaders: Record<SupportedLocale, (() => Promise<unknown>) | null> = {\n en: null,\n es: () => import('dayjs/locale/es.js'),\n 'es-mx': () => import('dayjs/locale/es-mx.js'),\n fr: () => import('dayjs/locale/fr.js'),\n pt: () => import('dayjs/locale/pt.js'),\n 'pt-br': () => import('dayjs/locale/pt-br.js'),\n de: () => import('dayjs/locale/de.js'),\n it: () => import('dayjs/locale/it.js'),\n ja: () => import('dayjs/locale/ja.js')\n}\n\nconst normalizeLocale = (locale: string): string => {\n return locale.trim().toLowerCase().replace(/_/g, '-')\n}\n\nconst asSupportedLocale = (locale: string): SupportedLocale | null => {\n if (!SUPPORTED_LOCALES.includes(locale as SupportedLocale)) {\n return null\n }\n\n return locale as SupportedLocale\n}\n\nexport const isSupportedLocale = (locale: string): boolean => {\n return resolveLocale(locale) !== null\n}\n\nexport const resolveLocale = (locale: LocaleInput): SupportedLocale | null => {\n const normalizedLocale = normalizeLocale(locale)\n const exactLocale = asSupportedLocale(normalizedLocale)\n\n if (exactLocale) {\n return exactLocale\n }\n\n const [baseLocale] = normalizedLocale.split('-')\n\n if (!baseLocale) {\n return null\n }\n\n return asSupportedLocale(baseLocale)\n}\n\nexport const markLocaleAsLoaded = (locale: SupportedLocale): void => {\n loadedLocales.add(locale)\n}\n\nexport const ensureLocaleLoaded = async (locale: SupportedLocale): Promise<void> => {\n if (loadedLocales.has(locale)) {\n return\n }\n\n const load = localeLoaders[locale]\n\n if (!load) {\n loadedLocales.add(locale)\n return\n }\n\n await load()\n loadedLocales.add(locale)\n}\n"],"mappings":";AAAA,OAAO,uBAAuB;AAC9B,OAAO,WAAW;;;ACDX,IAAM,oBAAoB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAKA,IAAM,gBAAgB,oBAAI,IAAqB,CAAC,IAAI,CAAC;AAErD,IAAM,gBAA0E;AAAA,EAC9E,IAAI;AAAA,EACJ,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,SAAS,MAAM,OAAO,uBAAuB;AAAA,EAC7C,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,SAAS,MAAM,OAAO,uBAAuB;AAAA,EAC7C,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AACvC;AAEA,IAAM,kBAAkB,CAAC,WAA2B;AAClD,SAAO,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,MAAM,GAAG;AACtD;AAEA,IAAM,oBAAoB,CAAC,WAA2C;AACpE,MAAI,CAAC,kBAAkB,SAAS,MAAyB,GAAG;AAC1D,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,IAAM,oBAAoB,CAAC,WAA4B;AAC5D,SAAO,cAAc,MAAM,MAAM;AACnC;AAEO,IAAM,gBAAgB,CAAC,WAAgD;AAC5E,QAAM,mBAAmB,gBAAgB,MAAM;AAC/C,QAAM,cAAc,kBAAkB,gBAAgB;AAEtD,MAAI,aAAa;AACf,WAAO;AAAA,EACT;AAEA,QAAM,CAAC,UAAU,IAAI,iBAAiB,MAAM,GAAG;AAE/C,MAAI,CAAC,YAAY;AACf,WAAO;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AS;AAAA,IACjD;AAAA,IACA,kBAAkB,MAAM;AAAA,IACxB,WAAW,OAAO,WAAwB;AACxC,YAAM,iBAAiB,qBAAqB,MAAM;AAElD,YAAM,mBAAmB,cAAc;AACvC,sBAAgB;AAAA,IAClB;AAAA,IACA;AAAA,EACF;AACF;","names":["parseDate"]}
@@ -17,6 +17,7 @@ var SUPPORTED_LOCALES = [
17
17
  "it",
18
18
  "ja"
19
19
  ];
20
+ var loadedLocales = /* @__PURE__ */ new Set(["en"]);
20
21
  var localeLoaders = {
21
22
  en: null,
22
23
  es: () => import("dayjs/locale/es.js"),
@@ -50,11 +51,16 @@ var resolveLocale = (locale) => {
50
51
  return asSupportedLocale(baseLocale);
51
52
  };
52
53
  var ensureLocaleLoaded = async (locale) => {
54
+ if (loadedLocales.has(locale)) {
55
+ return;
56
+ }
53
57
  const load = localeLoaders[locale];
54
58
  if (!load) {
59
+ loadedLocales.add(locale);
55
60
  return;
56
61
  }
57
62
  await load();
63
+ loadedLocales.add(locale);
58
64
  };
59
65
 
60
66
  // src/core/date.ts
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/react/index.ts","../../src/core/date.ts","../../src/core/locales.ts"],"sourcesContent":["import { useRef, useState } from 'react'\n\nimport {\n createDateFormatter,\n getSupportedLocales,\n type DateFormatterConfig,\n type DateParsingOptions,\n type GetDateOptions,\n type LocaleInput,\n type SupportedLocale\n} from '../index.js'\n\nexport type UseDateFormatterOptions = DateFormatterConfig\n\nexport const useDateFormatter = (options?: UseDateFormatterOptions) => {\n const formatterRef = useRef(createDateFormatter(options))\n const [locale, setLocaleState] = useState<SupportedLocale>(formatterRef.current.getCurrentLocale())\n\n return {\n locale,\n currentLocale: locale,\n getDate: (props?: GetDateOptions) => formatterRef.current.getDate(props),\n parseDate: (props: DateParsingOptions) => formatterRef.current.parseDate(props),\n isValidDate: (props: DateParsingOptions) => formatterRef.current.isValidDate(props),\n getSupportedLocales,\n ready: formatterRef.current.ready,\n setLocale: async (nextLocale: LocaleInput) => {\n await formatterRef.current.setLocale(nextLocale)\n setLocaleState(formatterRef.current.getCurrentLocale())\n }\n }\n}\n","import customParseFormat from 'dayjs/plugin/customParseFormat.js'\nimport dayjs from 'dayjs'\nimport type { Dayjs } from 'dayjs'\n\nimport { ensureLocaleLoaded, resolveLocale, SUPPORTED_LOCALES, type LocaleInput, type SupportedLocale } from './locales.js'\n\ndayjs.extend(customParseFormat)\ndayjs.locale('en')\n\nexport type DateValue = string | number | Date\n\ntype DateInputOptions = {\n input?: string | readonly string[]\n locale?: LocaleInput\n strict?: boolean\n}\n\nexport type DateParsingOptions = DateInputOptions & {\n date: DateValue\n}\n\nexport type GetDateOptions = DateInputOptions & {\n date?: DateValue\n output?: string\n invalid?: string\n}\n\nexport type DateFormatterConfig = {\n locale?: LocaleInput\n strict?: boolean\n invalid?: string\n}\n\ntype ResolvedDateFormatterConfig = {\n locale: SupportedLocale\n strict: boolean\n invalid: string\n}\n\nexport type DateFormatter = {\n getDate: (props?: GetDateOptions) => string\n parseDate: (props: DateParsingOptions) => ParseDateResult\n isValidDate: (props: DateParsingOptions) => boolean\n getSupportedLocales: () => readonly SupportedLocale[]\n getCurrentLocale: () => SupportedLocale\n setLocale: (locale: LocaleInput) => Promise<void>\n ready: Promise<void>\n}\n\nexport type ParseDateSuccess = {\n isValid: true\n locale: SupportedLocale\n date: Date\n iso: string\n timestamp: number\n format: (output?: string) => string\n}\n\nexport type ParseDateFailure = {\n isValid: false\n locale: SupportedLocale\n date: null\n iso: null\n timestamp: null\n error: string\n}\n\nexport type ParseDateResult = ParseDateSuccess | ParseDateFailure\n\nconst DEFAULT_FORMAT = 'YYYY-MM-DD'\nconst DEFAULT_LOCALE: SupportedLocale = 'en'\nconst DEFAULT_INVALID_DATE = 'Invalid Date'\nconst DEFAULT_STRICT = true\n\nconst createResolvedConfig = (\n locale: SupportedLocale,\n config?: DateFormatterConfig\n): ResolvedDateFormatterConfig => ({\n locale,\n strict: config?.strict ?? DEFAULT_STRICT,\n invalid: config?.invalid ?? DEFAULT_INVALID_DATE\n})\n\nconst getInvalidDateText = (config?: DateFormatterConfig, props?: GetDateOptions): string => {\n return props?.invalid ?? config?.invalid ?? DEFAULT_INVALID_DATE\n}\n\nconst getTargetLocale = (currentLocale: SupportedLocale, props?: GetDateOptions): SupportedLocale => {\n if (!props?.locale) {\n return currentLocale\n }\n\n return resolveLocaleOrThrow(props.locale)\n}\n\nconst getHelperLocale = <T extends { locale?: LocaleInput }>(\n config?: DateFormatterConfig,\n props?: T\n): SupportedLocale => {\n if (props?.locale) {\n return resolveLocaleOrThrow(props.locale)\n }\n\n if (config?.locale) {\n return resolveLocaleOrThrow(config.locale)\n }\n\n return DEFAULT_LOCALE\n}\n\nconst parseDateValue = (\n value: DateValue,\n input: DateParsingOptions['input'],\n locale: SupportedLocale,\n strict: boolean\n): Dayjs => {\n if (!input) {\n return dayjs(value).locale(locale)\n }\n\n if (typeof input === 'string') {\n return dayjs(value, input, locale, strict).locale(locale)\n }\n\n return dayjs(value, [...input], locale, strict).locale(locale)\n}\n\nconst createFormatterParseDate = (getConfig: () => ResolvedDateFormatterConfig) => {\n return (props: DateParsingOptions): ParseDateResult => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const parsed = parseDateValue(props.date, props.input, locale, props.strict ?? config.strict)\n\n if (!parsed.isValid()) {\n return {\n isValid: false,\n locale,\n date: null,\n iso: null,\n timestamp: null,\n error: getInvalidDateText(config, props)\n }\n }\n\n return {\n isValid: true,\n locale,\n date: parsed.toDate(),\n iso: parsed.toISOString(),\n timestamp: parsed.valueOf(),\n format: (output = DEFAULT_FORMAT) => parsed.format(output)\n }\n }\n}\n\nconst createFormatterIsValidDate = (parseDate: (props: DateParsingOptions) => ParseDateResult) => {\n return (props: DateParsingOptions): boolean => parseDate(props).isValid\n}\n\nconst createFormatterGetDate = (getConfig: () => ResolvedDateFormatterConfig) => {\n const parseDate = createFormatterParseDate(getConfig)\n\n return (props?: GetDateOptions): string => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const output = props?.output ?? DEFAULT_FORMAT\n\n if (!props) {\n return dayjs().locale(locale).format(DEFAULT_FORMAT)\n }\n\n if (props.date === undefined) {\n return dayjs().locale(locale).format(output)\n }\n\n const parsed = parseDate({\n date: props.date,\n input: props.input,\n locale: props.locale,\n strict: props.strict\n })\n\n if (!parsed.isValid) {\n return props.invalid ?? parsed.error\n }\n\n return parsed.format(output)\n }\n}\n\nfunction resolveLocaleOrThrow(locale: LocaleInput): SupportedLocale {\n const resolvedLocale = resolveLocale(locale)\n\n if (!resolvedLocale) {\n throw new Error(\n `Unsupported locale: ${locale}. The package tries an exact locale match first and then falls back to the base locale.`\n )\n }\n\n return resolvedLocale\n}\n\nexport const getSupportedLocales = (): readonly SupportedLocale[] => SUPPORTED_LOCALES\n\nexport const getDate = async (props?: GetDateOptions, config?: DateFormatterConfig): Promise<string> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.getDate(props)\n}\n\nexport const parseDate = async (\n props: DateParsingOptions,\n config?: DateFormatterConfig\n): Promise<ParseDateResult> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.parseDate(props)\n}\n\nexport const isValidDate = async (\n props: DateParsingOptions,\n config?: DateFormatterConfig\n): Promise<boolean> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.isValidDate(props)\n}\n\nexport const createDateFormatter = (config?: DateFormatterConfig): DateFormatter => {\n let currentLocale = config?.locale ? resolveLocaleOrThrow(config.locale) : DEFAULT_LOCALE\n\n const getConfig = (): ResolvedDateFormatterConfig => createResolvedConfig(currentLocale, config)\n\n const ready = ensureLocaleLoaded(currentLocale)\n const parseDate = createFormatterParseDate(getConfig)\n\n return {\n getDate: createFormatterGetDate(getConfig),\n parseDate,\n isValidDate: createFormatterIsValidDate(parseDate),\n getSupportedLocales,\n getCurrentLocale: () => currentLocale,\n setLocale: async (locale: LocaleInput) => {\n const resolvedLocale = resolveLocaleOrThrow(locale)\n\n await ensureLocaleLoaded(resolvedLocale)\n currentLocale = resolvedLocale\n },\n ready\n }\n}\n","export const SUPPORTED_LOCALES = [\n 'en',\n 'es',\n 'es-mx',\n 'fr',\n 'pt',\n 'pt-br',\n 'de',\n 'it',\n 'ja'\n] as const\n\nexport type SupportedLocale = (typeof SUPPORTED_LOCALES)[number]\nexport type LocaleInput = string\n\nconst localeLoaders: Record<SupportedLocale, (() => Promise<unknown>) | null> = {\n en: null,\n es: () => import('dayjs/locale/es.js'),\n 'es-mx': () => import('dayjs/locale/es-mx.js'),\n fr: () => import('dayjs/locale/fr.js'),\n pt: () => import('dayjs/locale/pt.js'),\n 'pt-br': () => import('dayjs/locale/pt-br.js'),\n de: () => import('dayjs/locale/de.js'),\n it: () => import('dayjs/locale/it.js'),\n ja: () => import('dayjs/locale/ja.js')\n}\n\nconst normalizeLocale = (locale: string): string => {\n return locale.trim().toLowerCase().replace(/_/g, '-')\n}\n\nconst asSupportedLocale = (locale: string): SupportedLocale | null => {\n if (!SUPPORTED_LOCALES.includes(locale as SupportedLocale)) {\n return null\n }\n\n return locale as SupportedLocale\n}\n\nexport const isSupportedLocale = (locale: string): boolean => {\n return resolveLocale(locale) !== null\n}\n\nexport const resolveLocale = (locale: LocaleInput): SupportedLocale | null => {\n const normalizedLocale = normalizeLocale(locale)\n const exactLocale = asSupportedLocale(normalizedLocale)\n\n if (exactLocale) {\n return exactLocale\n }\n\n const [baseLocale] = normalizedLocale.split('-')\n\n if (!baseLocale) {\n return null\n }\n\n return asSupportedLocale(baseLocale)\n}\n\nexport const ensureLocaleLoaded = async (locale: SupportedLocale): Promise<void> => {\n const load = localeLoaders[locale]\n\n if (!load) {\n return\n }\n\n await load()\n}\n"],"mappings":";AAAA,SAAS,QAAQ,gBAAgB;;;ACAjC,OAAO,uBAAuB;AAC9B,OAAO,WA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,uBAAuB,SAAS;AAAA,IACzC,WAAAA;AAAA,IACA,aAAa,2BAA2BA,UAAS;AAAA,IACjD;AAAA,IACA,kBAAkB,MAAM;AAAA,IACxB,WAAW,OAAO,WAAwB;AACxC,YAAM,iBAAiB,qBAAqB,MAAM;AAElD,YAAM,mBAAmB,cAAc;AACvC,sBAAgB;AAAA,IAClB;AAAA,IACA;AAAA,EACF;AACF;;;ADrPO,IAAM,mBAAmB,CAAC,YAAsC;AACrE,QAAM,eAAe,OAAO,oBAAoB,OAAO,CAAC;AACxD,QAAM,CAAC,QAAQ,cAAc,IAAI,SAA0B,aAAa,QAAQ,iBAAiB,CAAC;AAElG,SAAO;AAAA,IACL;AAAA,IACA,eAAe;AAAA,IACf,SAAS,CAAC,UAA2B,aAAa,QAAQ,QAAQ,KAAK;AAAA,IACvE,WAAW,CAAC,UAA8B,aAAa,QAAQ,UAAU,KAAK;AAAA,IAC9E,aAAa,CAAC,UAA8B,aAAa,QAAQ,YAAY,KAAK;AAAA,IAClF;AAAA,IACA,OAAO,aAAa,QAAQ;AAAA,IAC5B,WAAW,OAAO,eAA4B;AAC5C,YAAM,aAAa,QAAQ,UAAU,UAAU;AAC/C,qBAAe,aAAa,QAAQ,iBAAiB,CAAC;AAAA,IACxD;AAAA,EACF;AACF;","names":["parseDate","parseDate"]}
1
+ {"version":3,"sources":["../../src/react/index.ts","../../src/core/date.ts","../../src/core/locales.ts"],"sourcesContent":["import { useRef, useState } from 'react'\n\nimport {\n createDateFormatter,\n getSupportedLocales,\n type DateFormatterConfig,\n type DateParsingOptions,\n type GetDateOptions,\n type LocaleInput,\n type SupportedLocale\n} from '../index.js'\n\nexport type UseDateFormatterOptions = DateFormatterConfig\n\nexport const useDateFormatter = (options?: UseDateFormatterOptions) => {\n const formatterRef = useRef(createDateFormatter(options))\n const [locale, setLocaleState] = useState<SupportedLocale>(formatterRef.current.getCurrentLocale())\n\n return {\n locale,\n currentLocale: locale,\n getDate: (props?: GetDateOptions) => formatterRef.current.getDate(props),\n parseDate: (props: DateParsingOptions) => formatterRef.current.parseDate(props),\n isValidDate: (props: DateParsingOptions) => formatterRef.current.isValidDate(props),\n getSupportedLocales,\n ready: formatterRef.current.ready,\n setLocale: async (nextLocale: LocaleInput) => {\n await formatterRef.current.setLocale(nextLocale)\n setLocaleState(formatterRef.current.getCurrentLocale())\n }\n }\n}\n","import customParseFormat from 'dayjs/plugin/customParseFormat.js'\nimport dayjs from 'dayjs'\nimport type { Dayjs } from 'dayjs'\n\nimport { ensureLocaleLoaded, resolveLocale, SUPPORTED_LOCALES, type LocaleInput, type SupportedLocale } from './locales.js'\n\ndayjs.extend(customParseFormat)\ndayjs.locale('en')\n\nexport type DateValue = string | number | Date\n\ntype DateInputOptions = {\n input?: string | readonly string[]\n locale?: LocaleInput\n strict?: boolean\n}\n\nexport type DateParsingOptions = DateInputOptions & {\n date: DateValue\n}\n\nexport type GetDateOptions = DateInputOptions & {\n date?: DateValue\n output?: string\n invalid?: string\n}\n\nexport type DateFormatterConfig = {\n locale?: LocaleInput\n strict?: boolean\n invalid?: string\n}\n\ntype ResolvedDateFormatterConfig = {\n locale: SupportedLocale\n strict: boolean\n invalid: string\n}\n\nexport type DateFormatter = {\n getDate: (props?: GetDateOptions) => string\n parseDate: (props: DateParsingOptions) => ParseDateResult\n isValidDate: (props: DateParsingOptions) => boolean\n getSupportedLocales: () => readonly SupportedLocale[]\n getCurrentLocale: () => SupportedLocale\n setLocale: (locale: LocaleInput) => Promise<void>\n ready: Promise<void>\n}\n\nexport type ParseDateSuccess = {\n isValid: true\n locale: SupportedLocale\n date: Date\n iso: string\n timestamp: number\n format: (output?: string) => string\n}\n\nexport type ParseDateFailure = {\n isValid: false\n locale: SupportedLocale\n date: null\n iso: null\n timestamp: null\n error: string\n}\n\nexport type ParseDateResult = ParseDateSuccess | ParseDateFailure\n\nconst DEFAULT_FORMAT = 'YYYY-MM-DD'\nconst DEFAULT_LOCALE: SupportedLocale = 'en'\nconst DEFAULT_INVALID_DATE = 'Invalid Date'\nconst DEFAULT_STRICT = true\n\nconst createResolvedConfig = (\n locale: SupportedLocale,\n config?: DateFormatterConfig\n): ResolvedDateFormatterConfig => ({\n locale,\n strict: config?.strict ?? DEFAULT_STRICT,\n invalid: config?.invalid ?? DEFAULT_INVALID_DATE\n})\n\nconst getInvalidDateText = (config?: DateFormatterConfig, props?: GetDateOptions): string => {\n return props?.invalid ?? config?.invalid ?? DEFAULT_INVALID_DATE\n}\n\nconst getTargetLocale = (currentLocale: SupportedLocale, props?: GetDateOptions): SupportedLocale => {\n if (!props?.locale) {\n return currentLocale\n }\n\n return resolveLocaleOrThrow(props.locale)\n}\n\nconst getHelperLocale = <T extends { locale?: LocaleInput }>(\n config?: DateFormatterConfig,\n props?: T\n): SupportedLocale => {\n if (props?.locale) {\n return resolveLocaleOrThrow(props.locale)\n }\n\n if (config?.locale) {\n return resolveLocaleOrThrow(config.locale)\n }\n\n return DEFAULT_LOCALE\n}\n\nconst parseDateValue = (\n value: DateValue,\n input: DateParsingOptions['input'],\n locale: SupportedLocale,\n strict: boolean\n): Dayjs => {\n if (!input) {\n return dayjs(value).locale(locale)\n }\n\n if (typeof input === 'string') {\n return dayjs(value, input, locale, strict).locale(locale)\n }\n\n return dayjs(value, [...input], locale, strict).locale(locale)\n}\n\nconst createFormatterParseDate = (getConfig: () => ResolvedDateFormatterConfig) => {\n return (props: DateParsingOptions): ParseDateResult => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const parsed = parseDateValue(props.date, props.input, locale, props.strict ?? config.strict)\n\n if (!parsed.isValid()) {\n return {\n isValid: false,\n locale,\n date: null,\n iso: null,\n timestamp: null,\n error: getInvalidDateText(config, props)\n }\n }\n\n return {\n isValid: true,\n locale,\n date: parsed.toDate(),\n iso: parsed.toISOString(),\n timestamp: parsed.valueOf(),\n format: (output = DEFAULT_FORMAT) => parsed.format(output)\n }\n }\n}\n\nconst createFormatterIsValidDate = (parseDate: (props: DateParsingOptions) => ParseDateResult) => {\n return (props: DateParsingOptions): boolean => parseDate(props).isValid\n}\n\nconst createFormatterGetDate = (getConfig: () => ResolvedDateFormatterConfig) => {\n const parseDate = createFormatterParseDate(getConfig)\n\n return (props?: GetDateOptions): string => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const output = props?.output ?? DEFAULT_FORMAT\n\n if (!props) {\n return dayjs().locale(locale).format(DEFAULT_FORMAT)\n }\n\n if (props.date === undefined) {\n return dayjs().locale(locale).format(output)\n }\n\n const parsed = parseDate({\n date: props.date,\n input: props.input,\n locale: props.locale,\n strict: props.strict\n })\n\n if (!parsed.isValid) {\n return props.invalid ?? parsed.error\n }\n\n return parsed.format(output)\n }\n}\n\nfunction resolveLocaleOrThrow(locale: LocaleInput): SupportedLocale {\n const resolvedLocale = resolveLocale(locale)\n\n if (!resolvedLocale) {\n throw new Error(\n `Unsupported locale: ${locale}. The package tries an exact locale match first and then falls back to the base locale.`\n )\n }\n\n return resolvedLocale\n}\n\nexport const getSupportedLocales = (): readonly SupportedLocale[] => SUPPORTED_LOCALES\n\nexport const getDate = async (props?: GetDateOptions, config?: DateFormatterConfig): Promise<string> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.getDate(props)\n}\n\nexport const parseDate = async (\n props: DateParsingOptions,\n config?: DateFormatterConfig\n): Promise<ParseDateResult> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.parseDate(props)\n}\n\nexport const isValidDate = async (\n props: DateParsingOptions,\n config?: DateFormatterConfig\n): Promise<boolean> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.isValidDate(props)\n}\n\nexport const createDateFormatter = (config?: DateFormatterConfig): DateFormatter => {\n let currentLocale = config?.locale ? resolveLocaleOrThrow(config.locale) : DEFAULT_LOCALE\n\n const getConfig = (): ResolvedDateFormatterConfig => createResolvedConfig(currentLocale, config)\n\n const ready = ensureLocaleLoaded(currentLocale)\n const parseDate = createFormatterParseDate(getConfig)\n\n return {\n getDate: createFormatterGetDate(getConfig),\n parseDate,\n isValidDate: createFormatterIsValidDate(parseDate),\n getSupportedLocales,\n getCurrentLocale: () => currentLocale,\n setLocale: async (locale: LocaleInput) => {\n const resolvedLocale = resolveLocaleOrThrow(locale)\n\n await ensureLocaleLoaded(resolvedLocale)\n currentLocale = resolvedLocale\n },\n ready\n }\n}\n","export const SUPPORTED_LOCALES = [\n 'en',\n 'es',\n 'es-mx',\n 'fr',\n 'pt',\n 'pt-br',\n 'de',\n 'it',\n 'ja'\n] as const\n\nexport type SupportedLocale = (typeof SUPPORTED_LOCALES)[number]\nexport type LocaleInput = string\n\nconst loadedLocales = new Set<SupportedLocale>(['en'])\n\nconst localeLoaders: Record<SupportedLocale, (() => Promise<unknown>) | null> = {\n en: null,\n es: () => import('dayjs/locale/es.js'),\n 'es-mx': () => import('dayjs/locale/es-mx.js'),\n fr: () => import('dayjs/locale/fr.js'),\n pt: () => import('dayjs/locale/pt.js'),\n 'pt-br': () => import('dayjs/locale/pt-br.js'),\n de: () => import('dayjs/locale/de.js'),\n it: () => import('dayjs/locale/it.js'),\n ja: () => import('dayjs/locale/ja.js')\n}\n\nconst normalizeLocale = (locale: string): string => {\n return locale.trim().toLowerCase().replace(/_/g, '-')\n}\n\nconst asSupportedLocale = (locale: string): SupportedLocale | null => {\n if (!SUPPORTED_LOCALES.includes(locale as SupportedLocale)) {\n return null\n }\n\n return locale as SupportedLocale\n}\n\nexport const isSupportedLocale = (locale: string): boolean => {\n return resolveLocale(locale) !== null\n}\n\nexport const resolveLocale = (locale: LocaleInput): SupportedLocale | null => {\n const normalizedLocale = normalizeLocale(locale)\n const exactLocale = asSupportedLocale(normalizedLocale)\n\n if (exactLocale) {\n return exactLocale\n }\n\n const [baseLocale] = normalizedLocale.split('-')\n\n if (!baseLocale) {\n return null\n }\n\n return asSupportedLocale(baseLocale)\n}\n\nexport const markLocaleAsLoaded = (locale: SupportedLocale): void => {\n loadedLocales.add(locale)\n}\n\nexport const ensureLocaleLoaded = async (locale: SupportedLocale): Promise<void> => {\n if (loadedLocales.has(locale)) {\n return\n }\n\n const load = localeLoaders[locale]\n\n if (!load) {\n loadedLocales.add(locale)\n return\n }\n\n await load()\n loadedLocales.add(locale)\n}\n"],"mappings":";AAAA,SAAS,QAAQ,gBAAgB;;;ACAjC,OAAO,uBAAuB;AAC9B,OAAO,WAAW;;;ACDX,IAAM,oBAAoB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAKA,IAAM,gBAAgB,oBAAI,IAAqB,CAAC,IAAI,CAAC;AAErD,IAAM,gBAA0E;AAAA,EAC9E,IAAI;AAAA,EACJ,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,SAAS,MAAM,OAAO,uBAAuB;AAAA,EAC7C,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,SAAS,MAAM,OAAO,uBAAuB;AAAA,EAC7C,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AACvC;AAEA,IAAM,kBAAkB,CAAC,WAA2B;AAClD,SAAO,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,MAAM,GAAG;AACtD;AAEA,IAAM,oBAAoB,CAAC,WAA2C;AACpE,MAAI,CAAC,kBAAkB,SAAS,MAAyB,GAAG;AAC1D,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAMO,IAAM,gBAAgB,CAAC,WAAgD;AAC5E,QAAM,mBAAmB,gBAAgB,MAAM;AAC/C,QAAM,cAAc,kBAAkB,gBAAgB;AAEtD,MAAI,aAAa;AACf,WAAO;AAAA,EACT;AAEA,QAAM,CA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CAAC;AAAA,IACxD;AAAA,EACF;AACF;","names":["parseDate","parseDate"]}
@@ -17,6 +17,7 @@ var SUPPORTED_LOCALES = [
17
17
  "it",
18
18
  "ja"
19
19
  ];
20
+ var loadedLocales = /* @__PURE__ */ new Set(["en"]);
20
21
  var localeLoaders = {
21
22
  en: null,
22
23
  es: () => import("dayjs/locale/es.js"),
@@ -50,11 +51,16 @@ var resolveLocale = (locale) => {
50
51
  return asSupportedLocale(baseLocale);
51
52
  };
52
53
  var ensureLocaleLoaded = async (locale) => {
54
+ if (loadedLocales.has(locale)) {
55
+ return;
56
+ }
53
57
  const load = localeLoaders[locale];
54
58
  if (!load) {
59
+ loadedLocales.add(locale);
55
60
  return;
56
61
  }
57
62
  await load();
63
+ loadedLocales.add(locale);
58
64
  };
59
65
 
60
66
  // src/core/date.ts
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/svelte/index.ts","../../src/core/date.ts","../../src/core/locales.ts"],"sourcesContent":["import { get, writable } from 'svelte/store'\n\nimport {\n createDateFormatter,\n getSupportedLocales,\n type DateFormatterConfig,\n type DateParsingOptions,\n type GetDateOptions,\n type LocaleInput,\n type SupportedLocale\n} from '../index.js'\n\nexport type CreateDateFormatterStoreOptions = DateFormatterConfig\n\nexport const createDateFormatterStore = (options?: CreateDateFormatterStoreOptions) => {\n const formatter = createDateFormatter(options)\n const locale = writable<SupportedLocale>(formatter.getCurrentLocale())\n\n return {\n locale: {\n subscribe: locale.subscribe\n },\n currentLocale: () => get(locale),\n getDate: (props?: GetDateOptions) => formatter.getDate(props),\n parseDate: (props: DateParsingOptions) => formatter.parseDate(props),\n isValidDate: (props: DateParsingOptions) => formatter.isValidDate(props),\n getSupportedLocales,\n ready: formatter.ready,\n setLocale: async (nextLocale: LocaleInput) => {\n await formatter.setLocale(nextLocale)\n locale.set(formatter.getCurrentLocale())\n },\n getLocale: () => get(locale)\n }\n}\n","import customParseFormat from 'dayjs/plugin/customParseFormat.js'\nimport dayjs from 'dayjs'\nimport type { Dayjs } from 'dayjs'\n\nimport { ensureLocaleLoaded, resolveLocale, SUPPORTED_LOCALES, type LocaleInput, type SupportedLocale } from './locales.js'\n\ndayjs.extend(customParseFormat)\ndayjs.locale('en')\n\nexport type DateValue = string | number | Date\n\ntype DateInputOptions = {\n input?: string | readonly string[]\n locale?: LocaleInput\n strict?: boolean\n}\n\nexport type DateParsingOptions = DateInputOptions & {\n date: DateValue\n}\n\nexport type GetDateOptions = DateInputOptions & {\n date?: DateValue\n output?: string\n invalid?: string\n}\n\nexport type DateFormatterConfig = {\n locale?: LocaleInput\n strict?: boolean\n invalid?: string\n}\n\ntype ResolvedDateFormatterConfig = {\n locale: SupportedLocale\n strict: boolean\n invalid: string\n}\n\nexport type DateFormatter = {\n getDate: (props?: GetDateOptions) => string\n parseDate: (props: DateParsingOptions) => ParseDateResult\n isValidDate: (props: DateParsingOptions) => boolean\n getSupportedLocales: () => readonly SupportedLocale[]\n getCurrentLocale: () => SupportedLocale\n setLocale: (locale: LocaleInput) => Promise<void>\n ready: Promise<void>\n}\n\nexport type ParseDateSuccess = {\n isValid: true\n locale: SupportedLocale\n date: Date\n iso: string\n timestamp: number\n format: (output?: string) => string\n}\n\nexport type ParseDateFailure = {\n isValid: false\n locale: SupportedLocale\n date: null\n iso: null\n timestamp: null\n error: string\n}\n\nexport type ParseDateResult = ParseDateSuccess | ParseDateFailure\n\nconst DEFAULT_FORMAT = 'YYYY-MM-DD'\nconst DEFAULT_LOCALE: SupportedLocale = 'en'\nconst DEFAULT_INVALID_DATE = 'Invalid Date'\nconst DEFAULT_STRICT = true\n\nconst createResolvedConfig = (\n locale: SupportedLocale,\n config?: DateFormatterConfig\n): ResolvedDateFormatterConfig => ({\n locale,\n strict: config?.strict ?? DEFAULT_STRICT,\n invalid: config?.invalid ?? DEFAULT_INVALID_DATE\n})\n\nconst getInvalidDateText = (config?: DateFormatterConfig, props?: GetDateOptions): string => {\n return props?.invalid ?? config?.invalid ?? DEFAULT_INVALID_DATE\n}\n\nconst getTargetLocale = (currentLocale: SupportedLocale, props?: GetDateOptions): SupportedLocale => {\n if (!props?.locale) {\n return currentLocale\n }\n\n return resolveLocaleOrThrow(props.locale)\n}\n\nconst getHelperLocale = <T extends { locale?: LocaleInput }>(\n config?: DateFormatterConfig,\n props?: T\n): SupportedLocale => {\n if (props?.locale) {\n return resolveLocaleOrThrow(props.locale)\n }\n\n if (config?.locale) {\n return resolveLocaleOrThrow(config.locale)\n }\n\n return DEFAULT_LOCALE\n}\n\nconst parseDateValue = (\n value: DateValue,\n input: DateParsingOptions['input'],\n locale: SupportedLocale,\n strict: boolean\n): Dayjs => {\n if (!input) {\n return dayjs(value).locale(locale)\n }\n\n if (typeof input === 'string') {\n return dayjs(value, input, locale, strict).locale(locale)\n }\n\n return dayjs(value, [...input], locale, strict).locale(locale)\n}\n\nconst createFormatterParseDate = (getConfig: () => ResolvedDateFormatterConfig) => {\n return (props: DateParsingOptions): ParseDateResult => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const parsed = parseDateValue(props.date, props.input, locale, props.strict ?? config.strict)\n\n if (!parsed.isValid()) {\n return {\n isValid: false,\n locale,\n date: null,\n iso: null,\n timestamp: null,\n error: getInvalidDateText(config, props)\n }\n }\n\n return {\n isValid: true,\n locale,\n date: parsed.toDate(),\n iso: parsed.toISOString(),\n timestamp: parsed.valueOf(),\n format: (output = DEFAULT_FORMAT) => parsed.format(output)\n }\n }\n}\n\nconst createFormatterIsValidDate = (parseDate: (props: DateParsingOptions) => ParseDateResult) => {\n return (props: DateParsingOptions): boolean => parseDate(props).isValid\n}\n\nconst createFormatterGetDate = (getConfig: () => ResolvedDateFormatterConfig) => {\n const parseDate = createFormatterParseDate(getConfig)\n\n return (props?: GetDateOptions): string => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const output = props?.output ?? DEFAULT_FORMAT\n\n if (!props) {\n return dayjs().locale(locale).format(DEFAULT_FORMAT)\n }\n\n if (props.date === undefined) {\n return dayjs().locale(locale).format(output)\n }\n\n const parsed = parseDate({\n date: props.date,\n input: props.input,\n locale: props.locale,\n strict: props.strict\n })\n\n if (!parsed.isValid) {\n return props.invalid ?? parsed.error\n }\n\n return parsed.format(output)\n }\n}\n\nfunction resolveLocaleOrThrow(locale: LocaleInput): SupportedLocale {\n const resolvedLocale = resolveLocale(locale)\n\n if (!resolvedLocale) {\n throw new Error(\n `Unsupported locale: ${locale}. The package tries an exact locale match first and then falls back to the base locale.`\n )\n }\n\n return resolvedLocale\n}\n\nexport const getSupportedLocales = (): readonly SupportedLocale[] => SUPPORTED_LOCALES\n\nexport const getDate = async (props?: GetDateOptions, config?: DateFormatterConfig): Promise<string> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.getDate(props)\n}\n\nexport const parseDate = async (\n props: DateParsingOptions,\n config?: DateFormatterConfig\n): Promise<ParseDateResult> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.parseDate(props)\n}\n\nexport const isValidDate = async (\n props: DateParsingOptions,\n config?: DateFormatterConfig\n): Promise<boolean> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.isValidDate(props)\n}\n\nexport const createDateFormatter = (config?: DateFormatterConfig): DateFormatter => {\n let currentLocale = config?.locale ? resolveLocaleOrThrow(config.locale) : DEFAULT_LOCALE\n\n const getConfig = (): ResolvedDateFormatterConfig => createResolvedConfig(currentLocale, config)\n\n const ready = ensureLocaleLoaded(currentLocale)\n const parseDate = createFormatterParseDate(getConfig)\n\n return {\n getDate: createFormatterGetDate(getConfig),\n parseDate,\n isValidDate: createFormatterIsValidDate(parseDate),\n getSupportedLocales,\n getCurrentLocale: () => currentLocale,\n setLocale: async (locale: LocaleInput) => {\n const resolvedLocale = resolveLocaleOrThrow(locale)\n\n await ensureLocaleLoaded(resolvedLocale)\n currentLocale = resolvedLocale\n },\n ready\n }\n}\n","export const SUPPORTED_LOCALES = [\n 'en',\n 'es',\n 'es-mx',\n 'fr',\n 'pt',\n 'pt-br',\n 'de',\n 'it',\n 'ja'\n] as const\n\nexport type SupportedLocale = (typeof SUPPORTED_LOCALES)[number]\nexport type LocaleInput = string\n\nconst localeLoaders: Record<SupportedLocale, (() => Promise<unknown>) | null> = {\n en: null,\n es: () => import('dayjs/locale/es.js'),\n 'es-mx': () => import('dayjs/locale/es-mx.js'),\n fr: () => import('dayjs/locale/fr.js'),\n pt: () => import('dayjs/locale/pt.js'),\n 'pt-br': () => import('dayjs/locale/pt-br.js'),\n de: () => import('dayjs/locale/de.js'),\n it: () => import('dayjs/locale/it.js'),\n ja: () => import('dayjs/locale/ja.js')\n}\n\nconst normalizeLocale = (locale: string): string => {\n return locale.trim().toLowerCase().replace(/_/g, '-')\n}\n\nconst asSupportedLocale = (locale: string): SupportedLocale | null => {\n if (!SUPPORTED_LOCALES.includes(locale as SupportedLocale)) {\n return null\n }\n\n return locale as SupportedLocale\n}\n\nexport const isSupportedLocale = (locale: string): boolean => {\n return resolveLocale(locale) !== null\n}\n\nexport const resolveLocale = (locale: LocaleInput): SupportedLocale | null => {\n const normalizedLocale = normalizeLocale(locale)\n const exactLocale = asSupportedLocale(normalizedLocale)\n\n if (exactLocale) {\n return exactLocale\n }\n\n const [baseLocale] = normalizedLocale.split('-')\n\n if (!baseLocale) {\n return null\n }\n\n return asSupportedLocale(baseLocale)\n}\n\nexport const ensureLocaleLoaded = async (locale: SupportedLocale): Promise<void> => {\n const load = localeLoaders[locale]\n\n if (!load) {\n return\n }\n\n await load()\n}\n"],"mappings":";AAAA,SAAS,KAAK,gBAAgB;;;ACA9B,OAAO,uBAAuB;AAC9B,OAAO,WAAW;;;ACDX,IAAM,oBAAoB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAKA,IAAM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YAAM,iBAAiB,qBAAqB,MAAM;AAElD,YAAM,mBAAmB,cAAc;AACvC,sBAAgB;AAAA,IAClB;AAAA,IACA;AAAA,EACF;AACF;;;ADrPO,IAAM,2BAA2B,CAAC,YAA8C;AACrF,QAAM,YAAY,oBAAoB,OAAO;AAC7C,QAAM,SAAS,SAA0B,UAAU,iBAAiB,CAAC;AAErE,SAAO;AAAA,IACL,QAAQ;AAAA,MACN,WAAW,OAAO;AAAA,IACpB;AAAA,IACA,eAAe,MAAM,IAAI,MAAM;AAAA,IAC/B,SAAS,CAAC,UAA2B,UAAU,QAAQ,KAAK;AAAA,IAC5D,WAAW,CAAC,UAA8B,UAAU,UAAU,KAAK;AAAA,IACnE,aAAa,CAAC,UAA8B,UAAU,YAAY,KAAK;AAAA,IACvE;AAAA,IACA,OAAO,UAAU;AAAA,IACjB,WAAW,OAAO,eAA4B;AAC5C,YAAM,UAAU,UAAU,UAAU;AACpC,aAAO,IAAI,UAAU,iBAAiB,CAAC;AAAA,IACzC;AAAA,IACA,WAAW,MAAM,IAAI,MAAM;AAAA,EAC7B;AACF;","names":["parseDate","parseDate"]}
1
+ {"version":3,"sources":["../../src/svelte/index.ts","../../src/core/date.ts","../../src/core/locales.ts"],"sourcesContent":["import { get, writable } from 'svelte/store'\n\nimport {\n createDateFormatter,\n getSupportedLocales,\n type DateFormatterConfig,\n type DateParsingOptions,\n type GetDateOptions,\n type LocaleInput,\n type SupportedLocale\n} from '../index.js'\n\nexport type CreateDateFormatterStoreOptions = DateFormatterConfig\n\nexport const createDateFormatterStore = (options?: CreateDateFormatterStoreOptions) => {\n const formatter = createDateFormatter(options)\n const locale = writable<SupportedLocale>(formatter.getCurrentLocale())\n\n return {\n locale: {\n subscribe: locale.subscribe\n },\n currentLocale: () => get(locale),\n getDate: (props?: GetDateOptions) => formatter.getDate(props),\n parseDate: (props: DateParsingOptions) => formatter.parseDate(props),\n isValidDate: (props: DateParsingOptions) => formatter.isValidDate(props),\n getSupportedLocales,\n ready: formatter.ready,\n setLocale: async (nextLocale: LocaleInput) => {\n await formatter.setLocale(nextLocale)\n locale.set(formatter.getCurrentLocale())\n },\n getLocale: () => get(locale)\n }\n}\n","import customParseFormat from 'dayjs/plugin/customParseFormat.js'\nimport dayjs from 'dayjs'\nimport type { Dayjs } from 'dayjs'\n\nimport { ensureLocaleLoaded, resolveLocale, SUPPORTED_LOCALES, type LocaleInput, type SupportedLocale } from './locales.js'\n\ndayjs.extend(customParseFormat)\ndayjs.locale('en')\n\nexport type DateValue = string | number | Date\n\ntype DateInputOptions = {\n input?: string | readonly string[]\n locale?: LocaleInput\n strict?: boolean\n}\n\nexport type DateParsingOptions = DateInputOptions & {\n date: DateValue\n}\n\nexport type GetDateOptions = DateInputOptions & {\n date?: DateValue\n output?: string\n invalid?: string\n}\n\nexport type DateFormatterConfig = {\n locale?: LocaleInput\n strict?: boolean\n invalid?: string\n}\n\ntype ResolvedDateFormatterConfig = {\n locale: SupportedLocale\n strict: boolean\n invalid: string\n}\n\nexport type DateFormatter = {\n getDate: (props?: GetDateOptions) => string\n parseDate: (props: DateParsingOptions) => ParseDateResult\n isValidDate: (props: DateParsingOptions) => boolean\n getSupportedLocales: () => readonly SupportedLocale[]\n getCurrentLocale: () => SupportedLocale\n setLocale: (locale: LocaleInput) => Promise<void>\n ready: Promise<void>\n}\n\nexport type ParseDateSuccess = {\n isValid: true\n locale: SupportedLocale\n date: Date\n iso: string\n timestamp: number\n format: (output?: string) => string\n}\n\nexport type ParseDateFailure = {\n isValid: false\n locale: SupportedLocale\n date: null\n iso: null\n timestamp: null\n error: string\n}\n\nexport type ParseDateResult = ParseDateSuccess | ParseDateFailure\n\nconst DEFAULT_FORMAT = 'YYYY-MM-DD'\nconst DEFAULT_LOCALE: SupportedLocale = 'en'\nconst DEFAULT_INVALID_DATE = 'Invalid Date'\nconst DEFAULT_STRICT = true\n\nconst createResolvedConfig = (\n locale: SupportedLocale,\n config?: DateFormatterConfig\n): ResolvedDateFormatterConfig => ({\n locale,\n strict: config?.strict ?? DEFAULT_STRICT,\n invalid: config?.invalid ?? DEFAULT_INVALID_DATE\n})\n\nconst getInvalidDateText = (config?: DateFormatterConfig, props?: GetDateOptions): string => {\n return props?.invalid ?? config?.invalid ?? DEFAULT_INVALID_DATE\n}\n\nconst getTargetLocale = (currentLocale: SupportedLocale, props?: GetDateOptions): SupportedLocale => {\n if (!props?.locale) {\n return currentLocale\n }\n\n return resolveLocaleOrThrow(props.locale)\n}\n\nconst getHelperLocale = <T extends { locale?: LocaleInput }>(\n config?: DateFormatterConfig,\n props?: T\n): SupportedLocale => {\n if (props?.locale) {\n return resolveLocaleOrThrow(props.locale)\n }\n\n if (config?.locale) {\n return resolveLocaleOrThrow(config.locale)\n }\n\n return DEFAULT_LOCALE\n}\n\nconst parseDateValue = (\n value: DateValue,\n input: DateParsingOptions['input'],\n locale: SupportedLocale,\n strict: boolean\n): Dayjs => {\n if (!input) {\n return dayjs(value).locale(locale)\n }\n\n if (typeof input === 'string') {\n return dayjs(value, input, locale, strict).locale(locale)\n }\n\n return dayjs(value, [...input], locale, strict).locale(locale)\n}\n\nconst createFormatterParseDate = (getConfig: () => ResolvedDateFormatterConfig) => {\n return (props: DateParsingOptions): ParseDateResult => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const parsed = parseDateValue(props.date, props.input, locale, props.strict ?? config.strict)\n\n if (!parsed.isValid()) {\n return {\n isValid: false,\n locale,\n date: null,\n iso: null,\n timestamp: null,\n error: getInvalidDateText(config, props)\n }\n }\n\n return {\n isValid: true,\n locale,\n date: parsed.toDate(),\n iso: parsed.toISOString(),\n timestamp: parsed.valueOf(),\n format: (output = DEFAULT_FORMAT) => parsed.format(output)\n }\n }\n}\n\nconst createFormatterIsValidDate = (parseDate: (props: DateParsingOptions) => ParseDateResult) => {\n return (props: DateParsingOptions): boolean => parseDate(props).isValid\n}\n\nconst createFormatterGetDate = (getConfig: () => ResolvedDateFormatterConfig) => {\n const parseDate = createFormatterParseDate(getConfig)\n\n return (props?: GetDateOptions): string => {\n const config = getConfig()\n const locale = getTargetLocale(config.locale, props)\n const output = props?.output ?? DEFAULT_FORMAT\n\n if (!props) {\n return dayjs().locale(locale).format(DEFAULT_FORMAT)\n }\n\n if (props.date === undefined) {\n return dayjs().locale(locale).format(output)\n }\n\n const parsed = parseDate({\n date: props.date,\n input: props.input,\n locale: props.locale,\n strict: props.strict\n })\n\n if (!parsed.isValid) {\n return props.invalid ?? parsed.error\n }\n\n return parsed.format(output)\n }\n}\n\nfunction resolveLocaleOrThrow(locale: LocaleInput): SupportedLocale {\n const resolvedLocale = resolveLocale(locale)\n\n if (!resolvedLocale) {\n throw new Error(\n `Unsupported locale: ${locale}. The package tries an exact locale match first and then falls back to the base locale.`\n )\n }\n\n return resolvedLocale\n}\n\nexport const getSupportedLocales = (): readonly SupportedLocale[] => SUPPORTED_LOCALES\n\nexport const getDate = async (props?: GetDateOptions, config?: DateFormatterConfig): Promise<string> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.getDate(props)\n}\n\nexport const parseDate = async (\n props: DateParsingOptions,\n config?: DateFormatterConfig\n): Promise<ParseDateResult> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.parseDate(props)\n}\n\nexport const isValidDate = async (\n props: DateParsingOptions,\n config?: DateFormatterConfig\n): Promise<boolean> => {\n const locale = getHelperLocale(config, props)\n const formatter = createDateFormatter({ ...config, locale })\n\n await formatter.ready\n\n return formatter.isValidDate(props)\n}\n\nexport const createDateFormatter = (config?: DateFormatterConfig): DateFormatter => {\n let currentLocale = config?.locale ? resolveLocaleOrThrow(config.locale) : DEFAULT_LOCALE\n\n const getConfig = (): ResolvedDateFormatterConfig => createResolvedConfig(currentLocale, config)\n\n const ready = ensureLocaleLoaded(currentLocale)\n const parseDate = createFormatterParseDate(getConfig)\n\n return {\n getDate: createFormatterGetDate(getConfig),\n parseDate,\n isValidDate: createFormatterIsValidDate(parseDate),\n getSupportedLocales,\n getCurrentLocale: () => currentLocale,\n setLocale: async (locale: LocaleInput) => {\n const resolvedLocale = resolveLocaleOrThrow(locale)\n\n await ensureLocaleLoaded(resolvedLocale)\n currentLocale = resolvedLocale\n },\n ready\n }\n}\n","export const SUPPORTED_LOCALES = [\n 'en',\n 'es',\n 'es-mx',\n 'fr',\n 'pt',\n 'pt-br',\n 'de',\n 'it',\n 'ja'\n] as const\n\nexport type SupportedLocale = (typeof SUPPORTED_LOCALES)[number]\nexport type LocaleInput = string\n\nconst loadedLocales = new Set<SupportedLocale>(['en'])\n\nconst localeLoaders: Record<SupportedLocale, (() => Promise<unknown>) | null> = {\n en: null,\n es: () => import('dayjs/locale/es.js'),\n 'es-mx': () => import('dayjs/locale/es-mx.js'),\n fr: () => import('dayjs/locale/fr.js'),\n pt: () => import('dayjs/locale/pt.js'),\n 'pt-br': () => import('dayjs/locale/pt-br.js'),\n de: () => import('dayjs/locale/de.js'),\n it: () => import('dayjs/locale/it.js'),\n ja: () => import('dayjs/locale/ja.js')\n}\n\nconst normalizeLocale = (locale: string): string => {\n return locale.trim().toLowerCase().replace(/_/g, '-')\n}\n\nconst asSupportedLocale = (locale: string): SupportedLocale | null => {\n if (!SUPPORTED_LOCALES.includes(locale as SupportedLocale)) {\n return null\n }\n\n return locale as SupportedLocale\n}\n\nexport const isSupportedLocale = (locale: string): boolean => {\n return resolveLocale(locale) !== null\n}\n\nexport const resolveLocale = (locale: LocaleInput): SupportedLocale | null => {\n const normalizedLocale = normalizeLocale(locale)\n const exactLocale = asSupportedLocale(normalizedLocale)\n\n if (exactLocale) {\n return exactLocale\n }\n\n const [baseLocale] = normalizedLocale.split('-')\n\n if (!baseLocale) {\n return null\n }\n\n return asSupportedLocale(baseLocale)\n}\n\nexport const markLocaleAsLoaded = (locale: SupportedLocale): void => {\n loadedLocales.add(locale)\n}\n\nexport const ensureLocaleLoaded = async (locale: SupportedLocale): Promise<void> => {\n if (loadedLocales.has(locale)) {\n return\n }\n\n const load = localeLoaders[locale]\n\n if (!load) {\n loadedLocales.add(locale)\n return\n }\n\n await load()\n loadedLocales.add(locale)\n}\n"],"mappings":";AAAA,SAAS,KAAK,gBAAgB;;;ACA9B,OAAO,uBAAuB;AAC9B,OAAO,WAAW;;;ACDX,IAAM,oBAAoB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAKA,IAAM,gBAAgB,oBAAI,IAAqB,CAAC,IAAI,CAAC;AAErD,IAAM,gBAA0E;AAAA,EAC9E,IAAI;AAAA,EACJ,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,SAAS,MAAM,OAAO,uBAAuB;AAAA,EAC7C,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,SAAS,MAAM,OAAO,uBAAuB;AAAA,EAC7C,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AAAA,EACrC,IAAI,MAAM,OAAO,oBAAoB;AACvC;AAEA,IAAM,kBAAkB,CAAC,WAA2B;AAClD,SAAO,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,MAAM,GAAG;AACtD;AAEA,IAAM,oBAAoB,CAAC,WAA2C;AACpE,MAAI,CAAC,kBAAkB,SAAS,MAAyB,GAAG;AAC1D,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAMO,IAAM,gBAAgB,CAAC,WAAgD;AAC5E,QAAM,mBAAmB,gBAAgB,MAAM;AAC/C,QAAM,cAAc,kBAAkB,gBAAgB;AAEtD,MAAI,aAAa;AACf,WAAO;AAAA,EACT;AAEA,QAAM,CAAC,UAAU,IAAI,iBAAiB,MAAM,GAAG;AAE/C,MAAI,CAAC,YAAY;AACf,WAAO;AAAA,EACT;AAEA,SAAO,kBAAkB,UAAU;AACrC;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14
14
  "it",
15
15
  "ja"
16
16
  ];
17
+ var loadedLocales = /* @__PURE__ */ new Set(["en"]);
17
18
  var localeLoaders = {
18
19
  en: null,
19
20
  es: () => import("dayjs/locale/es.js"),
@@ -50,11 +51,16 @@ var resolveLocale = (locale) => {
50
51
  return asSupportedLocale(baseLocale);
51
52
  };
52
53
  var ensureLocaleLoaded = async (locale) => {
54
+ if (loadedLocales.has(locale)) {
55
+ return;
56
+ }
53
57
  const load = localeLoaders[locale];
54
58
  if (!load) {
59
+ loadedLocales.add(locale);
55
60
  return;
56
61
  }
57
62
  await load();
63
+ loadedLocales.add(locale);
58
64
  };
59
65
 
60
66
  // src/core/date.ts