@yh-kit/utils 1.6.0 → 1.7.0

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.
@@ -1 +1 @@
1
- (function(i,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(i=typeof globalThis<"u"?globalThis:i||self,b(i.yhkitUtils={}))})(this,function(i){"use strict";const w=Object.assign({unique(t){return t?Array.from(new Set(t)):[]},isExist(t,r){return!t||!r?!1:t.indexOf(r)!==-1},countOfAppear(t,r){let e=0;for(const n of t)n===r&&e++;return e},indexsOfAppear(t,r){let e=-1;const n=[];do e=t.indexOf(r,e+1),e!==-1&&n.push(e);while(e!==-1);return n},sort(t,r="asc"){return t?t.sort((e,n)=>r==="asc"?e>n?1:-1:e<n?1:-1):[]},shuffle(t){if(!t)return[];for(let r=t.length-1;r>0;r--){const e=Math.floor(Math.random()*(r+1));[t[r],t[e]]=[t[e],t[r]]}return t},getMaxValue(t){return t?Math.max(...t):0},getMinValue(t){return t?Math.min(...t):0}},{...Object.freeze(Object.defineProperty({__proto__:null,toEnumObj:t=>{if(!t||!t.length)return{};const r={};return t.forEach(e=>{const n=Object.assign({label:e.label,text:e.label},e);r[e==null?void 0:e.value]=n}),r}},Symbol.toStringTag,{value:"Module"}))}),U={toBlob(t,r="",e=512){const o=(t.split(",")[1]||t).replace(/-/g,"+").replace(/_/g,"/"),s="=".repeat((4-o.length%4)%4),u=o+s;try{const a=atob(u),l=[];for(let h=0;h<a.length;h+=e){const c=a.slice(h,h+e),d=new Array(c.length);for(let f=0;f<c.length;f++)d[f]=c.charCodeAt(f);const g=new Uint8Array(d);l.push(g)}return new Blob(l,{type:r})}catch(a){return console.error("Failed to convert base64 to blob:",a),null}},toFile(t,r="file.txt",e="text/plain"){const o=t.replace(/^data:.+;base64,/,"").replace(/-/g,"+").replace(/_/g,"/"),s="=".repeat((4-o.length%4)%4),u=o+s,a=atob(u),l=[];for(let c=0;c<a.length;c+=512){const d=a.slice(c,c+512),g=new Array(d.length);for(let f=0;f<d.length;f++)g[f]=d.charCodeAt(f);l.push(new Uint8Array(g))}const h=new Blob(l,{type:e});return new File([h],r,{type:e})}},m={isEmptyString(t){return typeof t=="string"&&t.trim()===""},isNumber(t){return typeof t=="number"&&!isNaN(t)},isObject(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)},isEmptyObject(t){return t?Object.keys(t).length===0&&t.constructor===Object:!0},isBoolean(t){return typeof t=="boolean"},isArray(t){return Array.isArray(t)},isFunction(t){return typeof t=="function"},isPromise(t){return!!t&&(typeof t=="object"||typeof t=="function")&&typeof t.then=="function"},isElement(t){return t instanceof Element},isPhone(t){return/^1[3-9]\d{9}$/.test(t)},isEmail(t){return/^[\w.-]+@[\w.-]+\.\w+$/.test(t)},isJSON(t){try{return JSON.parse(t),!0}catch{return!1}},isImageLoaded(t){return t.complete&&t.naturalWidth!==0},isInViewport(t){const r=t.getBoundingClientRect();return r.top>=0&&r.left>=0&&r.bottom<=window.innerHeight&&r.right<=window.innerWidth},isLeapYear(t){return t%4===0&&t%100!==0||t%400===0},isMobile(){return/Mobi|Android|iPhone/i.test(navigator.userAgent)}},S={getCookie(t){if(!t)return;const r=document.cookie.match(new RegExp("(^| )"+t+"=([^;]+)"));return r?decodeURIComponent(r[2]):null},setCookie(t,r,e=7){const n=new Date;n.setTime(n.getTime()+e*24*60*60*1e3),document.cookie=`${t}=${encodeURIComponent(r)};expires=${n.toUTCString()};path=/`},deleteCookie(t){this.setCookie(t,"",-1)}},M={getTimeString(t,r=!1){return r?new Date().toLocaleString(t,{hour12:!0}):new Date().toLocaleString("chinese",{hour12:!1})},diffDays(t,r){const e=new Date(t).getTime(),n=new Date(r).getTime();return e>n?Math.abs(Math.floor((e-n)/(24*3600*1e3))):Math.abs(Math.floor((n-e)/(24*3600*1e3)))},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)},getWhichDays(t,r,e){let n=e;for(let o=1;o<r;o++)switch(o){case 1:case 3:case 5:case 7:case 8:case 10:case 12:n+=31;break;case 2:m.isLeapYear(t)?n+=29:n+=28;break;default:n+=30;break}return n}},O={getOffsetTop(t){if(!t)throw new Error("Element is not provided");if(t instanceof SVGElement){const e=t.getBoundingClientRect(),n=window.pageYOffset||document.documentElement.scrollTop;return e.top+n}let r=0;for(;t;)r+=t.offsetTop,t=t.offsetParent;return r},getScrollValue(){const t={scrollLeft:0,scrollTop:0};return t.scrollLeft=document.body.scrollLeft||document.documentElement.scrollLeft,t.scrollTop=document.body.scrollTop||document.documentElement.scrollTop,t},getPageValue(t){t=t||window.event;const r=t.pageX||t.clientX+this.getScrollValue().scrollLeft,e=t.pageY||t.clientY+this.getScrollValue().scrollTop;return{pageX:r,pageY:e}},addEventListener(t,r,e){t.addEventListener?t.addEventListener(r,e):t.attachEvent?t.attachEvent("on"+r,e):t["on"+r]=e}},E={saveAsBlob(t,r){const e=document.createElement("a"),n=window.URL.createObjectURL(t);e.href=n,e.download=r,document.body.appendChild(e),e.click(),URL.revokeObjectURL(n),document.body.removeChild(e)}},j={sortFromA2Z(t){return t!=null&&t.length?t.sort((e,n)=>{const o=e.toUpperCase(),s=n.toUpperCase();return o<s?-1:o>s?1:0}):void 0}},L={rad(t){return t*Math.PI/180},getDistance(t,r,e,n){const o=this.rad(t),s=this.rad(e),u=o-s,a=this.rad(r)-this.rad(n);let l=2*Math.asin(Math.sqrt(Math.pow(Math.sin(u/2),2)+Math.cos(o)*Math.cos(s)*Math.pow(Math.sin(a/2),2)));return l=l*6378.137,l=Math.round(l*1e4)/1e4,l=+l.toFixed(2),console.log("经纬度计算的距离为:"+l),l}};class A{static toStandardFormat(r){try{const e=typeof r=="string"?parseFloat(r):r;if(isNaN(e))throw new Error("输入不是有效的数字");if(!isFinite(e))throw new Error("输入是无穷大");return e.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")}catch(e){return console.error("格式化失败:",e),"格式错误"}}static toChineseFormat(r){try{const e=typeof r=="string"?parseFloat(r):r;if(isNaN(e))throw new Error("输入不是有效的数字");if(e>9999999999999e-2||e<-9999999999999e-2)throw new Error("输入数字超出范围");const n=e<0,o=Math.abs(e),s=Math.floor(o),u=Math.round((o-s)*100),a=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"],l=["","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟"],h=["角","分"];let c="",d=s;if(d===0)c=a[0];else{let y=0;for(;d>0;){const p=d%10;p!==0?c=a[p]+l[y]+c:c.charAt(0)!==a[0]&&(c=a[p]+c),d=Math.floor(d/10),y++}c=c.replace(/零+/g,"零"),c=c.replace(/零+$/,"")}let g="";if(u>0){const y=Math.floor(u/10),p=u%10;y>0&&(g+=a[y]+h[0]),p>0&&(g+=a[p]+h[1])}else g="整";let f=(n?"负":"")+c+"圆"+g;return f==="零圆整"&&(f="零圆"),f}catch(e){return console.error("转换失败:",e),"格式错误"}}}const T={...Object.freeze(Object.defineProperty({__proto__:null,toLetter:t=>t>25||t<0?"":"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[t]},Symbol.toStringTag,{value:"Module"})),...Object.freeze(Object.defineProperty({__proto__:null,toMoney:t=>t.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")},Symbol.toStringTag,{value:"Module"})),isNumber(t){return typeof t=="number"&&!isNaN(t)}},C={isEmptyObject(t){return t?Object.keys(t).length===0&&t.constructor===Object:!0},copy(t,r){for(const e in t)r[e]=t[e]},deepCopy(t,r){for(const e in t){const n=t[e];n instanceof Object?(r[e]={},this.deepCopy(n,r[e])):n instanceof Array?(r[e]=[],this.deepCopy(n,r[e])):r[e]=t[e]}}},k={desensitize(t){return t?t.replace(/^(\d{3})\d{4}(\d{4})$/,"$1****$2")||t.slice(0,3)+"****"+t.slice(7):""}},_={color:function(){return`#${Math.random().toString(16).slice(2,8)}`},int(t,r){return Math.floor(Math.random()*(r-t+1))+t},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)}},v={getLocal(t){return localStorage.getItem(t)},setLocal(t,r){localStorage.setItem(t,r)},removeLocal(t){localStorage.removeItem(t)},getSession(t){return sessionStorage.getItem(t)},setSession(t,r){sessionStorage.setItem(t,r)},removeSession(t){sessionStorage.removeItem(t)}},I={isExist(t,r){if(!t||!r)return!1;const e=t.split(",");return console.log("判断某元素是否在字符串中",e.indexOf(r)===-1),e.indexOf(r)!==-1},includes(t,r){return!t||!r?!1:t.includes(r)},isJSON(t){try{return JSON.parse(t),!0}catch{return!1}},indexsOfAppear(t,r){let e=-1;const n=[];do e=t.indexOf(r,e+1),e!==-1&&n.push(e);while(e!==-1);return n},getMaxTimesAndVal(t){const r=[0,""],e={};for(let s=0;s<t.length;s++){const u=t.charAt(s);e[u]?e[u]++:e[u]=1}let n=1;for(const s in e)n<e[s]&&(n=e[s]);const o=[];for(const s in e)n==e[s]&&o.push(s);return r[0]=n,r[1]=o.join(),r}},B=t=>{const e=new RegExp("[?&]"+t+"=([^&#]*)","i").exec(window.location.href);return e?decodeURIComponent(e[1]):null};function N(t){return new URLSearchParams(window.location.search).get(t)}const P={...Object.freeze(Object.defineProperty({__proto__:null,getQueryInfoByName:B,getQueryParam:N},Symbol.toStringTag,{value:"Module"})),getHost(){return window.location.host},getPath(){return window.location.pathname}},F={toList(t,r=2){console.log(t,r);const e={};for(let o=0;o<r;o++)e[o]=[];t.forEach((o,s)=>e[s%r].push(o));const n=[];for(const o in e)n.push(...e[o]);return n}};i.MoneyFormatter=A,i.arrayUtils=w,i.base64Utils=U,i.booleanUtils=m,i.cookieUtils=S,i.dateUtils=M,i.documentUtils=O,i.downloadUtils=E,i.letterUtils=j,i.mapUtils=L,i.numberUtils=T,i.objectUtils=C,i.phoneUtils=k,i.randomUtils=_,i.storageUtils=v,i.stringUtils=I,i.urlUtils=P,i.waterfallUtils=F,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
1
+ (function(c,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(c=typeof globalThis<"u"?globalThis:c||self,b(c.yhkitUtils={}))})(this,function(c){"use strict";const p=Object.assign({unique(e){return e?Array.from(new Set(e)):[]},isExist(e,n){return!e||!n?!1:e.indexOf(n)!==-1},countOfAppear(e,n){let t=0;for(const r of e)r===n&&t++;return t},indexsOfAppear(e,n){let t=-1;const r=[];do t=e.indexOf(n,t+1),t!==-1&&r.push(t);while(t!==-1);return r},sort(e,n="asc"){return e?e.sort((t,r)=>n==="asc"?t>r?1:-1:t<r?1:-1):[]},shuffle(e){if(!e)return[];for(let n=e.length-1;n>0;n--){const t=Math.floor(Math.random()*(n+1));[e[n],e[t]]=[e[t],e[n]]}return e},getMaxValue(e){return e?Math.max(...e):0},getMinValue(e){return e?Math.min(...e):0},getMinValueAndIndex(e){if(e.length===0)return{minV:0,minI:0};const n={minV:e[0],minI:0};for(let t=1,r=e.length;t<r;t++){const o=e[t];n.minV>o&&(n.minV=o,n.minI=t)}return n},getMaxValueAndIndex(e){if(e.length===0)return{maxV:0,maxI:0};const n={maxV:e[0],maxI:0};for(let t=1,r=e.length;t<r;t++){const o=e[t];n.maxV<o&&(n.maxV=o,n.maxI=t)}return n}},{...Object.freeze(Object.defineProperty({__proto__:null,toEnumObj:e=>{if(!e||!e.length)return{};const n={};return e.forEach(t=>{const r=Object.assign({label:t.label,text:t.label},t);n[t==null?void 0:t.value]=r}),n}},Symbol.toStringTag,{value:"Module"}))}),M={toBlob(e,n="",t=512){const o=(e.split(",")[1]||e).replace(/-/g,"+").replace(/_/g,"/"),s="=".repeat((4-o.length%4)%4),u=o+s;try{const l=atob(u),a=[];for(let h=0;h<l.length;h+=t){const i=l.slice(h,h+t),d=new Array(i.length);for(let f=0;f<i.length;f++)d[f]=i.charCodeAt(f);const g=new Uint8Array(d);a.push(g)}return new Blob(a,{type:n})}catch(l){return console.error("Failed to convert base64 to blob:",l),null}},toFile(e,n="file.txt",t="text/plain"){const o=e.replace(/^data:.+;base64,/,"").replace(/-/g,"+").replace(/_/g,"/"),s="=".repeat((4-o.length%4)%4),u=o+s,l=atob(u),a=[];for(let i=0;i<l.length;i+=512){const d=l.slice(i,i+512),g=new Array(d.length);for(let f=0;f<d.length;f++)g[f]=d.charCodeAt(f);a.push(new Uint8Array(g))}const h=new Blob(a,{type:t});return new File([h],n,{type:t})}},w={isEmptyString(e){return typeof e=="string"&&e.trim()===""},isNumber(e){return typeof e=="number"&&!isNaN(e)},isObject(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)},isEmptyObject(e){return e?Object.keys(e).length===0&&e.constructor===Object:!0},isBoolean(e){return typeof e=="boolean"},isArray(e){return Array.isArray(e)},isFunction(e){return typeof e=="function"},isPromise(e){return!!e&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"},isElement(e){return e instanceof Element},isPhone(e){return/^1[3-9]\d{9}$/.test(e)},isEmail(e){return/^[\w.-]+@[\w.-]+\.\w+$/.test(e)},isJSON(e){try{return JSON.parse(e),!0}catch{return!1}},isImageLoaded(e){return e.complete&&e.naturalWidth!==0},isInViewport(e){const n=e.getBoundingClientRect();return n.top>=0&&n.left>=0&&n.bottom<=window.innerHeight&&n.right<=window.innerWidth},isLeapYear(e){return e%4===0&&e%100!==0||e%400===0},isMobile(){return/Mobi|Android|iPhone/i.test(navigator.userAgent)}},U={getCookie(e){if(!e)return;const n=document.cookie.match(new RegExp("(^| )"+e+"=([^;]+)"));return n?decodeURIComponent(n[2]):null},setCookie(e,n,t=7){const r=new Date;r.setTime(r.getTime()+t*24*60*60*1e3),document.cookie=`${e}=${encodeURIComponent(n)};expires=${r.toUTCString()};path=/`},deleteCookie(e){this.setCookie(e,"",-1)}},S={getTimeString(e,n=!1){return n?new Date().toLocaleString(e,{hour12:!0}):new Date().toLocaleString("chinese",{hour12:!1})},diffDays(e,n){const t=new Date(e).getTime(),r=new Date(n).getTime();return t>r?Math.abs(Math.floor((t-r)/(24*3600*1e3))):Math.abs(Math.floor((r-t)/(24*3600*1e3)))},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)},getWhichDays(e,n,t){let r=t;for(let o=1;o<n;o++)switch(o){case 1:case 3:case 5:case 7:case 8:case 10:case 12:r+=31;break;case 2:w.isLeapYear(e)?r+=29:r+=28;break;default:r+=30;break}return r}},O={getOffsetTop(e){if(!e)throw new Error("Element is not provided");if(e instanceof SVGElement){const t=e.getBoundingClientRect(),r=window.pageYOffset||document.documentElement.scrollTop;return t.top+r}let n=0;for(;e;)n+=e.offsetTop,e=e.offsetParent;return n},getScrollValue(){const e={scrollLeft:0,scrollTop:0};return e.scrollLeft=document.body.scrollLeft||document.documentElement.scrollLeft,e.scrollTop=document.body.scrollTop||document.documentElement.scrollTop,e},getPageValue(e){e=e||window.event;const n=e.pageX||e.clientX+this.getScrollValue().scrollLeft,t=e.pageY||e.clientY+this.getScrollValue().scrollTop;return{pageX:n,pageY:t}},addEventListener(e,n,t){e.addEventListener?e.addEventListener(n,t):e.attachEvent?e.attachEvent("on"+n,t):e["on"+n]=t}},A={saveAsBlob(e,n){const t=document.createElement("a"),r=window.URL.createObjectURL(e);t.href=r,t.download=n,document.body.appendChild(t),t.click(),URL.revokeObjectURL(r),document.body.removeChild(t)}},E={sortFromA2Z(e){return e!=null&&e.length?e.sort((t,r)=>{const o=t.toUpperCase(),s=r.toUpperCase();return o<s?-1:o>s?1:0}):void 0}},j={degrees2Radians(e){return e*Math.PI/180},getDistance(e,n,t,r){const o=this.degrees2Radians(e),s=this.degrees2Radians(t),u=o-s,l=this.degrees2Radians(n)-this.degrees2Radians(r);let a=2*Math.asin(Math.sqrt(Math.pow(Math.sin(u/2),2)+Math.cos(o)*Math.cos(s)*Math.pow(Math.sin(l/2),2)));return a=a*6378.137,a=Math.round(a*1e4)/1e4,a=+a.toFixed(2),console.log("经纬度计算的距离为:"+a),a},calculateDistanceByHaversine(e,n,t="km"){const r=this,o=e.longitude??e.lng,s=e.latitude??e.lat,u=n.longitude??n.lng,l=n.latitude??n.lat;if(o===void 0||s===void 0||u===void 0||l===void 0)throw new Error("无效的坐标格式,缺少经纬度信息");const a=6371,h=r.degrees2Radians(s),i=r.degrees2Radians(l),d=r.degrees2Radians(l-s),g=r.degrees2Radians(u-o),f=Math.sin(d/2)*Math.sin(d/2)+Math.cos(h)*Math.cos(i)*Math.sin(g/2)*Math.sin(g/2),y=2*Math.atan2(Math.sqrt(f),Math.sqrt(1-f)),m=a*y;switch(t){case"m":return m*1e3;case"mi":return m*.621371;case"nmi":return m*.539957;default:return m}},calculateDistancesByHaversine(e,n="km",t=!1){if(e.length<2)return{segments:[],total:0};const r=[];let o=0;for(let s=0;s<e.length-1;s++){const u=this.calculateDistanceByHaversine(e[s],e[s+1],n);r.push(u),o+=u}if(t&&e.length>2){const s=this.calculateDistanceByHaversine(e[e.length-1],e[0],n);r.push(s),o+=s}return{segments:r,total:o}}};class L{static toStandardFormat(n){try{const t=typeof n=="string"?parseFloat(n):n;if(isNaN(t))throw new Error("输入不是有效的数字");if(!isFinite(t))throw new Error("输入是无穷大");return t.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")}catch(t){return console.error("格式化失败:",t),"格式错误"}}static toChineseFormat(n){try{const t=typeof n=="string"?parseFloat(n):n;if(isNaN(t))throw new Error("输入不是有效的数字");if(t>9999999999999e-2||t<-9999999999999e-2)throw new Error("输入数字超出范围");const r=t<0,o=Math.abs(t),s=Math.floor(o),u=Math.round((o-s)*100),l=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"],a=["","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟"],h=["角","分"];let i="",d=s;if(d===0)i=l[0];else{let y=0;for(;d>0;){const m=d%10;m!==0?i=l[m]+a[y]+i:i.charAt(0)!==l[0]&&(i=l[m]+i),d=Math.floor(d/10),y++}i=i.replace(/零+/g,"零"),i=i.replace(/零+$/,"")}let g="";if(u>0){const y=Math.floor(u/10),m=u%10;y>0&&(g+=l[y]+h[0]),m>0&&(g+=l[m]+h[1])}else g="整";let f=(r?"负":"")+i+"圆"+g;return f==="零圆整"&&(f="零圆"),f}catch(t){return console.error("转换失败:",t),"格式错误"}}}const x={...Object.freeze(Object.defineProperty({__proto__:null,toLetter:e=>e>25||e<0?"":"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e]},Symbol.toStringTag,{value:"Module"})),...Object.freeze(Object.defineProperty({__proto__:null,toMoney:e=>e.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")},Symbol.toStringTag,{value:"Module"})),isNumber(e){return typeof e=="number"&&!isNaN(e)}},I={isEmptyObject(e){return e?Object.keys(e).length===0&&e.constructor===Object:!0},copy(e,n){for(const t in e)n[t]=e[t]},deepCopy(e,n){for(const t in e){const r=e[t];r instanceof Object?(n[t]={},this.deepCopy(r,n[t])):r instanceof Array?(n[t]=[],this.deepCopy(r,n[t])):n[t]=e[t]}}},v={desensitize(e){return e?e.replace(/^(\d{3})\d{4}(\d{4})$/,"$1****$2")||e.slice(0,3)+"****"+e.slice(7):""}},R={color:function(){return`#${Math.random().toString(16).slice(2,8)}`},int(e,n){return Math.floor(Math.random()*(n-e+1))+e},uniqueId(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)}},k={mobile:/^1[3-9]\d{9}$/,email:/^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,chinese:/^[\u4e00-\u9fa5]+$/,english:/^[a-zA-Z]+$/,chineseStart:/^[\u4e00-\u9fa5]+\w*$/,integer:/^\d+$/,integerAndzero:/^(0|[1-9]+[0-9]*)$/,strongPassword:/^(?!.*[\s\p{C}])(?:(?=.*[A-Z])(?=.*[a-z])(?=.*[\d\W])|(?=.*\d)(?=.*[^\w\s])).{8,}$/u,decimal:/^0\.(0[1-9]|[1-9][0-9]*)$/},C={getLocal(e){return localStorage.getItem(e)},setLocal(e,n){localStorage.setItem(e,n)},removeLocal(e){localStorage.removeItem(e)},getSession(e){return sessionStorage.getItem(e)},setSession(e,n){sessionStorage.setItem(e,n)},removeSession(e){sessionStorage.removeItem(e)}},T={isExist(e,n){if(!e||!n)return!1;const t=e.split(",");return console.log("判断某元素是否在字符串中",t.indexOf(n)===-1),t.indexOf(n)!==-1},includes(e,n){return!e||!n?!1:e.includes(n)},isJSON(e){try{return JSON.parse(e),!0}catch{return!1}},indexsOfAppear(e,n){let t=-1;const r=[];do t=e.indexOf(n,t+1),t!==-1&&r.push(t);while(t!==-1);return r},getMaxTimesAndVal(e){const n=[0,""],t={};for(let s=0;s<e.length;s++){const u=e.charAt(s);t[u]?t[u]++:t[u]=1}let r=1;for(const s in t)r<t[s]&&(r=t[s]);const o=[];for(const s in t)r==t[s]&&o.push(s);return n[0]=r,n[1]=o.join(),n}},B=e=>{const t=new RegExp("[?&]"+e+"=([^&#]*)","i").exec(window.location.href);return t?decodeURIComponent(t[1]):null};function V(e){return new URLSearchParams(window.location.search).get(e)}const _={...Object.freeze(Object.defineProperty({__proto__:null,getQueryInfoByName:B,getQueryParam:V},Symbol.toStringTag,{value:"Module"})),getHost(){return window.location.host},getPath(){return window.location.pathname}},$={toList(e,n=2){console.log(e,n);const t={};for(let o=0;o<n;o++)t[o]=[];e.forEach((o,s)=>t[s%n].push(o));const r=[];for(const o in t)r.push(...t[o]);return r},jsLayout(e,n,t){const r=e.offsetWidth,o=n[0].offsetWidth,s=parseInt((r/o).toString()),u=(r-o*s)/(s-1),l=[];for(let a=0,h=n.length;a<h;a++){const i=n[a];if(a<s)i.style.left=(o+u)*a+"px",l[a]=i.offsetHeight;else{const{minI:d,minV:g}=p.getMinValueAndIndex(l);i.style.left=(o+u)*d+"px",i.style.top=g+t+"px",l[d]=i.offsetHeight+t+g}}}};c.MoneyFormatter=L,c.arrayUtils=p,c.base64Utils=M,c.booleanUtils=w,c.cookieUtils=U,c.dateUtils=S,c.documentUtils=O,c.downloadUtils=A,c.letterUtils=E,c.mapUtils=j,c.numberUtils=x,c.objectUtils=I,c.phoneUtils=v,c.randomUtils=R,c.regexUtils=k,c.storageUtils=C,c.stringUtils=T,c.urlUtils=_,c.waterfallUtils=$,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@yh-kit/utils",
3
3
  "private": false,
4
- "version": "1.6.0",
4
+ "version": "1.7.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
@@ -60,6 +60,24 @@ export declare const arrayUtils: {
60
60
  * @returns 最小值
61
61
  */
62
62
  getMinValue(arr: number[]): number;
63
+ /**
64
+ * 获取数组中的最小值和索引
65
+ * @param array 数组
66
+ * @returns 最小值和索引
67
+ */
68
+ getMinValueAndIndex(array: number[]): {
69
+ minV: number;
70
+ minI: number;
71
+ };
72
+ /**
73
+ * 获取数组中的最大值和索引
74
+ * @param array 数组
75
+ * @returns 最大值和索引
76
+ */
77
+ getMaxValueAndIndex(array: number[]): {
78
+ maxV: number;
79
+ maxI: number;
80
+ };
63
81
  } & {
64
82
  toEnumObj: (arr: import("@yh-kit/types").IOptionItem[]) => import("@yh-kit/types").TValueEnum;
65
83
  };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 元素【Dom】相关工具函数
2
+ * 元素【Dom 文档流】相关工具函数
3
3
  */
4
4
  export declare const documentUtils: {
5
5
  /**
@@ -12,6 +12,7 @@ export * from "./number";
12
12
  export * from "./object";
13
13
  export * from "./phone";
14
14
  export * from "./random";
15
+ export * from "./regex";
15
16
  export * from "./storage";
16
17
  export * from "./string";
17
18
  export * from "./url";
@@ -1,18 +1,48 @@
1
+ /**
2
+ * 经纬度坐标接口 - 支持多种常见格式
3
+ *
4
+ * 经纬度通常以度(°)为单位表示,通常要求4位小数以上。其小数部分的位数决定了精度:
5
+ * 小数点后 1 位:约 11.1 km(影响较大)
6
+ * 小数点后 2 位:约 1.1 km(城市级别精度)
7
+ * 小数点后 3 位:约 111 m(街区级别精度)
8
+ * 小数点后 4 位:约 11.1 m(建筑物/大厦级别精度)
9
+ * 小数点后 5 位:约 1.1 m(GPS 设备常见精度)
10
+ * 小数点后 6 位:约 11 cm(高精度定位)
11
+ * 小数点后 7 位:约 1.1 cm(特高精度定位)
12
+ */
13
+ interface ICoordinate {
14
+ /** 经度 */
15
+ lng: number;
16
+ /** 纬度 */
17
+ lat: number;
18
+ longitude?: number;
19
+ latitude?: number;
20
+ [key: string]: unknown;
21
+ }
22
+ /**
23
+ * 距离计算结果接口
24
+ */
25
+ interface IDistanceResult {
26
+ /** 距离分段值 */
27
+ segments: number[];
28
+ /** 总距离值 */
29
+ total: number;
30
+ }
1
31
  /**
2
32
  * 地图相关工具函数
3
33
  */
4
34
  export declare const mapUtils: {
5
35
  /**
6
- * 计算弧度
36
+ * 角度(度数)转弧度
7
37
  * 在数学和编程里,角度有两种常用单位,分别是度(°)和弧度(rad)。
8
38
  * 1 个完整的圆周,用角度表示是 360°,用弧度表示则是 2π rad。
9
39
  * 角度和弧度的换算关系为:弧度 = 角度 × π / 180。
10
- * @param d 经度值或纬度值
40
+ * @param degrees 度数。单位:°
11
41
  * @returns 弧度值
12
42
  */
13
- rad(d: number): number;
43
+ degrees2Radians(degrees: number): number;
14
44
  /**
15
- * 根据经纬度计算距离
45
+ * 根据经纬度计算距离【弃用】
16
46
  * @param userLat 用户纬度
17
47
  * @param userLng 用户经度
18
48
  * @param targetLat 目标纬度
@@ -20,4 +50,29 @@ export declare const mapUtils: {
20
50
  * @returns 距离值 单位:km
21
51
  */
22
52
  getDistance(userLat: number, userLng: number, targetLat: number, targetLng: number): number;
53
+ /**
54
+ * 计算两个坐标点之间的距离(Haversine公式)
55
+ * Haversine公式:
56
+ * a = sin²(Δlat/2) + cos(lat1)·cos(lat2)·sin²(Δlon/2) 其中:
57
+ * lat1, lat2: 两点的纬度(弧度)
58
+ * Δlat: 两点纬度之差(弧度)
59
+ * Δlon: 两点经度之差(弧度)
60
+ * c = 2·atan2(√a, √(1−a))
61
+ * d = R·c 其中:
62
+ * R: 地球半径(平均约 6371km)
63
+ * @param point1 坐标点1
64
+ * @param point2 坐标点2
65
+ * @param unit 距离单位,默认单位为千米。可选值:km(千米)、m(米)、mi(英里)、nmi(海里)
66
+ * @returns 距离值
67
+ */
68
+ calculateDistanceByHaversine(point1: ICoordinate, point2: ICoordinate, unit?: "km" | "m" | "mi" | "nmi"): number;
69
+ /**
70
+ * 计算多个坐标点之间的总距离(Haversine公式)
71
+ * @param points 坐标点数组
72
+ * @param unit 距离单位,默认单位为千米。可选值:km(千米)、m(米)、mi(英里)、nmi(海里)
73
+ * @param closed 是否闭合路径,默认不闭合
74
+ * @returns 距离结果对象。包含每个距离段的数组(segments)和总距离(total)。
75
+ */
76
+ calculateDistancesByHaversine(points: ICoordinate[], unit?: "km" | "m" | "mi" | "nmi", closed?: boolean): IDistanceResult;
23
77
  };
78
+ export {};
@@ -0,0 +1,41 @@
1
+ /**
2
+ * 常用正则表达式
3
+ */
4
+ export declare const regexUtils: {
5
+ /**
6
+ * 验证手机号
7
+ */
8
+ mobile: RegExp;
9
+ /**
10
+ * 验证邮箱
11
+ */
12
+ email: RegExp;
13
+ /**
14
+ * 验证中文
15
+ */
16
+ chinese: RegExp;
17
+ /**
18
+ * 验证英文
19
+ */
20
+ english: RegExp;
21
+ /**
22
+ * 验证中文开头其他结束
23
+ */
24
+ chineseStart: RegExp;
25
+ /**
26
+ * 验证正整数
27
+ */
28
+ integer: RegExp;
29
+ /**
30
+ * 验证零+正整数
31
+ */
32
+ integerAndzero: RegExp;
33
+ /**
34
+ * 验证强密码正则:密码须由大小字母+数字、大小字母+特殊符号、数字+特殊字符等组合,且存在字母时,必须包含大小写字母。长度必须8位以上
35
+ */
36
+ strongPassword: RegExp;
37
+ /**
38
+ * 验证0.01~0.99正则:最多两位小数。0.1、0.10、0.9、0.90
39
+ */
40
+ decimal: RegExp;
41
+ };
@@ -3,10 +3,11 @@
3
3
  */
4
4
  export declare const waterfallUtils: {
5
5
  /**
6
- * 处理瀑布流数据,使其适合瀑布流布局展示
6
+ * 处理瀑布流数据,使其竖向瀑布流布局呈现横向瀑布流的展现形式。适用于 column-gap: 20rpx; column-count: 2; 布局的瀑布流
7
7
  * @param list 瀑布流数据-数组
8
8
  * @param columnsNum 需要展示的列数
9
9
  * @returns 适合瀑布流布局的数组
10
10
  */
11
11
  toList<T>(list: T[], columnsNum?: number): any[];
12
+ jsLayout(itemBox: HTMLElement, items: HTMLElement[], step: number): void;
12
13
  };