utils-uniapp 1.0.9 → 1.0.10
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/fs/index.js +1 -1
- package/lib/getLocation/index.js +1 -1
- package/lib/http/index.js +1 -1
- package/lib/index-b81565a7.js +1 -0
- package/lib/index.js +1 -1
- package/lib/magic/index.d.ts +52 -6
- package/lib/magic/index.js +1 -1
- package/package.json +1 -1
- package/lib/index-e3f8a8ef.js +0 -1
package/lib/fs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../index-b81565a7.js"),I=require("../http/index.js");require("../object/index.js");const x=I.createDownloadFile(),u=uni.getFileSystemManager(),P=["ascii","base64","binary","hex","ucs2","ucs-2","utf16le","utf-16le","utf-8","utf8","latin1"];function A(){return`data:image/${arguments.length>0&&arguments[0]!==void 0?arguments[0]:"png"};base64,`}function y(r){let{filePath:n,encoding:t,sync:e,opts:i={}}=r;if(!P.includes(t))throw"编码不符合";if(e===!0)try{return u.readFileSync(n,t,i.position,i.length)}catch(a){return console.error(a),null}return new Promise(function(a,s){u.readFile({filePath:n,encoding:t,...i,success(o){a(o)},fail:s})})}y.sync=function(r){return y({...r,sync:!0})};function g(r){let{filePath:n,data:t,encoding:e,sync:i,opts:a}=r;if(e=e||"binary",!P.includes(e))throw"编码不符合";if(i===!0)try{return u.writeFileSync(n,t,e),{tempFilePath:n,unlink:()=>u.unlinkSync(n)}}catch(s){return console.error(s),null}return new Promise(function(s,o){u.writeFile({filePath:n,encoding:e,data:t,...a,success(f){if(f.errMsg!=="writeFile:ok")return o(new Error(f.errMsg));s({tempFilePath:n,unlink:()=>u.unlinkSync(n)})},fail:o})})}g.sync=function(r){return g({...r,sync:!0})};function M(r){let{arraybuffer:n,fileType:t,method:e,canvasId:i,width:a,height:s,ctx:o,sync:f}=r;if(typeof n!="object"||n.toString().slice(8,-1)!=="ArrayBuffer")return reject(new Error("ArrayBuffer must be a ArrayBuffer"));if(e=e||"canvas",t=t||"png",e==="fs"){const d=wx.env.USER_DATA_PATH+"/"+Date.now()+"."+t;return g({filePath:d,data:n,sync:f})}if(e==="canvas")return new Promise(function(d,l){if(!["canvas","fs"].includes(e))return l(new Error("method must be canvas | fs"));const F=`data:image/${t};base64,${uni.arrayBufferToBase64(n)}`;if(typeof i!="string")return l(new Error("canvasId must be a string [#id]"));const w=uni.createSelectorQuery();o&&w.in(o),w.select(i).fields({node:!0,size:!0}).exec(function(){var b=v._asyncToGenerator(function*(c){if(c=c[0],!c)return l(new Error("No canvas nodes were obtained"));a=a||c.width,s=s||c.height;const m=c.node;if(!m)return l(new Error("No canvas instances were obtained"));const p=m.getContext("2d"),h=m.createImage();yield new Promise(T=>{h.onload=T,h.src=F}).catch(l),p.clearRect(0,0,a,s),p.drawImage(h,0,0,a,s),uni.canvasToTempFilePath({canvas:m,width:a,height:s,fileType:t,success:d,fail:l})});return function(c){return b.apply(this,arguments)}}())})}const S=uni.canIUse("chooseMedia");function B(r){return r={count:1,...r},new Promise((n,t)=>{S?uni.chooseMedia({...r,mediaType:"image",sizeType:["original","compressed"],success(e){if(e.errMsg=="chooseMedia:ok"&&e.tempFiles[0]){const i=e.tempFiles.map(a=>a.tempFilePath);n(i)}else t(e.errMsg)},fail(e){t(e)}}):uni.chooseImage({count:r.count,success(e){n(e.tempFilePaths)},fail(e){t(e)}})})}function E(r){return new Promise((n,t)=>{x(r).then(e=>{uni.saveImageToPhotosAlbum({filePath:e.tempFilePath,success:i=>{uni.showToast({icon:"none",title:"保存成功"}),n(i)},fail:i=>{t(i)}})})})}exports.$fs=u;exports.chooseImg=B;exports.getArraybufferTempPath=M;exports.getImgBase64Prefix=A;exports.readFile=y;exports.saveImageToPhotosAlbum=E;exports.writeFile=g;
|
package/lib/getLocation/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../index-b81565a7.js"),g="/packageOther/pages/errorPage/errorPage",m={altitude:!0,type:"gcj02"},d={check:!1,errorPage:{path:g,message:"定位失败",type:2,enabled:!0}};function a(e,n){try{return e()}catch(o){console.warn(n||"执行失败",o);return}}function w(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!1;const n=k(e);return new Promise((o,r)=>{const{success:l,fail:i,...t}=n.locationParams||{},c={...m,...t,success:o,fail:u=>{N(u,n,r)}};uni.getLocation(c)})}function k(e){return typeof e=="boolean"?{check:e,locationParams:{},errorPage:{...d.errorPage},onLocationFail:null,onNetworkFail:null}:e&&typeof e=="object"&&!Array.isArray(e)?{check:e.check!==!1,locationParams:e.locationParams||{},errorPage:{...d.errorPage,...e.errorPage||{}},onLocationFail:e.onLocationFail||null,onNetworkFail:e.onNetworkFail||null}:{check:d.check,locationParams:{},errorPage:{...d.errorPage},onLocationFail:null,onNetworkFail:null}}function N(e,n,o){a(()=>{var r;return(r=n.onLocationFail)===null||r===void 0?void 0:r.call(n,e)},"onLocationFail 回调执行失败"),n.check&&F(n),o(e)}function F(e){uni.getNetworkType({success:n=>{n.networkType==="none"?f(e,new Error("无网络连接")):P(e.errorPage)},fail:n=>{console.warn("网络检测失败",n),f(e,n),P(e.errorPage)}})}function f(e,n){if(typeof e.onNetworkFail=="function")a(()=>e.onNetworkFail(n),"onNetworkFail 回调执行失败");else{const o=(n==null?void 0:n.errMsg)||(n==null?void 0:n.message)||"网络连接异常";a(()=>{uni.showToast({title:o,icon:"none"})},"显示提示失败")}}function P(e){if((e==null?void 0:e.enabled)===!1)return;const n=v();if(!n){console.warn("无法获取当前页面");return}if(L(n))return;const o=y(n,e);a(()=>{uni.redirectTo({url:o})},"跳转错误页面失败")}function v(){try{const e=getCurrentPages();return e&&e.length>0?e[e.length-1]:null}catch(e){return console.warn("获取当前页面失败",e),null}}function L(e){const n=(e==null?void 0:e.route)||"",o=g.replace("/","");return n===o||n.startsWith(o+"/")}function y(e,n){var o;const{path:r,message:l,type:i}=n||{},t={url:(e==null||(o=e.$page)===null||o===void 0?void 0:o.fullPath)||"",message:l||"定位失败",type:i||2};return`${r||g}${h.toQueryString(t)}`}function E(e){let{latitude:n,longitude:o,name:r="",address:l=""}=e;return new Promise((i,t)=>{const c=Number(n),u=Number(o);if(isNaN(c)||isNaN(u)){const s=new Error("经纬度参数无效");a(()=>{uni.showToast({icon:"none",title:"位置信息不完整"})}),t(s);return}uni.openLocation({latitude:c,longitude:u,name:r||"",address:l||"",success:i,fail:s=>{a(()=>{uni.showToast({icon:"none",title:s.errMsg||"打开地图失败"})}),t(s)}})})}exports.getLocation=w;exports.openLocation=E;
|
package/lib/http/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("../index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("../index-b81565a7.js"),A=require("../object/index.js"),O=Object.freeze({JSON:"application/json;charset=UTF-8",TEXT:"text/plain;charset=UTF-8",FORM_URLENCODED:"application/x-www-form-urlencoded;charset=UTF-8",FORM_DATA:"multipart/form-data"}),m={caches:Object.create(null),add(e,t){this.caches[e]=t},delete(e){Reflect.deleteProperty(this.caches,e)},_cancel(e){const t=this.caches[e];typeof(t==null?void 0:t.abort)=="function"&&t.abort()},cancelAll(){Object.values(this.caches).forEach(e=>{typeof(e==null?void 0:e.abort)=="function"&&e.abort()}),this.caches=Object.create(null)},source(){const e=`${Date.now()}-${C.getRandomStr(16)}`;return{token:e,cancel:()=>this._cancel(e)}}};function b(e,t){return new Promise((r,c)=>{const o=uni[e]({...t,success(n){if(n.statusCode>=200&&n.statusCode<300)return r(n);c({type:"fail",res:n})},fail(n){c({type:"fail",res:n})},complete(){t.cancelToken&&m.delete(t.cancelToken)}});t.cancelToken&&m.add(t.cancelToken,o)})}let R=0,v=!1;function N(e){v||(v=!0,uni.showLoading({title:e,mask:!0}))}function S(){v&&(v=!1,uni.hideLoading())}function j(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"加载中...";R++,R===1&&N(e)}function D(){R>0&&R--,R===0&&S()}function _(e,t){return function(r,c,o,n){return e(r,t,c,o,n)}}function w(e){return typeof e=="function"?e:()=>e||{}}function k(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const c=w(t.headers)(),o=w(r.headers)(),n={...t,...r,headers:{...c,...o}},{headers:a,...s}=n;return{urlRes:e.startsWith("http")?e:n.baseURL?n.baseURL+e:e,headers:a,configRes:s}}function U(e){return typeof e=="function"?[e]:Array.isArray(e)?e.filter(t=>typeof t=="function"):[]}function F(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const c={qs:!0,showError:!0,isCache:!1,cacheKey:`api:${e.url}`,cacheExpire:1e3*60*60*1,loadingText:e.loadingText,loading:!0,reqInterceptor:o=>o,resInterceptor:o=>o,errInterceptor:()=>{},...t,...r};return["reqInterceptor","resInterceptor","errInterceptor"].forEach(o=>{const n=[...U(t[o]),...U(r[o])];c[o]=n.length?C.composeAsync(...n):a=>a}),c}function q(e,t){const r=Array.from(t);return()=>e(...A.cloneDeepWithDescriptors(r))}function E(e,t,r,c,o){return x.apply(this,arguments)}function x(){return x=C._asyncToGenerator(function*(e,t,r,c,o){let n;c.loading&&(j(c.loadingText),n=()=>{D(),n=null});try{var a;const u=yield c.reqInterceptor(r),l=yield e(t,u);return(a=n)===null||a===void 0||a(),yield c.resInterceptor(l,c,o)}catch(u){var s;(s=n)===null||s===void 0||s();const l=yield c.errInterceptor(u);return l!==void 0?l:Promise.reject(u)}}),x.apply(this,arguments)}function L(e,t){function r(c,o,n,a,s){const u=m.source(),l=q(r,arguments),i=F({url:c,loadingText:"加载中..."},t,s),{urlRes:y,headers:T,configRes:g}=k(c,e,a);if(i.isCache){const d=C.getCache(i.cacheKey);if(d)return Promise.resolve(d)}const p=o.toUpperCase()==="GET"?O.JSON:i.qs?O.FORM_URLENCODED:O.JSON,h={cancelToken:u.token,method:o,url:y,data:n,header:{"Content-Type":p,...T},...g};return E(b,"request",h,i,l).then(d=>(i.isCache&&C.setCache(i.cacheKey,d,i.cacheExpire),d))}return r.get=_(r,"get"),r.post=_(r,"post"),r}function P(e,t){return function r(c,o,n,a){const s=m.source(),u=q(r,arguments),l=F({loadingText:"上传中..."},t,a),{urlRes:i,headers:y,configRes:T}=k(c,e,n),{keyName:g="file",filePath:f,...p}={keyName:"file",...o};if(!f||!f.startsWith("http://tmp")&&!f.startsWith("wxfile://tmp"))return Promise.resolve({data:f});const h={cancelToken:s.token,url:i,filePath:f,name:g,formData:p,header:{...y},...T};return E(b,"uploadFile",h,l,u)}}function z(e,t){return function r(c,o,n,a){const s=m.source(),u=q(r,arguments),l=F({loadingText:"下载中..."},t,a),{urlRes:i,headers:y,configRes:T}=k(c,e,n);let g=i;if(o&&typeof o=="object"){const p=Object.entries(o).filter(h=>{let[,d]=h;return d!=null&&d!==""}).map(h=>{let[d,I]=h;return`${encodeURIComponent(d)}=${encodeURIComponent(I)}`}).join("&");p&&(g+=(g.includes("?")?"&":"?")+p)}const f={cancelToken:s.token,url:g,header:{...y},...T};return E(b,"downloadFile",f,l,u)}}exports.CONTENT_TYPES=O;exports.CancelToken=m;exports.createDownloadFile=z;exports.createRequest=L;exports.createUploadFile=P;exports.endLoading=D;exports.promisifyRequest=b;exports.startLoading=j;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function C(n,e,u,t,o,r,a){try{var i=n[r](a),c=i.value}catch(f){return void u(f)}i.done?e(c):Promise.resolve(c).then(t,o)}function h(n){return function(){var e=this,u=arguments;return new Promise(function(t,o){var r=n.apply(e,u);function a(c){C(r,t,o,a,i,"next",c)}function i(c){C(r,t,o,a,i,"throw",c)}a(void 0)})}}function y(){for(var n=arguments.length,e=new Array(n),u=0;u<n;u++)e[u]=arguments[u];if(e.some(t=>typeof t!="function"))throw new TypeError("compose 参数必须是函数");return e.length===0?function(){for(var t=arguments.length,o=new Array(t),r=0;r<t;r++)o[r]=arguments[r];return o.length===1?o[0]:o}:e.reduce((t,o)=>function(){for(var r=this,a=arguments.length,i=new Array(a),c=0;c<a;c++)i[c]=arguments[c];return o.call(this,function(){for(var f=arguments.length,l=new Array(f),s=0;s<f;s++)l[s]=arguments[s];return t.apply(r,l.concat(i))},...i)})}function P(){for(var n=arguments.length,e=new Array(n),u=0;u<n;u++)e[u]=arguments[u];if(e.some(t=>typeof t!="function"))throw new TypeError("composeAsync 参数必须是函数");return e.length===0?h(function*(){for(var t=arguments.length,o=new Array(t),r=0;r<t;r++)o[r]=arguments[r];return o.length===1?o[0]:o}):e.reduce((t,o)=>h(function*(){for(var r=this,a=arguments.length,i=new Array(a),c=0;c<a;c++)i[c]=arguments[c];return o.call(this,h(function*(){for(var f=arguments.length,l=new Array(f),s=0;s<f;s++)l[s]=arguments[s];return t.apply(r,l.concat(i))}),...i)}))}function I(){for(var n=arguments.length,e=new Array(n),u=0;u<n;u++)e[u]=arguments[u];if(e.some(t=>typeof t!="function"))throw new TypeError("pipe 参数必须是函数");return e.length===0?function(){for(var t=arguments.length,o=new Array(t),r=0;r<t;r++)o[r]=arguments[r];return o.length===1?o[0]:o}:e.reduce((t,o)=>function(){for(var r=this,a=arguments.length,i=new Array(a),c=0;c<a;c++)i[c]=arguments[c];return t.call(this,function(){for(var f=arguments.length,l=new Array(f),s=0;s<f;s++)l[s]=arguments[s];return o.apply(r,l.concat(i))},...i)})}function x(){for(var n=arguments.length,e=new Array(n),u=0;u<n;u++)e[u]=arguments[u];if(e.some(t=>typeof t!="function"))throw new TypeError("pipeAsync 参数必须是函数");return e.length===0?h(function*(){for(var t=arguments.length,o=new Array(t),r=0;r<t;r++)o[r]=arguments[r];return o.length===1?o[0]:o}):e.reduce((t,o)=>h(function*(){for(var r=this,a=arguments.length,i=new Array(a),c=0;c<a;c++)i[c]=arguments[c];return t.call(this,h(function*(){for(var f=arguments.length,l=new Array(f),s=0;s<f;s++)l[s]=arguments[s];return o.apply(r,l.concat(i))}),...i)}))}function R(n,e){let u=null;t.stop=()=>u&&clearTimeout(u);function t(){for(var o=arguments.length,r=new Array(o),a=0;a<o;a++)r[a]=arguments[a];t.stop(),u=setTimeout(()=>{n.apply(this,r)},e)}return t}function T(n,e){let u=null,t=[];o.stop=()=>{if(u){var r;(r=t.shift())===null||r===void 0||r("cancel"),clearTimeout(u)}};function o(){for(var r=arguments.length,a=new Array(r),i=0;i<r;i++)a[i]=arguments[i];return new Promise((c,f)=>{o.stop(),t.push(f),u=setTimeout(()=>{c(n.apply(this,a))},e)})}return o}function b(n){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:500,u=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0,t;return u?function(){if(!t){t=!0;for(var o=arguments.length,r=new Array(o),a=0;a<o;a++)r[a]=arguments[a];typeof n=="function"&&n.apply(this,r),setTimeout(()=>{t=!1},e)}}:function(){for(var o=arguments.length,r=new Array(o),a=0;a<o;a++)r[a]=arguments[a];t||(t=!0,setTimeout(()=>{t=!1,typeof n=="function"&&n.apply(this,r)},e))}}function U(n){return encodeURIComponent(JSON.stringify(n||{}))}function Q(n){return JSON.parse(decodeURIComponent(n||"{}"))}function A(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"",e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const{silent:u=!1,decodePlus:t=!0,strict:o=!1}=e,r={};if(typeof n!="string")return r;function a(s,g){let m=s;t&&(m=m.replace(/\+/g," "));try{return decodeURIComponent(m)}catch(d){return u||console.warn(`Failed to decode ${g?"key":"value"}: ${m}`,d),o?null:(g&&(m=m.replace(/%[0-9a-f]{2}/gi,"")),m)}}const i=n.split("#")[0],c=i.indexOf("?"),f=c>=0?i.slice(c+1):i;if(!f)return r;const l=f.split("&");for(let s=0;s<l.length;s++){const g=l[s];if(!g)continue;const m=g.indexOf("=");let d,S;m===-1?(d=g,S=""):(d=g.slice(0,m),S=g.slice(m+1));const p=a(d,!0);if(p===null)continue;const w=a(S,!1);if(w===null||!p)continue;const v=r[p];v===void 0?r[p]=w:Array.isArray(v)?v.push(w):r[p]=[v,w]}return r}function $(n){return typeof window>"u"?{}:A(window.location.search,n)}function M(n){if(typeof window>"u")return{};const e=window.location.hash,u=e.indexOf("?");if(u===-1)return{};const t=e.substring(u);return A(t,n)}function O(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,e=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),n.toString()].join(e)}function j(n){return n.replace(/([^-])([^-]*)/g,function(e,u,t){return u.toLocaleUpperCase()+t.toLocaleLowerCase()}).replace(/-/g,"")}function E(n,e){n=n.split("."),e=e.split(".");const u=Math.max(n.length,e.length);for(;n.length<u;)n.push("0");for(;e.length<u;)e.push("0");for(let t=0;t<u;t++){const o=parseInt(n[t]),r=parseInt(e[t]);if(o>r)return 1;if(o<r)return-1}return 0}function D(){return"#"+Math.floor(Math.random()*16777215).toString(16).padEnd(6,"0")}function F(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:8,e=arguments.length>1?arguments[1]:void 0;n=n||32,e||(e="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678");const u=e.length;let t="";for(let o=0;o<n;o++)t+=e.charAt(Math.floor(Math.random()*u));return t}function q(n){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1;if(!n||typeof n!="object")return"";const u=[];Object.keys(n).forEach(o=>{const r=n[o];if(r==null)return;const a=encodeURIComponent(o);if(Array.isArray(r)){r.forEach(c=>{const f=encodeURIComponent(c);u.push(`${a}=${f}`)});return}let i=r;typeof i=="object"&&i!==null&&(i=JSON.stringify(i)),u.push(`${a}=${encodeURIComponent(i)}`)});const t=u.join("&");return e&&t?`?${t}`:t}function L(n){const e=n.scene;return e&&(n={fromCode:!0,...n,...A(e)}),n}function V(n,e){let u=arguments.length>2&&arguments[2]!==void 0?arguments[2]:36e5;try{return uni.setStorageSync(n,{time:Date.now(),expire:u,data:e}),!0}catch(t){return console.error(`设置缓存[${n}]失败:`,t),!1}}function G(n){try{const e=uni.getStorageSync(n);return!e||typeof e!="object"||Array.isArray(e)||!("time"in e)||!("expire"in e)?(e&&uni.removeStorageSync(n),null):Date.now()-e.time>=e.expire?(uni.removeStorageSync(n),null):e.data}catch(e){return console.error(`获取缓存[${n}]失败:`,e),null}}function H(n){try{const e=uni.getStorageSync(n);return!e||typeof e!="object"||Array.isArray(e)||!("time"in e)||!("expire"in e)?!1:Date.now()-e.time>=e.expire?(uni.removeStorageSync(n),!1):(e.time=Date.now(),uni.setStorageSync(n,e),!0)}catch(e){return console.error(`续期缓存[${n}]失败:`,e),!1}}function J(n){try{return uni.removeStorageSync(n),!0}catch(e){return console.error(`删除缓存[${n}]失败:`,e),!1}}exports._asyncToGenerator=h;exports.compareVersion=E;exports.compose=y;exports.composeAsync=P;exports.debounce=R;exports.debouncePromise=T;exports.decodeURIParams=Q;exports.encodeURIParams=U;exports.getCache=G;exports.getOnLoadParams=L;exports.getPascalCase=j;exports.getQueryParams=A;exports.getQueryParamsFromHash=M;exports.getQueryParamsFromSearch=$;exports.getRandom=O;exports.getRandomStr=F;exports.pipe=I;exports.pipeAsync=x;exports.randomColor=D;exports.removeCache=J;exports.renewCache=H;exports.setCache=V;exports.throttle=b;exports.toQueryString=q;
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./array/index.js"),n=require("./date/index.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./array/index.js"),n=require("./date/index.js"),t=require("./fs/index.js"),s=require("./getLocation/index.js"),r=require("./http/index.js"),e=require("./index-b81565a7.js"),i=require("./object/index.js"),o=require("./validate/index.js"),c=require("./index-9456b3d9.js"),d=require("./lodash");Object.assign(exports,d);exports.exchangeArrP=a.exchangeArrP;exports.filterTree=a.filterTree;exports.findTreeItem=a.findTreeItem;exports.flatWithKey=a.flatWithKey;exports.getTreePath=a.getTreePath;exports.groupBy=a.groupBy;exports.reverseForEach=a.reverseForEach;exports.treeItemSetParent=a.treeItemSetParent;exports.dateFormat=n.dateFormat;exports.getDate=n.getDate;exports.$fs=t.$fs;exports.chooseImg=t.chooseImg;exports.getArraybufferTempPath=t.getArraybufferTempPath;exports.getImgBase64Prefix=t.getImgBase64Prefix;exports.readFile=t.readFile;exports.saveImageToPhotosAlbum=t.saveImageToPhotosAlbum;exports.writeFile=t.writeFile;exports.getLocation=s.getLocation;exports.openLocation=s.openLocation;exports.CONTENT_TYPES=r.CONTENT_TYPES;exports.CancelToken=r.CancelToken;exports.createDownloadFile=r.createDownloadFile;exports.createRequest=r.createRequest;exports.createUploadFile=r.createUploadFile;exports.endLoading=r.endLoading;exports.promisifyRequest=r.promisifyRequest;exports.startLoading=r.startLoading;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.getCache=e.getCache;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.removeCache=e.removeCache;exports.renewCache=e.renewCache;exports.setCache=e.setCache;exports.throttle=e.throttle;exports.toQueryString=e.toQueryString;exports.cloneDeepWithDescriptors=i.cloneDeepWithDescriptors;exports.getRawType=i.getRawType;exports.hasOwnProperty=i.hasOwnProperty;exports.isExternal=o.isExternal;exports.validDate=o.validDate;exports.validIDCard=o.validIDCard;exports.validPhone=o.validPhone;exports.validPostalCode=o.validPostalCode;exports.validURL=o.validURL;exports.wx=c.index;
|
package/lib/magic/index.d.ts
CHANGED
|
@@ -84,11 +84,51 @@ export function decodeURIParams<T = any>(params?: string): T;
|
|
|
84
84
|
/** 路径参数对象化结果,同名key聚合为数组 */
|
|
85
85
|
export type SearchParams = Record<string, string | string[]>;
|
|
86
86
|
|
|
87
|
+
export interface GetQueryParamsOptions {
|
|
88
|
+
/** 是否静默模式,不输出警告 */
|
|
89
|
+
silent?: boolean;
|
|
90
|
+
/** 是否将 + 号解码为空格 */
|
|
91
|
+
decodePlus?: boolean;
|
|
92
|
+
/** 严格模式,解码失败时跳过该参数 */
|
|
93
|
+
strict?: boolean;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 解析 URL query 字符串,相同 key 自动转为数组
|
|
98
|
+
* 支持传入完整 URL / query 字符串,自动剔除 hash
|
|
99
|
+
*
|
|
100
|
+
* @param str 完整 url / query 字符串,可以带开头 ?,可携带 #hash
|
|
101
|
+
* @param options 配置选项
|
|
102
|
+
* @returns 解析结果
|
|
103
|
+
*/
|
|
104
|
+
export declare function getQueryParams(
|
|
105
|
+
str?: string,
|
|
106
|
+
options?: GetQueryParamsOptions
|
|
107
|
+
): Record<string, string | string[]>;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* 从当前页面 URL 的 search 部分解析参数(仅浏览器环境)
|
|
111
|
+
* @param options 同 getQueryParams 的 options
|
|
112
|
+
* @returns 解析结果
|
|
113
|
+
*/
|
|
114
|
+
export declare function getQueryParamsFromSearch(
|
|
115
|
+
options?: GetQueryParamsOptions
|
|
116
|
+
): Record<string, string | string[]>;
|
|
117
|
+
|
|
87
118
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
119
|
+
* 从当前页面 URL 的 hash 部分解析参数(仅浏览器环境)
|
|
120
|
+
* 自动提取 hash 中 ? 后的 query 参数
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* // URL: https://example.com#/pages/index?a=1&b=2
|
|
124
|
+
* getQueryParamsFromHash() // => { a: '1', b: '2' }
|
|
125
|
+
*
|
|
126
|
+
* @param options 同 getQueryParams 的 options
|
|
127
|
+
* @returns 解析结果
|
|
90
128
|
*/
|
|
91
|
-
export function
|
|
129
|
+
export declare function getQueryParamsFromHash(
|
|
130
|
+
options?: GetQueryParamsOptions
|
|
131
|
+
): Record<string, string | string[]>;
|
|
92
132
|
|
|
93
133
|
/**
|
|
94
134
|
* 生成随机标识串(时间戳与随机数拼接)
|
|
@@ -123,10 +163,16 @@ export function randomColor(): string;
|
|
|
123
163
|
export function getRandomStr(len?: number, $chars?: string): string;
|
|
124
164
|
|
|
125
165
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
166
|
+
* 对象转url query字符串
|
|
167
|
+
* 数组自动展开为重复key,与 getQueryParams 解析行为双向对称
|
|
168
|
+
* @param params 参数对象
|
|
169
|
+
* @param addQuestionMark 是否添加开头问号 ?
|
|
170
|
+
* @returns query串
|
|
128
171
|
*/
|
|
129
|
-
export function
|
|
172
|
+
export declare function toQueryString(
|
|
173
|
+
params: Record<string, any>,
|
|
174
|
+
addQuestionMark?: boolean
|
|
175
|
+
): string;
|
|
130
176
|
|
|
131
177
|
/**
|
|
132
178
|
* 获取页面onLoad参数(自动解析小程序扫码scene)
|
package/lib/magic/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../index-b81565a7.js");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.getCache=e.getCache;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.removeCache=e.removeCache;exports.renewCache=e.renewCache;exports.setCache=e.setCache;exports.throttle=e.throttle;exports.toQueryString=e.toQueryString;
|
package/package.json
CHANGED
package/lib/index-e3f8a8ef.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";function l(r,t,a,n,o,e,u){try{var c=r[e](u),i=c.value}catch(m){return void a(m)}c.done?t(i):Promise.resolve(i).then(n,o)}function g(r){return function(){var t=this,a=arguments;return new Promise(function(n,o){var e=r.apply(t,a);function u(i){l(e,n,o,u,c,"next",i)}function c(i){l(e,n,o,u,c,"throw",i)}u(void 0)})}}function p(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];if(t.some(n=>typeof n!="function"))throw new TypeError("compose 参数必须是函数");return t.length===0?function(){for(var n=arguments.length,o=new Array(n),e=0;e<n;e++)o[e]=arguments[e];return o.length===1?o[0]:o}:t.reduce((n,o)=>function(){for(var e=this,u=arguments.length,c=new Array(u),i=0;i<u;i++)c[i]=arguments[i];return o.call(this,function(){for(var m=arguments.length,f=new Array(m),s=0;s<m;s++)f[s]=arguments[s];return n.apply(e,f.concat(c))},...c)})}function d(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];if(t.some(n=>typeof n!="function"))throw new TypeError("composeAsync 参数必须是函数");return t.length===0?g(function*(){for(var n=arguments.length,o=new Array(n),e=0;e<n;e++)o[e]=arguments[e];return o.length===1?o[0]:o}):t.reduce((n,o)=>g(function*(){for(var e=this,u=arguments.length,c=new Array(u),i=0;i<u;i++)c[i]=arguments[i];return o.call(this,g(function*(){for(var m=arguments.length,f=new Array(m),s=0;s<m;s++)f[s]=arguments[s];return n.apply(e,f.concat(c))}),...c)}))}function w(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];if(t.some(n=>typeof n!="function"))throw new TypeError("pipe 参数必须是函数");return t.length===0?function(){for(var n=arguments.length,o=new Array(n),e=0;e<n;e++)o[e]=arguments[e];return o.length===1?o[0]:o}:t.reduce((n,o)=>function(){for(var e=this,u=arguments.length,c=new Array(u),i=0;i<u;i++)c[i]=arguments[i];return n.call(this,function(){for(var m=arguments.length,f=new Array(m),s=0;s<m;s++)f[s]=arguments[s];return o.apply(e,f.concat(c))},...c)})}function S(){for(var r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];if(t.some(n=>typeof n!="function"))throw new TypeError("pipeAsync 参数必须是函数");return t.length===0?g(function*(){for(var n=arguments.length,o=new Array(n),e=0;e<n;e++)o[e]=arguments[e];return o.length===1?o[0]:o}):t.reduce((n,o)=>g(function*(){for(var e=this,u=arguments.length,c=new Array(u),i=0;i<u;i++)c[i]=arguments[i];return n.call(this,g(function*(){for(var m=arguments.length,f=new Array(m),s=0;s<m;s++)f[s]=arguments[s];return o.apply(e,f.concat(c))}),...c)}))}function v(r,t){let a=null;n.stop=()=>a&&clearTimeout(a);function n(){for(var o=arguments.length,e=new Array(o),u=0;u<o;u++)e[u]=arguments[u];n.stop(),a=setTimeout(()=>{r.apply(this,e)},t)}return n}function A(r,t){let a=null,n=[];o.stop=()=>{if(a){var e;(e=n.shift())===null||e===void 0||e("cancel"),clearTimeout(a)}};function o(){for(var e=arguments.length,u=new Array(e),c=0;c<e;c++)u[c]=arguments[c];return new Promise((i,m)=>{o.stop(),n.push(m),a=setTimeout(()=>{i(r.apply(this,u))},t)})}return o}function C(r){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:500,a=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0,n;return a?function(){if(!n){n=!0;for(var o=arguments.length,e=new Array(o),u=0;u<o;u++)e[u]=arguments[u];typeof r=="function"&&r.apply(this,e),setTimeout(()=>{n=!1},t)}}:function(){for(var o=arguments.length,e=new Array(o),u=0;u<o;u++)e[u]=arguments[u];n||(n=!0,setTimeout(()=>{n=!1,typeof r=="function"&&r.apply(this,e)},t))}}function P(r){return encodeURIComponent(JSON.stringify(r||{}))}function I(r){return JSON.parse(decodeURIComponent(r||"{}"))}function h(r){const t={};return decodeURIComponent(r).replace(/([^?^&]*?)=([^?^&]*)/g,(a,n,o)=>{const e=t[n];if(!e)return t[n]=o;if(e&&typeof e=="string")return t[n]=[e,o];t[n].push(o)}),t}function T(){let r=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),r.toString()].join(t)}function R(r){return r.replace(/([^-])([^-]*)/g,function(t,a,n){return a.toLocaleUpperCase()+n.toLocaleLowerCase()}).replace(/-/g,"")}function x(r,t){r=r.split("."),t=t.split(".");const a=Math.max(r.length,t.length);for(;r.length<a;)r.push("0");for(;t.length<a;)t.push("0");for(let n=0;n<a;n++){const o=parseInt(r[n]),e=parseInt(t[n]);if(o>e)return 1;if(o<e)return-1}return 0}function b(){return"#"+Math.floor(Math.random()*16777215).toString(16).padEnd(6,"0")}function M(){let r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:8,t=arguments.length>1?arguments[1]:void 0;r=r||32,t||(t="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678");const a=t.length;let n="";for(let o=0;o<r;o++)n+=t.charAt(Math.floor(Math.random()*a));return n}function U(r){return Object.keys(r).map(t=>{const a=r[t];return`${t}=${a&&typeof a=="object"?JSON.stringify(a):a}`}).join("&")}function j(r){const t=r.scene;return t&&(r={fromCode:!0,...r,...h(t)}),r}function D(r,t){let a=arguments.length>2&&arguments[2]!==void 0?arguments[2]:36e5;try{return uni.setStorageSync(r,{time:Date.now(),expire:a,data:t}),!0}catch(n){return console.error(`设置缓存[${r}]失败:`,n),!1}}function E(r){try{const t=uni.getStorageSync(r);return!t||typeof t!="object"||Array.isArray(t)||!("time"in t)||!("expire"in t)?(t&&uni.removeStorageSync(r),null):Date.now()-t.time>=t.expire?(uni.removeStorageSync(r),null):t.data}catch(t){return console.error(`获取缓存[${r}]失败:`,t),null}}function O(r){try{const t=uni.getStorageSync(r);return!t||typeof t!="object"||Array.isArray(t)||!("time"in t)||!("expire"in t)?!1:Date.now()-t.time>=t.expire?(uni.removeStorageSync(r),!1):(t.time=Date.now(),uni.setStorageSync(r,t),!0)}catch(t){return console.error(`续期缓存[${r}]失败:`,t),!1}}function L(r){try{return uni.removeStorageSync(r),!0}catch(t){return console.error(`删除缓存[${r}]失败:`,t),!1}}exports._asyncToGenerator=g;exports.compareVersion=x;exports.compose=p;exports.composeAsync=d;exports.debounce=v;exports.debouncePromise=A;exports.decodeURIParams=I;exports.encodeURIParams=P;exports.getCache=E;exports.getOnLoadParams=j;exports.getPascalCase=R;exports.getRandom=T;exports.getRandomStr=M;exports.getSearchParams=h;exports.getSearchStr=U;exports.pipe=w;exports.pipeAsync=S;exports.randomColor=b;exports.removeCache=L;exports.renewCache=O;exports.setCache=D;exports.throttle=C;
|