@yh-kit/utils 1.5.0 → 1.6.1
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.
- package/dist/utils.js +461 -223
- package/dist/utils.umd.cjs +1 -1
- package/package.json +1 -1
- package/types/utils/lib/array/index.d.ts +19 -0
- package/types/utils/lib/date/index.d.ts +8 -0
- package/types/utils/lib/document/index.d.ts +40 -0
- package/types/utils/lib/index.d.ts +2 -1
- package/types/utils/lib/map/index.d.ts +78 -0
- package/types/utils/lib/object/index.d.ts +20 -0
- package/types/utils/lib/string/index.d.ts +13 -0
- package/types/utils/lib/element/index.d.ts +0 -12
package/dist/utils.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(i,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(i=typeof globalThis<"u"?globalThis:i||self,p(i.yhkitUtils={}))})(this,function(i){"use strict";const w=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}},{...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),l=o+s;try{const c=atob(l),u=[];for(let g=0;g<c.length;g+=t){const a=c.slice(g,g+t),f=new Array(a.length);for(let d=0;d<a.length;d++)f[d]=a.charCodeAt(d);const h=new Uint8Array(f);u.push(h)}return new Blob(u,{type:n})}catch(c){return console.error("Failed to convert base64 to blob:",c),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),l=o+s,c=atob(l),u=[];for(let a=0;a<c.length;a+=512){const f=c.slice(a,a+512),h=new Array(f.length);for(let d=0;d<f.length;d++)h[d]=f.charCodeAt(d);u.push(new Uint8Array(h))}const g=new Blob(u,{type:t});return new File([g],n,{type:t})}},m={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:m.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}},E={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)}},L={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),l=o-s,c=this.degrees2Radians(n)-this.degrees2Radians(r);let u=2*Math.asin(Math.sqrt(Math.pow(Math.sin(l/2),2)+Math.cos(o)*Math.cos(s)*Math.pow(Math.sin(c/2),2)));return u=u*6378.137,u=Math.round(u*1e4)/1e4,u=+u.toFixed(2),console.log("经纬度计算的距离为:"+u),u},calculateDistanceByHaversine(e,n,t="km"){const r=this,o=e.longitude??e.lng,s=e.latitude??e.lat,l=n.longitude??n.lng,c=n.latitude??n.lat;if(o===void 0||s===void 0||l===void 0||c===void 0)throw new Error("无效的坐标格式,缺少经纬度信息");const u=6371,g=r.degrees2Radians(s),a=r.degrees2Radians(c),f=r.degrees2Radians(c-s),h=r.degrees2Radians(l-o),d=Math.sin(f/2)*Math.sin(f/2)+Math.cos(g)*Math.cos(a)*Math.sin(h/2)*Math.sin(h/2),b=2*Math.atan2(Math.sqrt(d),Math.sqrt(1-d)),y=u*b;switch(t){case"m":return y*1e3;case"mi":return y*.621371;case"nmi":return y*.539957;default:return y}},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 l=this.calculateDistanceByHaversine(e[s],e[s+1],n);r.push(l),o+=l}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 v{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),l=Math.round((o-s)*100),c=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"],u=["","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟"],g=["角","分"];let a="",f=s;if(f===0)a=c[0];else{let b=0;for(;f>0;){const y=f%10;y!==0?a=c[y]+u[b]+a:a.charAt(0)!==c[0]&&(a=c[y]+a),f=Math.floor(f/10),b++}a=a.replace(/零+/g,"零"),a=a.replace(/零+$/,"")}let h="";if(l>0){const b=Math.floor(l/10),y=l%10;b>0&&(h+=c[b]+g[0]),y>0&&(h+=c[y]+g[1])}else h="整";let d=(r?"负":"")+a+"圆"+h;return d==="零圆整"&&(d="零圆"),d}catch(t){return console.error("转换失败:",t),"格式错误"}}}const A={...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)}},R={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]}}},k={desensitize(e){return e?e.replace(/^(\d{3})\d{4}(\d{4})$/,"$1****$2")||e.slice(0,3)+"****"+e.slice(7):""}},T={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)}},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)}},B={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 l=e.charAt(s);t[l]?t[l]++:t[l]=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}},_=e=>{const t=new RegExp("[?&]"+e+"=([^&#]*)","i").exec(window.location.href);return t?decodeURIComponent(t[1]):null};function I(e){return new URLSearchParams(window.location.search).get(e)}const N={...Object.freeze(Object.defineProperty({__proto__:null,getQueryInfoByName:_,getQueryParam:I},Symbol.toStringTag,{value:"Module"})),getHost(){return window.location.host},getPath(){return window.location.pathname}},P={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}};i.MoneyFormatter=v,i.arrayUtils=w,i.base64Utils=M,i.booleanUtils=m,i.cookieUtils=U,i.dateUtils=S,i.documentUtils=O,i.downloadUtils=E,i.letterUtils=L,i.mapUtils=j,i.numberUtils=A,i.objectUtils=R,i.phoneUtils=k,i.randomUtils=T,i.storageUtils=C,i.stringUtils=B,i.urlUtils=N,i.waterfallUtils=P,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -22,6 +22,13 @@ export declare const arrayUtils: {
|
|
|
22
22
|
* @returns 出现次数
|
|
23
23
|
*/
|
|
24
24
|
countOfAppear<T>(arr: T[], target: T): number;
|
|
25
|
+
/**
|
|
26
|
+
* 查找某个元素在数组中重复出现的位置
|
|
27
|
+
* @param array 数组
|
|
28
|
+
* @param element 元素
|
|
29
|
+
* @returns 位置数组
|
|
30
|
+
*/
|
|
31
|
+
indexsOfAppear<T>(array: T[], element: T): number[];
|
|
25
32
|
/**
|
|
26
33
|
* 数组排序-默认升序
|
|
27
34
|
* @param arr 数组
|
|
@@ -41,6 +48,18 @@ export declare const arrayUtils: {
|
|
|
41
48
|
* @returns
|
|
42
49
|
*/
|
|
43
50
|
shuffle<T>(arr: T[]): T[];
|
|
51
|
+
/**
|
|
52
|
+
* 获取数组中的最大值
|
|
53
|
+
* @param arr 数组
|
|
54
|
+
* @returns 最大值
|
|
55
|
+
*/
|
|
56
|
+
getMaxValue(arr: number[]): number;
|
|
57
|
+
/**
|
|
58
|
+
* 获取数组中的最小值
|
|
59
|
+
* @param arr 数组
|
|
60
|
+
* @returns 最小值
|
|
61
|
+
*/
|
|
62
|
+
getMinValue(arr: number[]): number;
|
|
44
63
|
} & {
|
|
45
64
|
toEnumObj: (arr: import("@yh-kit/types").IOptionItem[]) => import("@yh-kit/types").TValueEnum;
|
|
46
65
|
};
|
|
@@ -21,4 +21,12 @@ export declare const dateUtils: {
|
|
|
21
21
|
* @returns 唯一ID
|
|
22
22
|
*/
|
|
23
23
|
uniqueId(): string;
|
|
24
|
+
/**
|
|
25
|
+
* 获取指定日期是当年的第几天
|
|
26
|
+
* @param year 年份
|
|
27
|
+
* @param month 月份 数字:1-12;1:代表一月;12:代表十二月
|
|
28
|
+
* @param day 日期
|
|
29
|
+
* @returns 当年的第几天
|
|
30
|
+
*/
|
|
31
|
+
getWhichDays(year: number, month: number, day: number): number;
|
|
24
32
|
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 元素【Dom】相关工具函数
|
|
3
|
+
*/
|
|
4
|
+
export declare const documentUtils: {
|
|
5
|
+
/**
|
|
6
|
+
* 获取元素相对于文档顶部的偏移量(距离)
|
|
7
|
+
* 处理了SVG元素的特殊情况。
|
|
8
|
+
* @param el 元素
|
|
9
|
+
* @returns 偏移量(距离值)
|
|
10
|
+
*/
|
|
11
|
+
getOffsetTop(el: HTMLElement): number;
|
|
12
|
+
/**
|
|
13
|
+
* 获取文档的滚动值
|
|
14
|
+
* @returns 包含滚动值的对象 { scrollLeft: 水平滚动值, scrollTop: 垂直滚动值 }
|
|
15
|
+
*/
|
|
16
|
+
getScrollValue(): {
|
|
17
|
+
scrollLeft: number;
|
|
18
|
+
scrollTop: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* 获取鼠标事件的页面坐标
|
|
22
|
+
* 已解决pageX、pageY兼容性问题
|
|
23
|
+
* e.pageX = e.clientX + 页面滚动的横向距离 ;
|
|
24
|
+
* e.pageY = e.clientY + 页面滚动的纵向距离 ;
|
|
25
|
+
* @param e 鼠标事件
|
|
26
|
+
* @returns 包含页面坐标的对象 { pageX: 水平页面坐标, pageY: 垂直页面坐标 }
|
|
27
|
+
*/
|
|
28
|
+
getPageValue(e: MouseEvent): {
|
|
29
|
+
pageX: number;
|
|
30
|
+
pageY: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* 给元素添加事件监听器 - 判断并处理了监听事件的兼容性问题
|
|
34
|
+
* 实例应用: addEventListenerFn(btn, 'click', function(){})
|
|
35
|
+
* @param element 元素
|
|
36
|
+
* @param eventName 事件名称
|
|
37
|
+
* @param fn 事件处理函数
|
|
38
|
+
*/
|
|
39
|
+
addEventListener(element: any, eventName: string, fn: any): void;
|
|
40
|
+
};
|
|
@@ -3,9 +3,10 @@ export * from "./base64";
|
|
|
3
3
|
export * from "./boolean";
|
|
4
4
|
export * from "./cookie";
|
|
5
5
|
export * from "./date";
|
|
6
|
+
export * from "./document";
|
|
6
7
|
export * from "./download";
|
|
7
|
-
export * from "./element";
|
|
8
8
|
export * from "./letter";
|
|
9
|
+
export * from "./map";
|
|
9
10
|
export * from "./money";
|
|
10
11
|
export * from "./number";
|
|
11
12
|
export * from "./object";
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 地图相关工具函数
|
|
33
|
+
*/
|
|
34
|
+
export declare const mapUtils: {
|
|
35
|
+
/**
|
|
36
|
+
* 角度(度数)转弧度
|
|
37
|
+
* 在数学和编程里,角度有两种常用单位,分别是度(°)和弧度(rad)。
|
|
38
|
+
* 1 个完整的圆周,用角度表示是 360°,用弧度表示则是 2π rad。
|
|
39
|
+
* 角度和弧度的换算关系为:弧度 = 角度 × π / 180。
|
|
40
|
+
* @param degrees 度数。单位:°
|
|
41
|
+
* @returns 弧度值
|
|
42
|
+
*/
|
|
43
|
+
degrees2Radians(degrees: number): number;
|
|
44
|
+
/**
|
|
45
|
+
* 根据经纬度计算距离【弃用】
|
|
46
|
+
* @param userLat 用户纬度
|
|
47
|
+
* @param userLng 用户经度
|
|
48
|
+
* @param targetLat 目标纬度
|
|
49
|
+
* @param targetLng 目标经度
|
|
50
|
+
* @returns 距离值 单位:km
|
|
51
|
+
*/
|
|
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;
|
|
77
|
+
};
|
|
78
|
+
export {};
|
|
@@ -8,4 +8,24 @@ export declare const objectUtils: {
|
|
|
8
8
|
* @returns 是否为空。true 为空;false 不为空
|
|
9
9
|
*/
|
|
10
10
|
isEmptyObject(obj: object): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* 复制对象【对象的浅拷贝 把obj1的成员,复制给obj2】
|
|
13
|
+
* @param obj1 源对象
|
|
14
|
+
* @param obj2 目标对象
|
|
15
|
+
*/
|
|
16
|
+
copy(obj1: {
|
|
17
|
+
[x: string]: any;
|
|
18
|
+
}, obj2: {
|
|
19
|
+
[x: string]: any;
|
|
20
|
+
}): void;
|
|
21
|
+
/**
|
|
22
|
+
* 对象的深拷贝 把o1 的成员,复制给o2
|
|
23
|
+
* @param o1
|
|
24
|
+
* @param o2
|
|
25
|
+
*/
|
|
26
|
+
deepCopy(o1: {
|
|
27
|
+
[x: string]: any;
|
|
28
|
+
}, o2: {
|
|
29
|
+
[x: string]: any;
|
|
30
|
+
}): void;
|
|
11
31
|
};
|
|
@@ -22,4 +22,17 @@ export declare const stringUtils: {
|
|
|
22
22
|
* @returns
|
|
23
23
|
*/
|
|
24
24
|
isJSON(str: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* 查找某个元素在字符串中重复出现的位置
|
|
27
|
+
* @param _string 字符串
|
|
28
|
+
* @param element 元素
|
|
29
|
+
* @returns 位置数组
|
|
30
|
+
*/
|
|
31
|
+
indexsOfAppear(_string: string, element: string): number[];
|
|
32
|
+
/**
|
|
33
|
+
* 获取字符串中出现次数最多的字符和次数
|
|
34
|
+
* @param string 字符串
|
|
35
|
+
* @returns 数组,第一个元素为出现次数,第二个元素为出现次数最多的字符
|
|
36
|
+
*/
|
|
37
|
+
getMaxTimesAndVal(string: string): [number, string];
|
|
25
38
|
};
|