utils-uniapp 1.2.15 → 1.2.17

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/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./aliPay/index.js"),r=require("./array/index.js"),s=require("./cache/index.js"),g=require("./date/index.js"),d=require("./EventBus/index.js"),a=require("./fs/index.js"),u=require("./getLocation/index.js"),o=require("./http/index.js"),e=require("./magic/index.js"),c=require("./object/index.js"),t=require("./pageStack/index.js"),i=require("./validate/index.js"),n=require("./WebSocketClient/index.js"),P=require("./index-0114bbbf.js");require("./_rollupPluginBabelHelpers-3cc6d021.js");var m=require("./lodash");Object.assign(exports,m);exports.alipaySubmit=l.alipaySubmit;exports.exchangeArrP=r.exchangeArrP;exports.filterTree=r.filterTree;exports.findTreeItem=r.findTreeItem;exports.flatWithKey=r.flatWithKey;exports.getTreePath=r.getTreePath;exports.groupBy=r.groupBy;exports.reverseForEach=r.reverseForEach;exports.treeItemSetParent=r.treeItemSetParent;exports.StorageCache=s.StorageCache;exports.localCache=s.localCache;exports.sessionCache=s.sessionCache;exports.dateFormat=g.dateFormat;exports.getDate=g.getDate;exports.EventBus=d.EventBus;exports.eventBus=d.eventBus;exports.$fs=a.$fs;exports.chooseImg=a.chooseImg;exports.getArraybufferTempPath=a.getArraybufferTempPath;exports.getImgBase64Prefix=a.getImgBase64Prefix;exports.readFile=a.readFile;exports.saveImageToPhotosAlbum=a.saveImageToPhotosAlbum;exports.writeFile=a.writeFile;exports.getLocation=u.getLocation;exports.openLocation=u.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=c.cloneDeepWithDescriptors;exports.getRawType=c.getRawType;exports.hasOwnProperty=c.hasOwnProperty;exports.backToRoute=t.backToRoute;exports.findPageByFullPath=t.findPageByFullPath;exports.findPageByRoute=t.findPageByRoute;exports.getCurrentPage=t.getCurrentPage;exports.getCurrentPageOptions=t.getCurrentPageOptions;exports.getCurrentRoute=t.getCurrentRoute;exports.getPageStack=t.getPageStack;exports.getPageVm=t.getPageVm;exports.getPrevPage=t.getPrevPage;exports.getPrevRoute=t.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.BrowserWebSocketAdapter=n.BrowserWebSocketAdapter;exports.UniWebSocketAdapter=n.UniWebSocketAdapter;exports.UniWebSocketClient=n.UniWebSocketClient;exports.WebSocketClient=n.WebSocketClient;exports.wx=P.index;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./aliPay/index.js"),r=require("./array/index.js"),s=require("./cache/index.js"),g=require("./date/index.js"),d=require("./EventBus/index.js"),a=require("./fs/index.js"),u=require("./getLocation/index.js"),n=require("./http/index.js"),e=require("./magic/index.js"),c=require("./object/index.js"),t=require("./pageStack/index.js"),o=require("./validate/index.js"),i=require("./WebSocketClient/index.js"),P=require("./index-0114bbbf.js");require("./_rollupPluginBabelHelpers-3cc6d021.js");var m=require("./lodash");Object.assign(exports,m);exports.alipaySubmit=l.alipaySubmit;exports.exchangeArrP=r.exchangeArrP;exports.filterTree=r.filterTree;exports.findTreeItem=r.findTreeItem;exports.flatWithKey=r.flatWithKey;exports.getTreePath=r.getTreePath;exports.groupBy=r.groupBy;exports.reverseForEach=r.reverseForEach;exports.treeItemSetParent=r.treeItemSetParent;exports.StorageCache=s.StorageCache;exports.localCache=s.localCache;exports.sessionCache=s.sessionCache;exports.dateFormat=g.dateFormat;exports.getDate=g.getDate;exports.EventBus=d.EventBus;exports.eventBus=d.eventBus;exports.$fs=a.$fs;exports.chooseImg=a.chooseImg;exports.getArraybufferTempPath=a.getArraybufferTempPath;exports.getImgBase64Prefix=a.getImgBase64Prefix;exports.readFile=a.readFile;exports.saveImageToPhotosAlbum=a.saveImageToPhotosAlbum;exports.writeFile=a.writeFile;exports.getLocation=u.getLocation;exports.openLocation=u.openLocation;exports.CONTENT_TYPES=n.CONTENT_TYPES;exports.CancelToken=n.CancelToken;exports.createDownloadFile=n.createDownloadFile;exports.createRequest=n.createRequest;exports.createUploadFile=n.createUploadFile;exports.promisifyRequest=n.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=c.cloneDeepWithDescriptors;exports.getRawType=c.getRawType;exports.hasOwnProperty=c.hasOwnProperty;exports.backToRoute=t.backToRoute;exports.findPageByFullPath=t.findPageByFullPath;exports.findPageByRoute=t.findPageByRoute;exports.getCurrentPage=t.getCurrentPage;exports.getCurrentPageOptions=t.getCurrentPageOptions;exports.getCurrentRoute=t.getCurrentRoute;exports.getPageStack=t.getPageStack;exports.getPageVm=t.getPageVm;exports.getPrevPage=t.getPrevPage;exports.getPrevRoute=t.getPrevRoute;exports.getIdcardInfo=o.getIdcardInfo;exports.getNameError=o.getNameError;exports.isExternal=o.isExternal;exports.validDate=o.validDate;exports.validPhone=o.validPhone;exports.validPostalCode=o.validPostalCode;exports.validURL=o.validURL;exports.BrowserWebSocketAdapter=i.BrowserWebSocketAdapter;exports.UniWebSocketAdapter=i.UniWebSocketAdapter;exports.UniWebSocketClient=i.UniWebSocketClient;exports.WebSocketClient=i.WebSocketClient;exports.wx=P.index;
@@ -98,6 +98,8 @@ export type SearchParams = Record<string, string | string[]>;
98
98
  export interface GetQueryParamsOptions {
99
99
  /** 是否静默模式,不输出警告 */
100
100
  silent?: boolean;
101
+ /** 是否解码,默认true */
102
+ decode?: boolean;
101
103
  /** 是否将 + 号解码为空格 */
102
104
  decodePlus?: boolean;
103
105
  /** 严格模式,解码失败时跳过该参数 */
@@ -170,6 +172,8 @@ export type ArrayFormatType = 'indices' | 'brackets' | 'repeat' | 'comma';
170
172
  export interface ToQueryStringOptions {
171
173
  /** 是否前置 ? */
172
174
  addQuestionMark?: boolean;
175
+ /** 是否编码,默认true */
176
+ encode?: boolean;
173
177
  /** 数组格式化模式,默认 comma */
174
178
  arrayFormat?: ArrayFormatType;
175
179
  /** true:空数组输出key=;false:空数组直接丢弃,默认 false */
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../_rollupPluginBabelHelpers-3cc6d021.js");function M(){for(var e=arguments.length,t=new Array(e),o=0;o<e;o++)t[o]=arguments[o];if(t.some(function(r){return typeof r!="function"}))throw new TypeError("compose 参数必须是函数");return t.length===0?function(){for(var r=arguments.length,n=new Array(r),a=0;a<r;a++)n[a]=arguments[a];return n.length===1?n[0]:n}:t.reduce(function(r,n){return function(){for(var a=this,i=arguments.length,c=new Array(i),u=0;u<i;u++)c[u]=arguments[u];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(a,m.concat(c))}].concat(c))}},function(r){return r})}function Q(){for(var e=arguments.length,t=new Array(e),o=0;o<e;o++)t[o]=arguments[o];if(t.some(function(r){return typeof r!="function"}))throw new TypeError("composeAsync 参数必须是函数");return t.length===0?l._asyncToGenerator(l._regenerator().m(function r(){var n,a,i,c=arguments;return l._regenerator().w(function(u){for(;;)switch(u.n){case 0:for(n=c.length,a=new Array(n),i=0;i<n;i++)a[i]=c[i];return u.a(2,a.length===1?a[0]:a)}},r)})):t.reduce(function(r,n){return l._asyncToGenerator(l._regenerator().m(function a(){var i=this,c,u,s,m=arguments;return l._regenerator().w(function(h){for(;;)switch(h.n){case 0:for(c=m.length,u=new Array(c),s=0;s<c;s++)u[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(i,g.concat(u)))}},w)}))].concat(u)))}},a,this)}))},function(){var r=l._asyncToGenerator(l._regenerator().m(function n(a){return l._regenerator().w(function(i){for(;;)switch(i.n){case 0:return i.a(2,a)}},n)}));return function(n){return r.apply(this,arguments)}}())}function j(){for(var e=arguments.length,t=new Array(e),o=0;o<e;o++)t[o]=arguments[o];if(t.some(function(r){return typeof r!="function"}))throw new TypeError("pipe 参数必须是函数");return t.length===0?function(){for(var r=arguments.length,n=new Array(r),a=0;a<r;a++)n[a]=arguments[a];return n.length===1?n[0]:n}:t.reverse().reduce(function(r,n){return function(){for(var a=this,i=arguments.length,c=new Array(i),u=0;u<i;u++)c[u]=arguments[u];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(a,m.concat(c))}].concat(c))}},function(r){return r})}function O(){for(var e=arguments.length,t=new Array(e),o=0;o<e;o++)t[o]=arguments[o];if(t.some(function(r){return typeof r!="function"}))throw new TypeError("pipeAsync 参数必须是函数");return t.length===0?l._asyncToGenerator(l._regenerator().m(function r(){var n,a,i,c=arguments;return l._regenerator().w(function(u){for(;;)switch(u.n){case 0:for(n=c.length,a=new Array(n),i=0;i<n;i++)a[i]=c[i];return u.a(2,a.length===1?a[0]:a)}},r)})):t.reverse().reduce(function(r,n){return l._asyncToGenerator(l._regenerator().m(function a(){var i=this,c,u,s,m=arguments;return l._regenerator().w(function(h){for(;;)switch(h.n){case 0:for(c=m.length,u=new Array(c),s=0;s<c;s++)u[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(i,g.concat(u)))}},w)}))].concat(u)))}},a,this)}))},function(){var r=l._asyncToGenerator(l._regenerator().m(function n(a){return l._regenerator().w(function(i){for(;;)switch(i.n){case 0:return i.a(2,a)}},n)}));return function(n){return r.apply(this,arguments)}}())}function F(e,t){var o=null;r.stop=function(){return o&&clearTimeout(o)};function r(){for(var n=this,a=arguments.length,i=new Array(a),c=0;c<a;c++)i[c]=arguments[c];return r.stop(),o=setTimeout(function(){e.apply(n,i)},t),o}return r}function G(e,t){var o=null,r=[];n.stop=function(){if(o){var a;(a=r.shift())===null||a===void 0||a("cancel"),clearTimeout(o)}};function n(){for(var a=this,i=arguments.length,c=new Array(i),u=0;u<i;u++)c[u]=arguments[u];return new Promise(function(s,m){n.stop(),r.push(m),o=setTimeout(function(){s(e.apply(a,c))},t)})}return n}function _(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:500,o=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0,r,n,a=o?function(){if(!n){n=!0;for(var i=arguments.length,c=new Array(i),u=0;u<i;u++)c[u]=arguments[u];return typeof e=="function"&&e.apply(this,c),r=setTimeout(function(){n=!1},t),r}}:function(){for(var i=this,c=arguments.length,u=new Array(c),s=0;s<c;s++)u[s]=arguments[s];if(!n)return n=!0,r=setTimeout(function(){n=!1,typeof e=="function"&&e.apply(i,u)},t),r};return a.stop=function(){return r&&clearTimeout(r)},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]:"",t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},o=t.silent,r=o===void 0?!1:o,n=t.decodePlus,a=n===void 0?!0:n,i=t.strict,c=i===void 0?!1:i,u={};if(typeof e!="string")return u;function s(U,I){var A=U;a&&(A=A.replace(/\+/g," "));try{return decodeURIComponent(A)}catch(E){return r||console.warn("Failed to decode ".concat(I?"key":"value",": ").concat(A),E),c?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 u;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=u[T];C===void 0?u[T]=b?[S]:S:Array.isArray(C)?C.push(S):u[T]=[C,S]}}}}return u}function L(e){return typeof window=="undefined"?{}:R(window.location.search,e)}function J(e){if(typeof window=="undefined")return{};var t=window.location.hash,o=t.indexOf("?");if(o===-1)return{};var r=t.substring(o);return R(r,e)}function q(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,t=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(t)}function B(e){return e.replace(/([^-])([^-]*)/g,function(t,o,r){return o.toLocaleUpperCase()+r.toLocaleLowerCase()}).replace(/-/g,"")}function D(e,t){e=e.split("."),t=t.split(".");for(var o=Math.max(e.length,t.length);e.length<o;)e.push("0");for(;t.length<o;)t.push("0");for(var r=0;r<o;r++){var n=parseInt(e[r]),a=parseInt(t[r]);if(n>a)return 1;if(n<a)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,t=arguments.length>1?arguments[1]:void 0;e=e||32,t||(t="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678");for(var o=t.length,r="",n=0;n<e;n++)r+=t.charAt(Math.floor(Math.random()*o));return r}function V(e){var t,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,a=o.arrayFormat,i=a===void 0?"comma":a,c=o.keepEmptyArray,u=c===void 0?!1:c,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=(t=m[i])!==null&&t!==void 0?t: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){u&&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 t=e.scene;return t&&(e=l._objectSpread2(l._objectSpread2({fromCode:!0},e),R(t))),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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../_rollupPluginBabelHelpers-3cc6d021.js");function j(){for(var e=arguments.length,t=new Array(e),o=0;o<e;o++)t[o]=arguments[o];if(t.some(function(r){return typeof r!="function"}))throw new TypeError("compose 参数必须是函数");return t.length===0?function(){for(var r=arguments.length,n=new Array(r),a=0;a<r;a++)n[a]=arguments[a];return n.length===1?n[0]:n}:t.reduce(function(r,n){return function(){for(var a=this,u=arguments.length,c=new Array(u),i=0;i<u;i++)c[i]=arguments[i];return n.call.apply(n,[this,function(){for(var s=arguments.length,m=new Array(s),l=0;l<s;l++)m[l]=arguments[l];return r.apply(a,m.concat(c))}].concat(c))}},function(r){return r})}function O(){for(var e=arguments.length,t=new Array(e),o=0;o<e;o++)t[o]=arguments[o];if(t.some(function(r){return typeof r!="function"}))throw new TypeError("composeAsync 参数必须是函数");return t.length===0?f._asyncToGenerator(f._regenerator().m(function r(){var n,a,u,c=arguments;return f._regenerator().w(function(i){for(;;)switch(i.n){case 0:for(n=c.length,a=new Array(n),u=0;u<n;u++)a[u]=c[u];return i.a(2,a.length===1?a[0]:a)}},r)})):t.reduce(function(r,n){return f._asyncToGenerator(f._regenerator().m(function a(){var u=this,c,i,s,m=arguments;return f._regenerator().w(function(l){for(;;)switch(l.n){case 0:for(c=m.length,i=new Array(c),s=0;s<c;s++)i[s]=m[s];return l.a(2,n.call.apply(n,[this,f._asyncToGenerator(f._regenerator().m(function v(){var y,P,p,h=arguments;return f._regenerator().w(function(g){for(;;)switch(g.n){case 0:for(y=h.length,P=new Array(y),p=0;p<y;p++)P[p]=h[p];return g.a(2,r.apply(u,P.concat(i)))}},v)}))].concat(i)))}},a,this)}))},function(){var r=f._asyncToGenerator(f._regenerator().m(function n(a){return f._regenerator().w(function(u){for(;;)switch(u.n){case 0:return u.a(2,a)}},n)}));return function(n){return r.apply(this,arguments)}}())}function F(){for(var e=arguments.length,t=new Array(e),o=0;o<e;o++)t[o]=arguments[o];if(t.some(function(r){return typeof r!="function"}))throw new TypeError("pipe 参数必须是函数");return t.length===0?function(){for(var r=arguments.length,n=new Array(r),a=0;a<r;a++)n[a]=arguments[a];return n.length===1?n[0]:n}:t.reverse().reduce(function(r,n){return function(){for(var a=this,u=arguments.length,c=new Array(u),i=0;i<u;i++)c[i]=arguments[i];return n.call.apply(n,[this,function(){for(var s=arguments.length,m=new Array(s),l=0;l<s;l++)m[l]=arguments[l];return r.apply(a,m.concat(c))}].concat(c))}},function(r){return r})}function G(){for(var e=arguments.length,t=new Array(e),o=0;o<e;o++)t[o]=arguments[o];if(t.some(function(r){return typeof r!="function"}))throw new TypeError("pipeAsync 参数必须是函数");return t.length===0?f._asyncToGenerator(f._regenerator().m(function r(){var n,a,u,c=arguments;return f._regenerator().w(function(i){for(;;)switch(i.n){case 0:for(n=c.length,a=new Array(n),u=0;u<n;u++)a[u]=c[u];return i.a(2,a.length===1?a[0]:a)}},r)})):t.reverse().reduce(function(r,n){return f._asyncToGenerator(f._regenerator().m(function a(){var u=this,c,i,s,m=arguments;return f._regenerator().w(function(l){for(;;)switch(l.n){case 0:for(c=m.length,i=new Array(c),s=0;s<c;s++)i[s]=m[s];return l.a(2,n.call.apply(n,[this,f._asyncToGenerator(f._regenerator().m(function v(){var y,P,p,h=arguments;return f._regenerator().w(function(g){for(;;)switch(g.n){case 0:for(y=h.length,P=new Array(y),p=0;p<y;p++)P[p]=h[p];return g.a(2,r.apply(u,P.concat(i)))}},v)}))].concat(i)))}},a,this)}))},function(){var r=f._asyncToGenerator(f._regenerator().m(function n(a){return f._regenerator().w(function(u){for(;;)switch(u.n){case 0:return u.a(2,a)}},n)}));return function(n){return r.apply(this,arguments)}}())}function I(e,t){var o=null;r.stop=function(){return o&&clearTimeout(o)};function r(){for(var n=this,a=arguments.length,u=new Array(a),c=0;c<a;c++)u[c]=arguments[c];return r.stop(),o=setTimeout(function(){e.apply(n,u)},t),o}return r}function U(e,t){var o=null,r=[];n.stop=function(){if(o){var a;(a=r.shift())===null||a===void 0||a("cancel"),clearTimeout(o)}};function n(){for(var a=this,u=arguments.length,c=new Array(u),i=0;i<u;i++)c[i]=arguments[i];return new Promise(function(s,m){n.stop(),r.push(m),o=setTimeout(function(){s(e.apply(a,c))},t)})}return n}function H(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:500,o=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0,r,n,a=o?function(){if(!n){n=!0;for(var u=arguments.length,c=new Array(u),i=0;i<u;i++)c[i]=arguments[i];return typeof e=="function"&&e.apply(this,c),r=setTimeout(function(){n=!1},t),r}}:function(){for(var u=this,c=arguments.length,i=new Array(c),s=0;s<c;s++)i[s]=arguments[s];if(!n)return n=!0,r=setTimeout(function(){n=!1,typeof e=="function"&&e.apply(u,i)},t),r};return a.stop=function(){return r&&clearTimeout(r)},a}function L(e){return encodeURIComponent(JSON.stringify(e||{}))}function J(e){return JSON.parse(decodeURIComponent(e||"{}"))}function R(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"",t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},o=t.decode,r=o===void 0?!0:o,n=t.silent,a=n===void 0?!1:n,u=t.decodePlus,c=u===void 0?!0:u,i=t.strict,s=i===void 0?!1:i,m={};if(typeof e!="string")return m;function l(Q,_){if(!r)return Q;var T=Q;c&&(T=T.replace(/\+/g," "));try{return decodeURIComponent(T)}catch($){return a||console.warn("Failed to decode ".concat(_?"key":"value",": ").concat(T),$),s?null:(_&&(T=T.replace(/%[0-9a-f]{2}/gi,"")),T)}}var v=e.split("#")[0],y=v.indexOf("?"),P=y>=0?v.slice(y+1):v;if(!P)return m;for(var p=P.split("&"),h=0;h<p.length;h++){var g=p[h];if(g){var d=g.indexOf("="),w=void 0,A=void 0;d===-1?(w=g,A=""):(w=g.slice(0,d),A=g.slice(d+1));var S=l(w,!0);if(!(S===null||!S)){var b=l(A,!1);if(b!==null){var C=S,M=!1;/\[\]$/.test(S)?(C=S.slice(0,-2),M=!0):/^(.+)\[\d+\]$/.test(S)&&(C=S.replace(/\[\d+\]$/,""),M=!0);var E=m[C];E===void 0?m[C]=M?[b]:b:Array.isArray(E)?E.push(b):m[C]=[E,b]}}}}return m}function q(e){return typeof window=="undefined"?{}:R(window.location.search,e)}function B(e){if(typeof window=="undefined")return{};var t=window.location.hash,o=t.indexOf("?");if(o===-1)return{};var r=t.substring(o);return R(r,e)}function D(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,t=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(t)}function N(e){return e.replace(/([^-])([^-]*)/g,function(t,o,r){return o.toLocaleUpperCase()+r.toLocaleLowerCase()}).replace(/-/g,"")}function z(e,t){e=e.split("."),t=t.split(".");for(var o=Math.max(e.length,t.length);e.length<o;)e.push("0");for(;t.length<o;)t.push("0");for(var r=0;r<o;r++){var n=parseInt(e[r]),a=parseInt(t[r]);if(n>a)return 1;if(n<a)return-1}return 0}function V(){return"#"+Math.floor(Math.random()*16777215).toString(16).padEnd(6,"0")}function W(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:8,t=arguments.length>1?arguments[1]:void 0;e=e||32,t||(t="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678");for(var o=t.length,r="",n=0;n<e;n++)r+=t.charAt(Math.floor(Math.random()*o));return r}function X(e){var t,o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!e||f._typeof(e)!=="object")return"";var r=o.addQuestionMark,n=r===void 0?!1:r,a=o.encode,u=a===void 0?!0:a,c=o.arrayFormat,i=c===void 0?"comma":c,s=o.keepEmptyArray,m=s===void 0?!1:s,l=[];function v(h){return u?encodeURIComponent(h):h}var y={indices:function(g,d){d.forEach(function(w,A){l.push("".concat(g,"[").concat(A,"]=").concat(v(w)))})},brackets:function(g,d){d.forEach(function(w){l.push("".concat(g,"[]=").concat(v(w)))})},repeat:function(g,d){d.forEach(function(w){l.push("".concat(g,"=").concat(v(w)))})},comma:function(g,d){var w=d.map(function(A){return v(A)}).join(",");l.push("".concat(g,"=").concat(w))}},P=(t=y[i])!==null&&t!==void 0?t:y.comma;Object.keys(e).forEach(function(h){var g=e[h];if(g!=null){var d=v(h);if(Array.isArray(g)){var w=g.filter(function(S){return S!=null});if(w.length===0){m&&l.push("".concat(d,"="));return}P(d,w);return}var A=g;f._typeof(A)==="object"&&A!==null&&(A=JSON.stringify(A)),l.push("".concat(d,"=").concat(v(A)))}});var p=l.join("&");return n&&p?"?".concat(p):p}function Y(e){var t=e.scene;return t&&(e=f._objectSpread2(f._objectSpread2({fromCode:!0},e),R(t))),e}exports.compareVersion=z;exports.compose=j;exports.composeAsync=O;exports.debounce=I;exports.debouncePromise=U;exports.decodeURIParams=J;exports.encodeURIParams=L;exports.getOnLoadParams=Y;exports.getPascalCase=N;exports.getQueryParams=R;exports.getQueryParamsFromHash=B;exports.getQueryParamsFromSearch=q;exports.getRandom=D;exports.getRandomStr=W;exports.pipe=F;exports.pipeAsync=G;exports.randomColor=V;exports.throttle=H;exports.toQueryString=X;
@@ -22,14 +22,10 @@ export function validDate(str: string): boolean;
22
22
  */
23
23
  export function validPhone(str: string): boolean;
24
24
 
25
- /**
26
- * 校验是否为身份证号(15/18位)
27
- * @param { string } str 身份证号
28
- */
29
- export function validIDCard(str: string): boolean;
30
-
31
25
  /**
32
26
  * 校验是否为邮政编码(6位非零开头)
33
27
  * @param { string } str 邮政编码
34
28
  */
35
29
  export function validPostalCode(str: string): boolean;
30
+
31
+ export * from './personValidator'
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function a(t){return/^(https?:|mailto:|tel:)/.test(t)}function r(t){var e=/^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/;return e.test(t)}function d(t){var e=/^\d{4}-\d{1,2}-\d{1,2}/;return e.test(t)}function n(t){var e=/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;return e.test(t)}function i(t){var e=/^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$|^([1-6][1-9]|50)\d{4}\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}$/;return e.test(t)}function o(t){var e=/[1-9]\d{5}(?!\d)/;return e.test(t)}exports.isExternal=a;exports.validDate=d;exports.validIDCard=i;exports.validPhone=n;exports.validPostalCode=o;exports.validURL=r;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var d=2,g=50,c=["先生","小姐","太太","女士","销售","医生","醫生","护士","護士","老师","老師","经理","經理","客服"],f="(?:[\\u3400-\\u4DBF\\u4E00-\\u9FFF\\uF900-\\uFAD9]|[\\uD840-\\uD87E][\\uDC00-\\uDFFF])",m=new RegExp("^(?:"+f+"|\\u00B7)+$"),A=new RegExp("^"+f+"+(?:\\u00B7"+f+"+)*$"),D=function(e){for(var a=0,r=0;r<e.length;r++)a++,e.charCodeAt(r)>=55296&&e.charCodeAt(r)<=56319&&r++;return a},E=function(e,a){var r=a||{},n=r.min!=null?r.min:d,o=r.max!=null?r.max:g,l=r.forbiddenWords||c;if(!e)return r.emptyMsg||"请输入姓名";var u=D(e);return u<n||u>o?"姓名长度须为"+n+"~"+o+"个字符":m.test(e)?A.test(e)?l.some(function(i){return e.indexOf(i)!==-1})?"姓名不合格,不能含先生/小姐/医生等称谓":"":"间隔点·不能位于首尾或连续出现":"姓名仅支持中文,可含间隔点·"},h=new Set([11,12,13,14,15,21,22,23,31,32,33,34,35,36,37,41,42,43,44,45,46,50,51,52,53,54,61,62,63,64,65,71,81,82,83]),F=[7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2],C="10X98765432";function N(t){var e=String(t).trim().toUpperCase(),a=/^\d{17}[\dX]$/.test(e),r=/^\d{15}$/.test(e);if(!a&&!r)return!1;var n=r?e.slice(0,6)+"19"+e.slice(6):e;if(!h.has(Number(n.slice(0,2))))return!1;var o=+n.slice(6,10),l=+n.slice(10,12),u=+n.slice(12,14),i=new Date(o,l-1,u);if(i.getFullYear()!==o||i.getMonth()!==l-1||i.getDate()!==u||o<1900||i.getTime()>Date.now())return!1;if(a){for(var s=0,v=0;v<17;v++)s+=+n[v]*F[v];if(C[s%11]!==n[17])return!1}return!0}var p=function(e){if(!e||!N(e))return null;var a,r;e.length===18?(a=e.slice(6,14),r=e.charAt(16)):(a="19"+e.slice(6,12),r=e.charAt(14));var n=Number(a.slice(0,4)),o=Number(a.slice(4,6)),l=Number(a.slice(6,8)),u=new Date,i=u.getFullYear()-n;return(u.getMonth()+1<o||u.getMonth()+1===o&&u.getDate()<l)&&i--,{gender:Number(r)%2===1?"1":"2",age:i}};function b(t){return/^(https?:|mailto:|tel:)/.test(t)}function x(t){var e=/^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/;return e.test(t)}function I(t){var e=/^\d{4}-\d{1,2}-\d{1,2}/;return e.test(t)}function M(t){var e=/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;return e.test(t)}function R(t){var e=/[1-9]\d{5}(?!\d)/;return e.test(t)}exports.getIdcardInfo=p;exports.getNameError=E;exports.isExternal=b;exports.validDate=I;exports.validPhone=M;exports.validPostalCode=R;exports.validURL=x;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * 人员信息校验工具
3
+ */
4
+
5
+ /**
6
+ * 中文姓名校验配置项(均可选)
7
+ */
8
+ export interface NameOptions {
9
+ /** 姓名最小长度(按Unicode码点计,间隔点计入),默认 2 */
10
+ min?: number;
11
+ /** 姓名最大长度(按Unicode码点计,间隔点计入),默认 50 */
12
+ max?: number;
13
+ /** 禁用词列表,默认内置称谓词(先生/小姐/医生等) */
14
+ forbiddenWords?: string[];
15
+ /** 姓名为空时的提示文案,默认 '请输入姓名' */
16
+ emptyMsg?: string;
17
+ }
18
+
19
+ /**
20
+ * 校验中文姓名
21
+ *
22
+ * 规则:
23
+ * - 仅允许汉字(含扩展A区/基本区/兼容区/扩展B区及以上)与间隔点·
24
+ * - 汉字开头结尾,间隔点不能连续
25
+ * - 长度按 Unicode 码点计,间隔点计入
26
+ * - 不能包含禁用词
27
+ *
28
+ * @param name 待校验姓名
29
+ * @param options 可选配置
30
+ * @returns 错误提示文案;合法返回 ''
31
+ */
32
+ export declare function getNameError(name: string, options?: NameOptions): string;
33
+
34
+ /**
35
+ * 身份证信息提取结果
36
+ */
37
+ export interface IdcardInfo {
38
+ /** 性别:'1' 男,'2' 女 */
39
+ gender: '1' | '2';
40
+ /** 周岁年龄 */
41
+ age: number;
42
+ }
43
+
44
+ /**
45
+ * 从身份证号(18位或15位)提取性别与周岁年龄
46
+ *
47
+ * 校验规则:省份码、出生日期(含大小月/闰年,不早于1900年且不晚于当前日期)、
48
+ * 18位证校验位;15位老证按19xx年出生年份升位处理。
49
+ *
50
+ * @param idcard 身份证号
51
+ * @returns 性别与周岁年龄;号码不合法返回 null
52
+ */
53
+ export declare function getIdcardInfo(idcard: string): IdcardInfo | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utils-uniapp",
3
- "version": "1.2.15",
3
+ "version": "1.2.17",
4
4
  "description": "aubyn's utils for uniapp",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",