utils-uniapp 1.2.2 → 1.2.3
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/lib/magic/index.d.ts +17 -8
- package/lib/magic/index.js +1 -1
- package/package.json +1 -1
package/lib/magic/index.d.ts
CHANGED
|
@@ -99,14 +99,13 @@ export interface GetQueryParamsOptions {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
|
-
* 解析 URL query
|
|
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
|
|
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
|
|
168
|
-
* @returns query
|
|
176
|
+
* @param options 配置项
|
|
177
|
+
* @returns query字符串
|
|
169
178
|
*/
|
|
170
|
-
export
|
|
179
|
+
export function toQueryString(params: Record<string, any> | null | undefined, options?: ToQueryStringOptions): string;
|
|
171
180
|
|
|
172
181
|
/**
|
|
173
182
|
* 获取页面onLoad参数(自动解析小程序扫码scene)
|
package/lib/magic/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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;
|