@minionorg/share
Version:
2 lines (1 loc) • 8.74 kB
JavaScript
(function(o,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(o=typeof globalThis<"u"?globalThis:o||self,l(o.index={}))})(this,function(o){"use strict";var z=Object.defineProperty;var B=(o,l,h)=>l in o?z(o,l,{enumerable:!0,configurable:!0,writable:!0,value:h}):o[l]=h;var H=(o,l,h)=>(B(o,typeof l!="symbol"?l+"":l,h),h);function l(e){return e.charAt(0).toUpperCase()+e.slice(1)}function h(e){if(!e)throw new SyntaxError("type is must");return function(t){return Object.prototype.toString.call(t)===`[object ${l(e)}]`}}function c(e){if(!e)throw new SyntaxError("type is must");return function(t){return Object.prototype.toString.call(t)===`[object ${l(e)}]`}}h("Function"),h("Object");class g{constructor(){}static notNull(t,r){if(t===null)throw new SyntaxError(r||"The value must not be empty")}static notEmpty(t,r){if(t.length===0)throw new SyntaxError(r||"The String must not be empty")}static errMsg(t){return function(r){return`${t}: ${r}`}}static isString(t){if(t===null)return null;if(c("string")(t))return t;throw new TypeError("The parameter type is string")}static isValidDateFormat(t){return/(^(y{4}|y{2})[.\u002f-](m{1,2})[.\u002f-](d{1,2})$)|(^(m{1,2})[.\u002f-](d{1,2})[.\u002f-]((y{4}|y{2})$))|(^(d{1,2})[.\u002f-](m{1,2})[.\u002f-]((y{4}|y{2})$))/gi.test(t)}static isTimeFormat(t){return/(^(h{1,2}):(m{1,2}):(s{1,2})$)|(^(h{1,2}):(m{1,2})$)/gi.test(t)}}H(g,"DEFAULT_NOT_NAN_EX_MESSAGE","\u9A8C\u8BC1\u7684\u503C\u4E0D\u662F\u6570\u5B57");function m(e,t){if(g.isString(e)===null)return!1;const n=/^(?:[-+]?(?:0|[1-9][0-9]*))$/,a=/^[-+]?[0-9]+$/,i=t||{},s=Object.prototype.hasOwnProperty,u=(Object.prototype.hasOwnProperty.call(i,"zeroes")&&!i.zeroes?n:a).test(e),f=parseInt(e,10);return u&&(!s.call(i,"min")||f>=i.min)&&(!s.call(i,"max")||f<=i.max)&&(!s.call(i,"lt")||f<i.lt)&&(!s.call(i,"gt")||f>i.gt)}function y(e,t){if(!c("Date")(e))throw new TypeError(`Invalid date: ${e}`);if(!m(t+""))throw new SyntaxError(`Invalid number: ${t}`);const r=new Date(e.getTime());return r.setDate(r.getDate()+(c("Number")(t)?t:+t)),r}function D(e,t){if(!c("Date")(e))throw new TypeError(`Invalid date: ${e}`);if(!m(t+""))throw new SyntaxError(`Invalid number: ${t}`);const r=new Date(e.getTime());return r.setHours(r.getHours()+(c("Number")(t)?t:+t)),r}function S(e,t){if(!c("Date")(e))throw new TypeError(`Invalid date: ${e}`);if(!m(t+""))throw new SyntaxError(`Invalid number: ${t}`);const r=new Date(e.getTime());return r.setMinutes(r.getMinutes()+(c("Number")(t)?t:+t)),r}function $(e,t){if(!c("Date")(e))throw new TypeError(`Invalid date: ${e}`);if(!m(t+""))throw new SyntaxError(`Invalid number: ${t}`);const r=new Date(e.getTime());return r.setMonth(r.getMonth()+(c("Number")(t)?t:+t)),r}function M(e,t){if(!c("Date")(e))throw new TypeError(`Invalid date: ${e}`);if(!m(t+""))throw new SyntaxError(`Invalid number: ${t}`);const r=new Date(e.getTime());return r.setSeconds(r.getSeconds()+(c("Number")(t)?t:+t)),r}function T(e,t){if(!c("Date")(e))throw new TypeError(`Invalid date: ${e}`);if(!m(t+""))throw new SyntaxError(`Invalid number: ${t}`);const r=new Date(e.getTime());return r.setFullYear(r.getFullYear()+(c("Number")(t)?t:+t)),r}function I(e,t){if(!c("Date")(e))throw new TypeError(`Invalid date: ${e}`);const r={years:0,months:0,days:0,hours:0,mins:0,secs:0},{years:n,months:a,days:i,hours:s,mins:d,secs:u}={...r,...t};if(!m(n+"")||!m(a+"")||!m(i+"")||!m(s+"")||!m(d+"")||!m(u+""))throw new SyntaxError("Invalid time values");let f=new Date(e.getTime());return f=T(f,n),f=$(f,a),f=y(f,i),f=D(f,s),f=S(f,d),f=M(f,u),f}function N(e){return/(^(y{4}|y{2})[.\u002f-](m{1,2})[.\u002f-](d{1,2})$)|(^(m{1,2})[.\u002f-](d{1,2})[.\u002f-]((y{4}|y{2})$))|(^(d{1,2})[.\u002f-](m{1,2})[.\u002f-]((y{4}|y{2})$))/gi.test(e)}function O(e,t){const r=[],n=Math.min(e.length,t.length);for(let a=0;a<n;a++)r.push([e[a],t[a]]);return r}function w(e,t){if(t={format:"YYYY/MM/DD",delimiters:["/","-"],strictMode:!1,...t},c("String")(e)&&N(t.format)){const r=t.delimiters.find(s=>t.format.indexOf(s)!==-1),n=t.strictMode?r:t.delimiters.find(s=>e.indexOf(s)!==-1),a=O(e.split(n),t.format.toLowerCase().split(r)),i={};for(const[s,d]of a){if(s.length!==d.length)return!1;i[d.charAt(0)]=s}return new Date(`${i.m}/${i.d}/${i.y}`).getDate()===+i.d}return t.strictMode?!1:c("Date")(e)}function U(e,t){const r=[],n=Math.min(e.length,t.length);for(let a=0;a<n;a++)r.push([e[a],t[a]]);return r}function p(e,t,r){const n=t.delimiters.find(d=>t.format.indexOf(d)!==-1),a=t.strictMode?n:t.delimiters.find(d=>e.indexOf(d)!==-1),i=U(e.split(a),t.format.toLowerCase().split(n)),s={};for(const[d,u]of i){if(d.length!==u.length)throw new SyntaxError(`${t.format} format is error`);s[u.charAt(0)]=d}return r.format.replace(/(y{4}|y{2})/gi,s.y).replace(/(m{1,2})/gi,s.m).replace(/(d{1,2})/gi,s.d)}function L(e,t){const r=e.getFullYear();return t.format.replace(/(y{4}|y{2})/gi,r+"").replace(/(m{1,2})/gi,a=>a.length===1?String(e.getMonth()+1):String(e.getMonth()+1).padStart(2,"0")).replace(/(d{1,2})/gi,a=>a.length===1?String(e.getDate()):String(e.getDate()).padStart(2,"0"))}function E(e){if(!g.isValidDateFormat(e.format))throw new SyntaxError(`${e.format} is not valid date format`);return function(t,r){if(r={format:"YYYY/MM/DD",delimiters:["/","-"],strictMode:!1,...r},!w(t,r))throw new SyntaxError(`${t} is not valid date`);if(c("String")(t))return p(t,r,e);if(c("Date")(t))return L(t,e)}}function v(e,t,r){const n=r||{start:void 0,finish:void 0};if(!w(e,n.start)||!w(t,n.finish))throw new SyntaxError("Invalid date values");const a=E({format:"YYYY/MM/DD"}),i=24*60*60*1e3,s=new Date(a(e,n.start)),d=new Date(a(t,n.finish)),u=Math.abs(d.getTime()-s.getTime());return Math.ceil(u/i)}function F(e){return new Date(e.getFullYear(),2,0).getDate()===29}function Y(e){switch(e.getMonth()){case 0:case 2:case 4:case 6:case 7:case 9:case 11:return 31;case 1:return F(e)?29:28;default:return 30}}function x(e){return new Date(e.getFullYear(),e.getMonth(),1)}function A(e){return new Date(e.getFullYear(),e.getMonth()+1,0)}const _={24:{default:/^([01]?\d|2[0-3]):([0-5]\d)$/,hasSecond:/^([01]?\d|2[0-3]):([0-5]\d):([0-5]\d)$/},12:{default:/^(0?\d|1[0-2]):([0-5]\d) (A|P)M$/,hasSecond:/^(0?\d|1[0-2]):([0-5]\d):([0-5]\d) (A|P)M$/}};function P(e,t){if(!c("String")(e))return!1;if(t={format:"HH:MM:SS",mode:24,...t},!g.isTimeFormat(t.format))throw new SyntaxError(`${t.format} is not valid format`);if(![24,12].includes(t.mode))throw new SyntaxError(`${t.mode} is not valid mode`);const r=t.format.match(/s/ig),n=r&&r.length>0;return _[t.mode][n?"hasSecond":"default"].test(e)}const V={24:{default:/^([01]?\d|2[0-3]):([0-5]\d)$/,hasSecond:/^([01]?\d|2[0-3]):([0-5]\d):([0-5]\d)$/},12:{default:/^(0?\d|1[0-2]):([0-5]\d) (A|P)M$/,hasSecond:/^(0?\d|1[0-2]):([0-5]\d):([0-5]\d) (A|P)M$/}};function C(e,t,r){let n;for(const a in t)if(["12","24"].includes(a)){const i=C(e,t[a],a);i&&(n=i)}else if(t[a].test(e))return{mode:r,format:a,matches:e.match(t[a])};return n}function b(e){if(!g.isTimeFormat(e.format))throw new SyntaxError(`${e.format} is not valid format`);if(![24,12].includes(e.mode))throw new SyntaxError(`${e.mode} is not valid mode`);return function(t){const r=C(t,V,void 0);if(!r)throw new SyntaxError(`${t} is not valid time`);const n={h:"",m:"",s:"",b:""};if(r.mode==="12"){const[i,s,d,u]=[...r.matches].splice(1,4);n.h=i,n.m=s,n.s=d,n.b=u,e.mode===24&&u==="P"&&(n.h=+i+12+"")}else if(r.mode==="24"){const[i,s,d]=[...r.matches].splice(1,3);n.h=i,n.m=s,n.s=d}if(e.mode===12&&!n.b){const i=+n.h;i>12?(n.h=i-12+"",n.b="P"):n.b="A"}let a=e.format.replace(/(h{1,2})/gi,n.h).replace(/(m{1,2})/gi,n.m).replace(n.s?/(s{1,2})/gi:/:(s{1,2})/gi,n.s?n.s:"");return e.mode===12&&n.b&&(a+=` ${n.b}M`),a}}function j(e){const t=new Date(e.getTime()),r=t.getUTCFullYear(),n=String(t.getUTCMonth()+1).padStart(2,"0"),a=String(t.getUTCDate()).padStart(2,"0"),i=String(t.getUTCHours()).padStart(2,"0"),s=String(t.getUTCMinutes()).padStart(2,"0"),d=String(t.getUTCSeconds()).padStart(2,"0"),u=String((t.getUTCMilliseconds()/1e3).toFixed(3).slice(2,5)).padStart(3,"0");return`${r}-${n}-${a}T${i}:${s}:${d}.${u}Z`}const W={addDays:y,addHours:D,addMinutes:S,addMonths:$,addSecs:M,addTime:I,addYears:T,dateFormatHoc:E,getDatePeriod:v,getDaysInMonth:Y,getFirstDateInMonth:x,getLastDateInMonth:A,isDate:w,isLeapYear:F,isTime:P,timeFormatHoc:b,toISOString:j};o.addDays=y,o.addHours=D,o.addMinutes=S,o.addMonths=$,o.addSecs=M,o.addTime=I,o.addYears=T,o.dateFormatHoc=E,o.default=W,o.getDatePeriod=v,o.getDaysInMonth=Y,o.getFirstDateInMonth=x,o.getLastDateInMonth=A,o.isDate=w,o.isLeapYear=F,o.isTime=P,o.timeFormatHoc=b,o.toISOString=j,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});