utils-uniapp 1.2.2 → 1.2.4

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.
@@ -0,0 +1,95 @@
1
+ // WebSocketClient.d.ts
2
+ export declare class WebSocketClient {
3
+ /**
4
+ * @param url websocket地址
5
+ * @param options 配置项
6
+ */
7
+ constructor(url: string, options?: WebSocketClientOptions);
8
+
9
+ url: string;
10
+ reconnectDelay: number;
11
+ heartbeatInterval: number;
12
+ heartbeatTimeout: number;
13
+ heartbeatMsg: string;
14
+ maxReconnect: number;
15
+ socketTask: UniApp.SocketTask | null;
16
+ isConnected: boolean;
17
+ heartbeatTimer: number | null;
18
+ heartbeatTimeoutTimer: number | null;
19
+ reconnectTimer: number | null;
20
+ reconnectCount: number;
21
+
22
+ /**
23
+ * 注册事件监听,替代 addEventListener
24
+ * @param event 事件名 open | message | close | error
25
+ * @param fn 回调函数
26
+ */
27
+ on(event: 'open', fn: (res: UniApp.OnSocketOpenCallbackResult) => void): this;
28
+ on(event: 'message', fn: (res: UniApp.OnSocketMessageCallbackResult) => void): this;
29
+ on(event: 'close', fn: (res: UniApp.OnSocketCloseCallbackResult) => void): this;
30
+ on(event: 'error', fn: (err: UniApp.GeneralCallbackResult) => void): this;
31
+
32
+ /**
33
+ * 移除事件监听
34
+ * @param event 事件名
35
+ * @param fn 回调函数
36
+ */
37
+ off(event: 'open' | 'message' | 'close' | 'error', fn: Function): this;
38
+
39
+ /**
40
+ * 内部触发事件(外部一般不用)
41
+ */
42
+ emit(event: 'open' | 'message' | 'close' | 'error', ...args: any[]): void;
43
+
44
+ /**
45
+ * 建立连接
46
+ */
47
+ connect(): this;
48
+
49
+ /**
50
+ * 发送消息,支持字符串/ArrayBuffer
51
+ * @param message 发送的数据
52
+ */
53
+ send(message: string | ArrayBuffer): this;
54
+
55
+ /**
56
+ * 开启心跳
57
+ */
58
+ startHeartbeat(): void;
59
+
60
+ /**
61
+ * 停止心跳
62
+ */
63
+ stopHeartbeat(): void;
64
+
65
+ startHeartbeatTimeout(): void;
66
+ resetHeartbeatTimeout(): void;
67
+ clearHeartbeatTimeout(): void;
68
+
69
+ /**
70
+ * 自动重连
71
+ */
72
+ reconnect(): void;
73
+
74
+ /**
75
+ * 关闭连接
76
+ * @param code 关闭码
77
+ * @param reason 关闭原因
78
+ */
79
+ close(code?: number, reason?: string): void;
80
+ }
81
+
82
+ export declare interface WebSocketClientOptions {
83
+ /** 重连间隔 ms 默认1000 */
84
+ reconnectDelay?: number;
85
+ /** 心跳发送间隔 ms 默认30000 */
86
+ heartbeatInterval?: number;
87
+ /** 心跳超时时间 ms 默认10000,收不到服务端消息则断开 */
88
+ heartbeatTimeout?: number;
89
+ /** 心跳消息 默认ping */
90
+ heartbeatMsg?: string;
91
+ /** 最大重连次数,-1无限重连 */
92
+ maxReconnect?: number;
93
+ }
94
+
95
+ export default WebSocketClient;
package/lib/index.d.ts CHANGED
@@ -10,4 +10,5 @@ export * from './magic';
10
10
  export * from './object';
11
11
  export * from './pageStack';
12
12
  export * from './validate';
13
+ export * from './WebSocketClient';
13
14
  export * as wx from './wx';
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("./aliPay/index.js"),t=require("./array/index.js"),n=require("./cache/index.js"),c=require("./date/index.js"),r=require("./fs/index.js"),g=require("./getLocation/index.js"),o=require("./http/index.js"),e=require("./magic/index.js"),s=require("./object/index.js"),a=require("./pageStack/index.js"),i=require("./validate/index.js"),l=require("./index-2cb7f964.js");require("./_rollupPluginBabelHelpers-63255c86.js");var P=require("./lodash");Object.assign(exports,P);exports.alipaySubmit=d.alipaySubmit;exports.exchangeArrP=t.exchangeArrP;exports.filterTree=t.filterTree;exports.findTreeItem=t.findTreeItem;exports.flatWithKey=t.flatWithKey;exports.getTreePath=t.getTreePath;exports.groupBy=t.groupBy;exports.reverseForEach=t.reverseForEach;exports.treeItemSetParent=t.treeItemSetParent;exports.StorageCache=n.StorageCache;exports.localCache=n.localCache;exports.sessionCache=n.sessionCache;exports.dateFormat=c.dateFormat;exports.getDate=c.getDate;exports.$fs=r.$fs;exports.chooseImg=r.chooseImg;exports.getArraybufferTempPath=r.getArraybufferTempPath;exports.getImgBase64Prefix=r.getImgBase64Prefix;exports.readFile=r.readFile;exports.saveImageToPhotosAlbum=r.saveImageToPhotosAlbum;exports.writeFile=r.writeFile;exports.getLocation=g.getLocation;exports.openLocation=g.openLocation;exports.CONTENT_TYPES=o.CONTENT_TYPES;exports.CancelToken=o.CancelToken;exports.createDownloadFile=o.createDownloadFile;exports.createRequest=o.createRequest;exports.createUploadFile=o.createUploadFile;exports.promisifyRequest=o.promisifyRequest;exports.compareVersion=e.compareVersion;exports.compose=e.compose;exports.composeAsync=e.composeAsync;exports.debounce=e.debounce;exports.debouncePromise=e.debouncePromise;exports.decodeURIParams=e.decodeURIParams;exports.encodeURIParams=e.encodeURIParams;exports.getOnLoadParams=e.getOnLoadParams;exports.getPascalCase=e.getPascalCase;exports.getQueryParams=e.getQueryParams;exports.getQueryParamsFromHash=e.getQueryParamsFromHash;exports.getQueryParamsFromSearch=e.getQueryParamsFromSearch;exports.getRandom=e.getRandom;exports.getRandomStr=e.getRandomStr;exports.pipe=e.pipe;exports.pipeAsync=e.pipeAsync;exports.randomColor=e.randomColor;exports.throttle=e.throttle;exports.toQueryString=e.toQueryString;exports.cloneDeepWithDescriptors=s.cloneDeepWithDescriptors;exports.getRawType=s.getRawType;exports.hasOwnProperty=s.hasOwnProperty;exports.backToRoute=a.backToRoute;exports.findPageByFullPath=a.findPageByFullPath;exports.findPageByRoute=a.findPageByRoute;exports.getCurrentPage=a.getCurrentPage;exports.getCurrentPageOptions=a.getCurrentPageOptions;exports.getCurrentRoute=a.getCurrentRoute;exports.getPageStack=a.getPageStack;exports.getPageVm=a.getPageVm;exports.getPrevPage=a.getPrevPage;exports.getPrevRoute=a.getPrevRoute;exports.isExternal=i.isExternal;exports.validDate=i.validDate;exports.validIDCard=i.validIDCard;exports.validPhone=i.validPhone;exports.validPostalCode=i.validPostalCode;exports.validURL=i.validURL;exports.wx=l.index;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./aliPay/index.js"),n=require("./array/index.js"),h=require("./cache/index.js"),T=require("./date/index.js"),i=require("./fs/index.js"),f=require("./getLocation/index.js"),s=require("./http/index.js"),a=require("./magic/index.js"),m=require("./object/index.js"),o=require("./pageStack/index.js"),c=require("./validate/index.js"),d=require("./_rollupPluginBabelHelpers-63255c86.js"),P=require("./index-2cb7f964.js");var k=function(){function g(r){var e,t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};d._classCallCheck(this,g),this.url=r,this.reconnectDelay=t.reconnectDelay||1e3,this.heartbeatInterval=t.heartbeatInterval||3e4,this.heartbeatTimeout=t.heartbeatTimeout||1e4,this.heartbeatMsg=t.heartbeatMsg||"ping",this.maxReconnect=(e=t.maxReconnect)!==null&&e!==void 0?e:-1,this.socketTask=null,this.isConnected=!1,this.heartbeatTimer=null,this.heartbeatTimeoutTimer=null,this.reconnectTimer=null,this.reconnectCount=0,this.events={open:[],message:[],close:[],error:[]}}return d._createClass(g,[{key:"on",value:function(e,t){return this.events[e]&&this.events[e].push(t),this}},{key:"off",value:function(e,t){if(!this.events[e])return this;var u=this.events[e].indexOf(t);return u>-1&&this.events[e].splice(u,1),this}},{key:"emit",value:function(e){for(var t=arguments.length,u=new Array(t>1?t-1:0),l=1;l<t;l++)u[l-1]=arguments[l];this.events[e]&&this.events[e].forEach(function(b){return b.apply(void 0,u)})}},{key:"connect",value:function(){var e=this;return this.socketTask&&(this.socketTask.close(),this.socketTask=null),this.socketTask=uni.connectSocket({url:this.url,complete:function(){}}),this.socketTask.onOpen(function(t){e.isConnected=!0,e.reconnectCount=0,console.log("Connection established"),e.emit("open",t),e.startHeartbeat()}),this.socketTask.onMessage(function(t){e.resetHeartbeatTimeout(),e.emit("message",t)}),this.socketTask.onClose(function(t){e.isConnected=!1,console.log("Connection closed",t),e.stopHeartbeat(),e.emit("close",t),e.reconnect()}),this.socketTask.onError(function(t){console.error("WebSocket error: ",t),e.emit("error",t),e.isConnected&&e.stopHeartbeat(),e.socketTask&&e.socketTask.close()}),this}},{key:"send",value:function(e){return this.isConnected&&this.socketTask?this.socketTask.send({data:e}):console.error("WebSocket is not connected"),this}},{key:"startHeartbeat",value:function(){var e=this;this.stopHeartbeat(),this.heartbeatTimer=setInterval(function(){e.isConnected&&(e.send(e.heartbeatMsg),e.startHeartbeatTimeout())},this.heartbeatInterval)}},{key:"stopHeartbeat",value:function(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null),this.clearHeartbeatTimeout()}},{key:"startHeartbeatTimeout",value:function(){var e=this;this.clearHeartbeatTimeout(),this.heartbeatTimeoutTimer=setTimeout(function(){console.warn("Heartbeat timeout, close socket"),e.socketTask&&e.socketTask.close()},this.heartbeatTimeout)}},{key:"resetHeartbeatTimeout",value:function(){this.clearHeartbeatTimeout()}},{key:"clearHeartbeatTimeout",value:function(){this.heartbeatTimeoutTimer&&(clearTimeout(this.heartbeatTimeoutTimer),this.heartbeatTimeoutTimer=null)}},{key:"reconnect",value:function(){var e=this;if(!this.isConnected){if(this.maxReconnect!==-1&&this.reconnectCount>=this.maxReconnect){console.log("Reach max reconnect count, stop reconnect");return}this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.reconnectCount+=1,console.log("Reconnecting in ".concat(this.reconnectDelay/1e3," seconds... count:").concat(this.reconnectCount)),this.reconnectTimer=setTimeout(function(){e.connect()},this.reconnectDelay)}}},{key:"close",value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:1e3,t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"";this.stopHeartbeat(),this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.reconnectCount=0,this.socketTask&&this.socketTask.close({code:e,reason:t})}}])}(),v=require("./lodash");Object.assign(exports,v);exports.alipaySubmit=p.alipaySubmit;exports.exchangeArrP=n.exchangeArrP;exports.filterTree=n.filterTree;exports.findTreeItem=n.findTreeItem;exports.flatWithKey=n.flatWithKey;exports.getTreePath=n.getTreePath;exports.groupBy=n.groupBy;exports.reverseForEach=n.reverseForEach;exports.treeItemSetParent=n.treeItemSetParent;exports.StorageCache=h.StorageCache;exports.localCache=h.localCache;exports.sessionCache=h.sessionCache;exports.dateFormat=T.dateFormat;exports.getDate=T.getDate;exports.$fs=i.$fs;exports.chooseImg=i.chooseImg;exports.getArraybufferTempPath=i.getArraybufferTempPath;exports.getImgBase64Prefix=i.getImgBase64Prefix;exports.readFile=i.readFile;exports.saveImageToPhotosAlbum=i.saveImageToPhotosAlbum;exports.writeFile=i.writeFile;exports.getLocation=f.getLocation;exports.openLocation=f.openLocation;exports.CONTENT_TYPES=s.CONTENT_TYPES;exports.CancelToken=s.CancelToken;exports.createDownloadFile=s.createDownloadFile;exports.createRequest=s.createRequest;exports.createUploadFile=s.createUploadFile;exports.promisifyRequest=s.promisifyRequest;exports.compareVersion=a.compareVersion;exports.compose=a.compose;exports.composeAsync=a.composeAsync;exports.debounce=a.debounce;exports.debouncePromise=a.debouncePromise;exports.decodeURIParams=a.decodeURIParams;exports.encodeURIParams=a.encodeURIParams;exports.getOnLoadParams=a.getOnLoadParams;exports.getPascalCase=a.getPascalCase;exports.getQueryParams=a.getQueryParams;exports.getQueryParamsFromHash=a.getQueryParamsFromHash;exports.getQueryParamsFromSearch=a.getQueryParamsFromSearch;exports.getRandom=a.getRandom;exports.getRandomStr=a.getRandomStr;exports.pipe=a.pipe;exports.pipeAsync=a.pipeAsync;exports.randomColor=a.randomColor;exports.throttle=a.throttle;exports.toQueryString=a.toQueryString;exports.cloneDeepWithDescriptors=m.cloneDeepWithDescriptors;exports.getRawType=m.getRawType;exports.hasOwnProperty=m.hasOwnProperty;exports.backToRoute=o.backToRoute;exports.findPageByFullPath=o.findPageByFullPath;exports.findPageByRoute=o.findPageByRoute;exports.getCurrentPage=o.getCurrentPage;exports.getCurrentPageOptions=o.getCurrentPageOptions;exports.getCurrentRoute=o.getCurrentRoute;exports.getPageStack=o.getPageStack;exports.getPageVm=o.getPageVm;exports.getPrevPage=o.getPrevPage;exports.getPrevRoute=o.getPrevRoute;exports.isExternal=c.isExternal;exports.validDate=c.validDate;exports.validIDCard=c.validIDCard;exports.validPhone=c.validPhone;exports.validPostalCode=c.validPostalCode;exports.validURL=c.validURL;exports.wx=P.index;exports.WebSocketClient=k;
@@ -99,14 +99,13 @@ export interface GetQueryParamsOptions {
99
99
  }
100
100
 
101
101
  /**
102
- * 解析 URL query 字符串,相同 key 自动转为数组
102
+ * 解析 URL query 字符串,自动识别多种数组形式:a=1&a=2、a[]=1&a[]=2、a[0]=1&a[1]=2
103
103
  * 支持传入完整 URL / query 字符串,自动剔除 hash
104
- *
105
104
  * @param str 完整 url / query 字符串,可以带开头 ?,可携带 #hash
106
105
  * @param options 配置选项
107
- * @returns 解析结果
106
+ * @returns 解析结果对象
108
107
  */
109
- export declare function getQueryParams(str?: string, options?: GetQueryParamsOptions): Record<string, string | string[]>;
108
+ export function getQueryParams(str?: string, options?: GetQueryParamsOptions): Record<string, string | string[]>;
110
109
 
111
110
  /**
112
111
  * 从当前页面 URL 的 search 部分解析参数(仅浏览器环境)
@@ -160,14 +159,24 @@ export function randomColor(): string;
160
159
  */
161
160
  export function getRandomStr(len?: number, $chars?: string): string;
162
161
 
162
+ export type ArrayFormatType = 'indices' | 'brackets' | 'repeat' | 'comma';
163
+
164
+ export interface ToQueryStringOptions {
165
+ /** 是否前置 ? */
166
+ addQuestionMark?: boolean;
167
+ /** 数组格式化模式,默认 comma */
168
+ arrayFormat?: ArrayFormatType;
169
+ /** true:空数组输出key=;false:空数组直接丢弃,默认 false */
170
+ keepEmptyArray?: boolean;
171
+ }
172
+
163
173
  /**
164
174
  * 对象转url query字符串
165
- * 数组自动展开为重复key,与 getQueryParams 解析行为双向对称
166
175
  * @param params 参数对象
167
- * @param addQuestionMark 是否添加开头问号 ?
168
- * @returns query串
176
+ * @param options 配置项
177
+ * @returns query字符串
169
178
  */
170
- export declare function toQueryString(params: Record<string, any>, addQuestionMark?: boolean): string;
179
+ export function toQueryString(params: Record<string, any> | null | undefined, options?: ToQueryStringOptions): string;
171
180
 
172
181
  /**
173
182
  * 获取页面onLoad参数(自动解析小程序扫码scene)
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../_rollupPluginBabelHelpers-63255c86.js");function U(){for(var t=arguments.length,a=new Array(t),o=0;o<t;o++)a[o]=arguments[o];if(a.some(function(r){return typeof r!="function"}))throw new TypeError("compose 参数必须是函数");return a.length===0?function(){for(var r=arguments.length,e=new Array(r),n=0;n<r;n++)e[n]=arguments[n];return e.length===1?e[0]:e}:a.reduce(function(r,e){return function(){for(var n=this,u=arguments.length,i=new Array(u),c=0;c<u;c++)i[c]=arguments[c];return e.call.apply(e,[this,function(){for(var f=arguments.length,g=new Array(f),l=0;l<f;l++)g[l]=arguments[l];return r.apply(n,g.concat(i))}].concat(i))}},function(r){return r})}function M(){for(var t=arguments.length,a=new Array(t),o=0;o<t;o++)a[o]=arguments[o];if(a.some(function(r){return typeof r!="function"}))throw new TypeError("composeAsync 参数必须是函数");return a.length===0?s._asyncToGenerator(s._regenerator().m(function r(){var e,n,u,i=arguments;return s._regenerator().w(function(c){for(;;)switch(c.n){case 0:for(e=i.length,n=new Array(e),u=0;u<e;u++)n[u]=i[u];return c.a(2,n.length===1?n[0]:n)}},r)})):a.reduce(function(r,e){return s._asyncToGenerator(s._regenerator().m(function n(){var u=this,i,c,f,g=arguments;return s._regenerator().w(function(l){for(;;)switch(l.n){case 0:for(i=g.length,c=new Array(i),f=0;f<i;f++)c[f]=g[f];return l.a(2,e.call.apply(e,[this,s._asyncToGenerator(s._regenerator().m(function y(){var p,h,m,d=arguments;return s._regenerator().w(function(v){for(;;)switch(v.n){case 0:for(p=d.length,h=new Array(p),m=0;m<p;m++)h[m]=d[m];return v.a(2,r.apply(u,h.concat(c)))}},y)}))].concat(c)))}},n,this)}))},function(){var r=s._asyncToGenerator(s._regenerator().m(function e(n){return s._regenerator().w(function(u){for(;;)switch(u.n){case 0:return u.a(2,n)}},e)}));return function(e){return r.apply(this,arguments)}}())}function O(){for(var t=arguments.length,a=new Array(t),o=0;o<t;o++)a[o]=arguments[o];if(a.some(function(r){return typeof r!="function"}))throw new TypeError("pipe 参数必须是函数");return a.length===0?function(){for(var r=arguments.length,e=new Array(r),n=0;n<r;n++)e[n]=arguments[n];return e.length===1?e[0]:e}:a.reverse().reduce(function(r,e){return function(){for(var n=this,u=arguments.length,i=new Array(u),c=0;c<u;c++)i[c]=arguments[c];return e.call.apply(e,[this,function(){for(var f=arguments.length,g=new Array(f),l=0;l<f;l++)g[l]=arguments[l];return r.apply(n,g.concat(i))}].concat(i))}},function(r){return r})}function Q(){for(var t=arguments.length,a=new Array(t),o=0;o<t;o++)a[o]=arguments[o];if(a.some(function(r){return typeof r!="function"}))throw new TypeError("pipeAsync 参数必须是函数");return a.length===0?s._asyncToGenerator(s._regenerator().m(function r(){var e,n,u,i=arguments;return s._regenerator().w(function(c){for(;;)switch(c.n){case 0:for(e=i.length,n=new Array(e),u=0;u<e;u++)n[u]=i[u];return c.a(2,n.length===1?n[0]:n)}},r)})):a.reverse().reduce(function(r,e){return s._asyncToGenerator(s._regenerator().m(function n(){var u=this,i,c,f,g=arguments;return s._regenerator().w(function(l){for(;;)switch(l.n){case 0:for(i=g.length,c=new Array(i),f=0;f<i;f++)c[f]=g[f];return l.a(2,e.call.apply(e,[this,s._asyncToGenerator(s._regenerator().m(function y(){var p,h,m,d=arguments;return s._regenerator().w(function(v){for(;;)switch(v.n){case 0:for(p=d.length,h=new Array(p),m=0;m<p;m++)h[m]=d[m];return v.a(2,r.apply(u,h.concat(c)))}},y)}))].concat(c)))}},n,this)}))},function(){var r=s._asyncToGenerator(s._regenerator().m(function e(n){return s._regenerator().w(function(u){for(;;)switch(u.n){case 0:return u.a(2,n)}},e)}));return function(e){return r.apply(this,arguments)}}())}function j(t,a){var o=null;r.stop=function(){return o&&clearTimeout(o)};function r(){for(var e=this,n=arguments.length,u=new Array(n),i=0;i<n;i++)u[i]=arguments[i];r.stop(),o=setTimeout(function(){t.apply(e,u)},a)}return r}function G(t,a){var o=null,r=[];e.stop=function(){if(o){var n;(n=r.shift())===null||n===void 0||n("cancel"),clearTimeout(o)}};function e(){for(var n=this,u=arguments.length,i=new Array(u),c=0;c<u;c++)i[c]=arguments[c];return new Promise(function(f,g){e.stop(),r.push(g),o=setTimeout(function(){f(t.apply(n,i))},a)})}return e}function E(t){var a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:500,o=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0,r;return o?function(){if(!r){r=!0;for(var e=arguments.length,n=new Array(e),u=0;u<e;u++)n[u]=arguments[u];typeof t=="function"&&t.apply(this,n),setTimeout(function(){r=!1},a)}}:function(){for(var e=this,n=arguments.length,u=new Array(n),i=0;i<n;i++)u[i]=arguments[i];r||(r=!0,setTimeout(function(){r=!1,typeof t=="function"&&t.apply(e,u)},a))}}function F(t){return encodeURIComponent(JSON.stringify(t||{}))}function H(t){return JSON.parse(decodeURIComponent(t||"{}"))}function S(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"",a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},o=a.silent,r=o===void 0?!1:o,e=a.decodePlus,n=e===void 0?!0:e,u=a.strict,i=u===void 0?!1:u,c={};if(typeof t!="string")return c;function f(b,R){var w=b;n&&(w=w.replace(/\+/g," "));try{return decodeURIComponent(w)}catch(I){return r||console.warn("Failed to decode ".concat(R?"key":"value",": ").concat(w),I),i?null:(R&&(w=w.replace(/%[0-9a-f]{2}/gi,"")),w)}}var g=t.split("#")[0],l=g.indexOf("?"),y=l>=0?g.slice(l+1):g;if(!y)return c;for(var p=y.split("&"),h=0;h<p.length;h++){var m=p[h];if(m){var d=m.indexOf("="),v=void 0,C=void 0;d===-1?(v=m,C=""):(v=m.slice(0,d),C=m.slice(d+1));var A=f(v,!0);if(A!==null){var P=f(C,!1);if(P!==null&&A){var T=c[A];T===void 0?c[A]=P:Array.isArray(T)?T.push(P):c[A]=[T,P]}}}}return c}function L(t){return typeof window=="undefined"?{}:S(window.location.search,t)}function _(t){if(typeof window=="undefined")return{};var a=window.location.hash,o=a.indexOf("?");if(o===-1)return{};var r=a.substring(o);return S(r,t)}function J(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"-";return[Date.now().toString(),Math.random().toString(16).slice(2,10),Math.random().toString(16).slice(7),t.toString()].join(a)}function N(t){return t.replace(/([^-])([^-]*)/g,function(a,o,r){return o.toLocaleUpperCase()+r.toLocaleLowerCase()}).replace(/-/g,"")}function q(t,a){t=t.split("."),a=a.split(".");for(var o=Math.max(t.length,a.length);t.length<o;)t.push("0");for(;a.length<o;)a.push("0");for(var r=0;r<o;r++){var e=parseInt(t[r]),n=parseInt(a[r]);if(e>n)return 1;if(e<n)return-1}return 0}function B(){return"#"+Math.floor(Math.random()*16777215).toString(16).padEnd(6,"0")}function D(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:8,a=arguments.length>1?arguments[1]:void 0;t=t||32,a||(a="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678");for(var o=a.length,r="",e=0;e<t;e++)r+=a.charAt(Math.floor(Math.random()*o));return r}function V(t){var a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1;if(!t||s._typeof(t)!=="object")return"";var o=[];Object.keys(t).forEach(function(e){var n=t[e];if(n!=null){var u=encodeURIComponent(e);if(Array.isArray(n)){n.forEach(function(c){var f=encodeURIComponent(c);o.push("".concat(u,"=").concat(f))});return}var i=n;s._typeof(i)==="object"&&i!==null&&(i=JSON.stringify(i)),o.push("".concat(u,"=").concat(encodeURIComponent(i)))}});var r=o.join("&");return a&&r?"?".concat(r):r}function $(t){var a=t.scene;return a&&(t=s._objectSpread2(s._objectSpread2({fromCode:!0},t),S(a))),t}exports.compareVersion=q;exports.compose=U;exports.composeAsync=M;exports.debounce=j;exports.debouncePromise=G;exports.decodeURIParams=H;exports.encodeURIParams=F;exports.getOnLoadParams=$;exports.getPascalCase=N;exports.getQueryParams=S;exports.getQueryParamsFromHash=_;exports.getQueryParamsFromSearch=L;exports.getRandom=J;exports.getRandomStr=D;exports.pipe=O;exports.pipeAsync=Q;exports.randomColor=B;exports.throttle=E;exports.toQueryString=V;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../_rollupPluginBabelHelpers-63255c86.js");function M(){for(var e=arguments.length,a=new Array(e),o=0;o<e;o++)a[o]=arguments[o];if(a.some(function(r){return typeof r!="function"}))throw new TypeError("compose 参数必须是函数");return a.length===0?function(){for(var r=arguments.length,n=new Array(r),t=0;t<r;t++)n[t]=arguments[t];return n.length===1?n[0]:n}:a.reduce(function(r,n){return function(){for(var t=this,u=arguments.length,i=new Array(u),c=0;c<u;c++)i[c]=arguments[c];return n.call.apply(n,[this,function(){for(var s=arguments.length,m=new Array(s),h=0;h<s;h++)m[h]=arguments[h];return r.apply(t,m.concat(i))}].concat(i))}},function(r){return r})}function Q(){for(var e=arguments.length,a=new Array(e),o=0;o<e;o++)a[o]=arguments[o];if(a.some(function(r){return typeof r!="function"}))throw new TypeError("composeAsync 参数必须是函数");return a.length===0?l._asyncToGenerator(l._regenerator().m(function r(){var n,t,u,i=arguments;return l._regenerator().w(function(c){for(;;)switch(c.n){case 0:for(n=i.length,t=new Array(n),u=0;u<n;u++)t[u]=i[u];return c.a(2,t.length===1?t[0]:t)}},r)})):a.reduce(function(r,n){return l._asyncToGenerator(l._regenerator().m(function t(){var u=this,i,c,s,m=arguments;return l._regenerator().w(function(h){for(;;)switch(h.n){case 0:for(i=m.length,c=new Array(i),s=0;s<i;s++)c[s]=m[s];return h.a(2,n.call.apply(n,[this,l._asyncToGenerator(l._regenerator().m(function w(){var v,g,f,p=arguments;return l._regenerator().w(function(d){for(;;)switch(d.n){case 0:for(v=p.length,g=new Array(v),f=0;f<v;f++)g[f]=p[f];return d.a(2,r.apply(u,g.concat(c)))}},w)}))].concat(c)))}},t,this)}))},function(){var r=l._asyncToGenerator(l._regenerator().m(function n(t){return l._regenerator().w(function(u){for(;;)switch(u.n){case 0:return u.a(2,t)}},n)}));return function(n){return r.apply(this,arguments)}}())}function j(){for(var e=arguments.length,a=new Array(e),o=0;o<e;o++)a[o]=arguments[o];if(a.some(function(r){return typeof r!="function"}))throw new TypeError("pipe 参数必须是函数");return a.length===0?function(){for(var r=arguments.length,n=new Array(r),t=0;t<r;t++)n[t]=arguments[t];return n.length===1?n[0]:n}:a.reverse().reduce(function(r,n){return function(){for(var t=this,u=arguments.length,i=new Array(u),c=0;c<u;c++)i[c]=arguments[c];return n.call.apply(n,[this,function(){for(var s=arguments.length,m=new Array(s),h=0;h<s;h++)m[h]=arguments[h];return r.apply(t,m.concat(i))}].concat(i))}},function(r){return r})}function O(){for(var e=arguments.length,a=new Array(e),o=0;o<e;o++)a[o]=arguments[o];if(a.some(function(r){return typeof r!="function"}))throw new TypeError("pipeAsync 参数必须是函数");return a.length===0?l._asyncToGenerator(l._regenerator().m(function r(){var n,t,u,i=arguments;return l._regenerator().w(function(c){for(;;)switch(c.n){case 0:for(n=i.length,t=new Array(n),u=0;u<n;u++)t[u]=i[u];return c.a(2,t.length===1?t[0]:t)}},r)})):a.reverse().reduce(function(r,n){return l._asyncToGenerator(l._regenerator().m(function t(){var u=this,i,c,s,m=arguments;return l._regenerator().w(function(h){for(;;)switch(h.n){case 0:for(i=m.length,c=new Array(i),s=0;s<i;s++)c[s]=m[s];return h.a(2,n.call.apply(n,[this,l._asyncToGenerator(l._regenerator().m(function w(){var v,g,f,p=arguments;return l._regenerator().w(function(d){for(;;)switch(d.n){case 0:for(v=p.length,g=new Array(v),f=0;f<v;f++)g[f]=p[f];return d.a(2,r.apply(u,g.concat(c)))}},w)}))].concat(c)))}},t,this)}))},function(){var r=l._asyncToGenerator(l._regenerator().m(function n(t){return l._regenerator().w(function(u){for(;;)switch(u.n){case 0:return u.a(2,t)}},n)}));return function(n){return r.apply(this,arguments)}}())}function F(e,a){var o=null;r.stop=function(){return o&&clearTimeout(o)};function r(){for(var n=this,t=arguments.length,u=new Array(t),i=0;i<t;i++)u[i]=arguments[i];r.stop(),o=setTimeout(function(){e.apply(n,u)},a)}return r}function G(e,a){var o=null,r=[];n.stop=function(){if(o){var t;(t=r.shift())===null||t===void 0||t("cancel"),clearTimeout(o)}};function n(){for(var t=this,u=arguments.length,i=new Array(u),c=0;c<u;c++)i[c]=arguments[c];return new Promise(function(s,m){n.stop(),r.push(m),o=setTimeout(function(){s(e.apply(t,i))},a)})}return n}function _(e){var a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:500,o=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0,r;return o?function(){if(!r){r=!0;for(var n=arguments.length,t=new Array(n),u=0;u<n;u++)t[u]=arguments[u];typeof e=="function"&&e.apply(this,t),setTimeout(function(){r=!1},a)}}:function(){for(var n=this,t=arguments.length,u=new Array(t),i=0;i<t;i++)u[i]=arguments[i];r||(r=!0,setTimeout(function(){r=!1,typeof e=="function"&&e.apply(n,u)},a))}}function $(e){return encodeURIComponent(JSON.stringify(e||{}))}function H(e){return JSON.parse(decodeURIComponent(e||"{}"))}function R(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"",a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},o=a.silent,r=o===void 0?!1:o,n=a.decodePlus,t=n===void 0?!0:n,u=a.strict,i=u===void 0?!1:u,c={};if(typeof e!="string")return c;function s(U,I){var A=U;t&&(A=A.replace(/\+/g," "));try{return decodeURIComponent(A)}catch(E){return r||console.warn("Failed to decode ".concat(I?"key":"value",": ").concat(A),E),i?null:(I&&(A=A.replace(/%[0-9a-f]{2}/gi,"")),A)}}var m=e.split("#")[0],h=m.indexOf("?"),w=h>=0?m.slice(h+1):m;if(!w)return c;for(var v=w.split("&"),g=0;g<v.length;g++){var f=v[g];if(f){var p=f.indexOf("="),d=void 0,P=void 0;p===-1?(d=f,P=""):(d=f.slice(0,p),P=f.slice(p+1));var y=s(d,!0);if(!(y===null||!y)){var S=s(P,!1);if(S!==null){var T=y,b=!1;/\[\]$/.test(y)?(T=y.slice(0,-2),b=!0):/^(.+)\[\d+\]$/.test(y)&&(T=y.replace(/\[\d+\]$/,""),b=!0);var C=c[T];C===void 0?c[T]=b?[S]:S:Array.isArray(C)?C.push(S):c[T]=[C,S]}}}}return c}function L(e){return typeof window=="undefined"?{}:R(window.location.search,e)}function J(e){if(typeof window=="undefined")return{};var a=window.location.hash,o=a.indexOf("?");if(o===-1)return{};var r=a.substring(o);return R(r,e)}function q(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"-";return[Date.now().toString(),Math.random().toString(16).slice(2,10),Math.random().toString(16).slice(7),e.toString()].join(a)}function B(e){return e.replace(/([^-])([^-]*)/g,function(a,o,r){return o.toLocaleUpperCase()+r.toLocaleLowerCase()}).replace(/-/g,"")}function D(e,a){e=e.split("."),a=a.split(".");for(var o=Math.max(e.length,a.length);e.length<o;)e.push("0");for(;a.length<o;)a.push("0");for(var r=0;r<o;r++){var n=parseInt(e[r]),t=parseInt(a[r]);if(n>t)return 1;if(n<t)return-1}return 0}function N(){return"#"+Math.floor(Math.random()*16777215).toString(16).padEnd(6,"0")}function z(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:8,a=arguments.length>1?arguments[1]:void 0;e=e||32,a||(a="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678");for(var o=a.length,r="",n=0;n<e;n++)r+=a.charAt(Math.floor(Math.random()*o));return r}function V(e){var a,o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!e||l._typeof(e)!=="object")return"";var r=o.addQuestionMark,n=r===void 0?!1:r,t=o.arrayFormat,u=t===void 0?"comma":t,i=o.keepEmptyArray,c=i===void 0?!1:i,s=[],m={indices:function(g,f){f.forEach(function(p,d){s.push("".concat(g,"[").concat(d,"]=").concat(encodeURIComponent(p)))})},brackets:function(g,f){f.forEach(function(p){s.push("".concat(g,"[]=").concat(encodeURIComponent(p)))})},repeat:function(g,f){f.forEach(function(p){s.push("".concat(g,"=").concat(encodeURIComponent(p)))})},comma:function(g,f){var p=f.map(function(d){return encodeURIComponent(d)}).join(",");s.push("".concat(g,"=").concat(p))}},h=(a=m[u])!==null&&a!==void 0?a:m.comma;Object.keys(e).forEach(function(v){var g=e[v];if(g!=null){var f=encodeURIComponent(v);if(Array.isArray(g)){var p=g.filter(function(P){return P!=null});if(p.length===0){c&&s.push("".concat(f,"="));return}h(f,p);return}var d=g;l._typeof(d)==="object"&&d!==null&&(d=JSON.stringify(d)),s.push("".concat(f,"=").concat(encodeURIComponent(d)))}});var w=s.join("&");return n&&w?"?".concat(w):w}function W(e){var a=e.scene;return a&&(e=l._objectSpread2(l._objectSpread2({fromCode:!0},e),R(a))),e}exports.compareVersion=D;exports.compose=M;exports.composeAsync=Q;exports.debounce=F;exports.debouncePromise=G;exports.decodeURIParams=H;exports.encodeURIParams=$;exports.getOnLoadParams=W;exports.getPascalCase=B;exports.getQueryParams=R;exports.getQueryParamsFromHash=J;exports.getQueryParamsFromSearch=L;exports.getRandom=q;exports.getRandomStr=z;exports.pipe=j;exports.pipeAsync=O;exports.randomColor=N;exports.throttle=_;exports.toQueryString=V;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utils-uniapp",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "aubyn's utils for uniapp",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",