UNPKG

maz-ui

Version:

A standalone components library for Vue.Js 3 & Nuxt.Js 3

1 lines 5.46 kB
import{formatDate}from"@maz-ui/utils/helpers/formatDate";import dayjs from"dayjs";import{capitalize}from"@maz-ui/utils/helpers/capitalize";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf;var __hasOwnProp=Object.prototype.hasOwnProperty;var __commonJSMin=(cb,mod)=>()=>(mod||(cb((mod={exports:{}}).exports,mod),cb=null),mod.exports);var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==`object`||typeof from==`function`)for(var keys=__getOwnPropNames(from),i=0,n=keys.length,key;i<n;i++)key=keys[i],!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:(k=>from[k]).bind(null,key),enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod==null?{}:__create(__getProtoOf(mod)),__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,`default`,{value:mod,enumerable:!0}):target,mod));var import_weekday=__toESM(__commonJSMin(((exports,module)=>{(function(e,t){typeof exports==`object`&&module!==void 0?module.exports=t():typeof define==`function`&&define.amd?define(t):(e=typeof globalThis<`u`?globalThis:e||self).dayjs_plugin_weekday=t()})(exports,(function(){return function(e,t){t.prototype.weekday=function(e){var t=this.$locale().weekStart||0,i=this.$W,n=(i<t?i+7:i)-t;return this.$utils().u(e)?n:this.subtract(n,`day`).add(e,`day`)}}}))}))(),1);dayjs.extend(import_weekday.default);function getFormattedDate({value,locale,options}){let formattedDate=value?formatDate(value,locale,options):void 0;return formattedDate?capitalize(formattedDate):void 0}function getRangeFormattedDate({value,locale,options}){let startValue=getFormattedDate({value:value.start,locale,options});let endValue=getFormattedDate({value:value.end,locale,options});return startValue||endValue?`${startValue||`...`} - ${endValue||`...`}`:void 0}function getFirstDayOfMonth(value){return dayjs(value).startOf(`month`).day()}function getDaysOfWeek(locale,firstDayOfWeek){let currentDate=dayjs().locale(locale);let days=[];for(let i=0;i<7;i++){let dayName=formatDate(currentDate.day(i+firstDayOfWeek).toDate(),locale,{weekday:`short`});dayName&&days.push(dayName)}return days}function getDaysInMonth(date){return dayjs(date).daysInMonth()}function isSameDate(date,date2,unit){return dayjs(date).isSame(date2,unit)}function isSameDay(date,dayNumber){return dayjs(date).day()===dayNumber}function getISODate(value,format=`YYYY-MM-DD`){if(value)return dayjs(value).format(format)}function getRangeISODate(value,format=`YYYY-MM-DD`){if(value)return{start:getISODate(value.start,format),end:getISODate(value.end,format)}}function checkValueWithMinMaxDates({value,minDate,maxDate,format,minMaxAuto}){return minMaxAuto?minDate&&dayjs(value).isBefore(minDate)?{newValue:minDate,newCurrentDate:dayjs(minDate,format).format()}:maxDate&&dayjs(value).isAfter(maxDate)?{newValue:maxDate,newCurrentDate:dayjs(maxDate,format).format()}:{newValue:void 0,newCurrentDate:void 0}:{newValue:value,newCurrentDate:value}}function isValueDisabledWeekly({value,disabledWeekly}){return disabledWeekly.some(dayNumber=>isSameDay(value,dayNumber))}function isValueDisabledDate({value,disabledDates}){return disabledDates.some(disabledDate=>dayjs(value).isSame(dayjs(disabledDate),`date`))}function scrollToTarget(scrollContainer,target,offset=0,hasSmoothEffect=!0){scrollContainer.scrollTo({top:target.offsetTop-offset,behavior:hasSmoothEffect?`smooth`:`auto`})}function findNearestNumberInList(list,number){return list.reduce((prev,curr)=>Math.abs(curr-number)<Math.abs(prev-number)?curr:prev)}function isRangeValue(value){return!!value&&typeof value==`object`}function isValidDate(value){return!!value&&(typeof value==`string`||typeof value==`number`||value instanceof Date)&&dayjs(value).isValid()}function getDefaultsShortcuts(t){return[{label:t.lastSevenDays,identifier:`last7Days`,value:{start:dayjs().subtract(6,`day`).format(`YYYY-MM-DD`),end:dayjs().format(`YYYY-MM-DD`)}},{label:t.lastThirtyDays,identifier:`last30Days`,value:{start:dayjs().subtract(29,`day`).format(`YYYY-MM-DD`),end:dayjs().format(`YYYY-MM-DD`)}},{label:t.thisWeek,identifier:`thisWeek`,value:{start:dayjs().startOf(`week`).format(`YYYY-MM-DD`),end:dayjs().endOf(`week`).format(`YYYY-MM-DD`)}},{label:t.lastWeek,identifier:`lastWeek`,value:{start:dayjs().subtract(1,`week`).startOf(`week`).format(`YYYY-MM-DD`),end:dayjs().subtract(1,`week`).endOf(`week`).format(`YYYY-MM-DD`)}},{label:t.thisMonth,identifier:`thisMonth`,value:{start:dayjs().set(`date`,1).format(`YYYY-MM-DD`),end:dayjs().set(`date`,dayjs().daysInMonth()).format(`YYYY-MM-DD`)}},{label:t.thisYear,identifier:`thisYear`,value:{start:dayjs().startOf(`year`).format(`YYYY-MM-DD`),end:dayjs().endOf(`year`).format(`YYYY-MM-DD`)}},{label:t.lastYear,identifier:`lastYear`,value:{start:dayjs().subtract(1,`year`).startOf(`year`).format(`YYYY-MM-DD`),end:dayjs().subtract(1,`year`).endOf(`year`).format(`YYYY-MM-DD`)}}]}export{scrollToTarget as _,getDefaultsShortcuts as a,getISODate as c,isRangeValue as d,isSameDate as f,isValueDisabledWeekly as g,isValueDisabledDate as h,getDaysOfWeek as i,getRangeFormattedDate as l,isValidDate as m,findNearestNumberInList as n,getFirstDayOfMonth as o,isSameDay as p,getDaysInMonth as r,getFormattedDate as s,checkValueWithMinMaxDates as t,getRangeISODate as u,__commonJSMin as v,__toESM as y};