UNPKG

@fe6/shared

Version:

水滴共享函数集

2 lines (1 loc) 6.03 kB
const e=/(\d{3})\d{4}(\d{4})/g,t=/^1[3456789]\d{9}$/,r=/^(0[0-9]{2,3}\-)([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$/,n=/^(0[0-9]{2,3})?$/,o=/^([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$/,i=/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g,s=/\B([A-Z])/g,u=/^[0-9A-Za-z]+$/g,c=/^[\u4e00-\u9fa5]+$/g,a=/^\d+(\.\d+)?$/,l=/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/,f=/(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/,g=/(((https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/,$=(e="-")=>new RegExp(`${"string"!=typeof e||"+"===e||"*"===e?"-":e}(\\w)`,"g"),p=Object.prototype.toString,h=e=>p.call(e),w=e=>h(e).replace(/(\[object )(\w*)(\])/g,((e,t,r)=>r)),m=e=>"Arguments"===w(e),d=e=>"Number"===w(e),y=e=>"String"===w(e),b=e=>"Symbol"===w(e),z=e=>"Boolean"===w(e),A=e=>"Function"===w(e),S=e=>"Undefined"===w(e),x=e=>"Null"===w(e),N=e=>"Array"===w(e),M=e=>"Object"===w(e),O=e=>"Promise"===w(e),Z=e=>"Set"===w(e),K=e=>"WeakSet"===w(e),j=e=>"Map"===w(e),B=e=>"Date"===w(e),_=e=>{const t=e&&e.constructor,r=Object.prototype;return e===(A(t)&&t.prototype||r)},v=e=>{if(b(e))return!0;const t=Number(e);return t!=t},C=e=>{if(N(e)){return!e.length}if(y(e)){return!e.length}if(j(e)||Z(e)){return!e.size}const t=e,r=e;if(_(e))return!Object.keys(r).length;if(M(t)||m(t)){if(Object.keys(t).length>0)return!1}return!0};function E(e){if(!y(e))return!1;return f.test(e)}const{hasOwnProperty:U}=Object.prototype,k=(e,t)=>!(!M(e)||!t)&&U.call(e,t),{keys:F}=Object;function I(e={},t={}){if(!M(e)||!M(t))return{};const r={...t};return F(e).forEach((n=>{r[n]=M(e[n])?I(e[n],t[n]):N(t[n])?t[n].slice():t[n]})),r}const D=e=>{if(N(e)&&!C(e))return e.map(D);if(M(e)&&!C(e)){const t={};return F(e).forEach((r=>{t[r]=D(e[r])})),t}return e},R=()=>!("undefined"==typeof window||!window.document||!window.document.createElement),T=e=>{if(S(e))return{size:0,unit:""};let t="bytes",r=e||0,n=0;return r>0&&r<1024?(n=0,{size:r,unit:t}):(r>=1024&&r<1048576&&(n=1,t="KB"),r>=1048576&&r<1024**3&&(n=2,t="MB"),r>=1024**3&&r<1024**4&&(n=3,t="GB"),r>=1024**4&&r<1024**5&&(n=3,t="TB"),r/=1024**n,{size:Number(r.toFixed(2)),unit:t})},J=(r="")=>{if(!y(r)&&!d(r))return"";const n=String(r);return t.test(n)?n.replace(e,"$1****$2"):""},P=(e="",t)=>{if(!y(e)&&!d(e))return"";const r=String(e).split("."),n=r.length>1,o=r[0];let s="";const u=/,/g,c=u.test(o);if(!c&&!i.test(o))return"";return s=t||c?o.replace(u,""):`${o}`.replace(i,"$&,"),n?`${s}.${r[1]}`:s},G=(e="",t="-")=>{if(!y(e))return"";const r=e;return"+"!==t&&"*"!==t&&$(t).test(r)?r.replace($(t),((e,t)=>t.toUpperCase())):""},L=(e="",t="-")=>{if(!y(e))return"";const r=e;return s.test(r)?r.replace(s,`${t}$1`).toLowerCase():""},W=(e="")=>{if(!y(e))return"";const t=e,r=t.charAt(0);return/^[A-Za-z]/.test(r)?r.toUpperCase()+t.slice(1):""},q=(e,t)=>{let r="";if(M(e)){const t=e;r=F(t).reduce(((e,r)=>`${r}=${encodeURIComponent(t[r])}&${e}`),"")}if(r=r.replace(/&$/,""),y(t)){const e=t;return/\?$/.test(e)?e+r:e.replace(/\/?$/,"?")+r}return r},H=e=>{if(b(e)||v(Number(e)))return!1;return"-"===String(e)[0]},Q=e=>d(e)&&Number.isFinite(e)&&Math.floor(e)===e,V=e=>Q(e)&&!H(e),X=e=>!S(e)&&!v(e)&&d(e)&&!Q(e),Y=e=>Q(e)&&H(e),ee=(e,t,r)=>{if(v(e)||!d(e)||v(t)||!d(t))return 0;const n=e,o=t;if(r||X(n)||X(o)){const e=Math.random();return Math.min(n+e*(o-n+parseFloat(`1e-${`${e}`.length-1}`)),o)}const i=o-n+1;return Math.floor(Math.random()*i+n)},te=(e,t=0,r)=>{if(!d(e)||b(t)||!d(t))return!1;let n=t;const o=e;let i=n;return S(r)&&(n=0),!(!S(r)&&!d(r))&&(!S(r)&&d(r)&&(i=r),o>=Math.min(n,i)&&o<Math.max(n,i))},re=(e,t=0)=>(r,n)=>{if(S(r)&&S(n))return t;let o=r,i=n;if(b(o)&&b(i))return t;b(o)&&!b(i)&&(o=i),!b(o)&&b(i)&&(i=o);let s=Number(o),u=S(i)?s:Number(i);return v(s)&&v(u)?t:(v(s)&&!v(u)&&(s=u),!v(s)&&v(u)&&(u=s),e(s,u))},ne=re(((e,t)=>e+t),0),oe=re(((e,t)=>e-t),0),ie=re(((e,t)=>e*t),1),se=re(((e,t)=>e/t),1),ue=604800,ce=({prefixKey:e,storage:t}={})=>new class{constructor(){this.storage=t||localStorage,this.prefixKey=e||""}getKey(e){return y(e)?`${this.prefixKey}${e}`.toUpperCase():""}set(e,t,r){if(y(e)&&""!==e){const n=b(r)?0:Number(r),o=d(r)&&!v(n)&&n>0?(new Date).getTime()+1e3*Number(r):null,i=JSON.stringify({value:t,expire:o});this.storage.setItem(this.getKey(e),i)}}get(e,t=""){const r=this.storage.getItem(this.getKey(e));if(r){const t=JSON.parse(r),{value:n,expire:o}=t;return null===o||o>=(new Date).getTime()?n:(this.remove(this.getKey(e)),"")}return t}remove(e){this.storage.removeItem(this.getKey(e))}clear(){this.storage.clear()}},ae=()=>Math.ceil(65536*(1+Math.random())).toString(16).substring(1),le=()=>`${ae()}${ae()}${ae()}${ae()}${ae()}${ae()}${ae()}${ae()}`;function fe(e){const t=new RegExp(`(^|&)${e}=([^&]*)(&|$)`,"i"),r=window.location.href.split("?");if(!r[1])return"";const n=r[1].match(t);return n?n[2]:""}const ge=(e,t="ww")=>y(e)?String(e).replace(/[^\x00-\xff]/g,t).length:0;export{ue as DEFAULT_CACHE_TIME,ne as add,G as camelize,D as clone,re as count,ce as createStorage,I as deepMerge,se as divide,T as fileSize,W as firstCapitalize,ge as getStrLength,k as hasOwn,L as hyphenate,te as inRange,m as isArguments,N as isArray,z as isBoolean,R as isClient,B as isDate,C as isEmpty,X as isFloat,A as isFunction,Q as isInteger,j as isMap,H as isMinus,Y as isMinusInteger,v as isNaN,x as isNull,d as isNumber,M as isPlainObject,V as isPlusInteger,O as isPromise,_ as isPrototype,Z as isSet,y as isString,b as isSymbol,S as isUndefined,E as isUrl,K as isWeakSet,F as keys,w as like,P as money,ie as multiply,q as objectToQuery,p as objectToString,J as phone,ee as randomNumber,$ as reCamelize,l as reEmail,s as reHyphenate,r as reLandlineAll,n as reLandlineAreaCode,o as reLandlineTel,i as reMoneyPrettify,c as reOnlyCn,u as reOnlyEnOrNum,t as rePhone,e as rePhone344,a as rePlusNumber,f as reUrl,g as reUrlInString,fe as searchUrl,oe as subtract,h as toTypeString,le as uuid};