utils-uniapp 1.2.20 → 1.2.22
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.d.ts +6 -13
- package/lib/fs/index.js +1 -1
- package/lib/magic/index.js +1 -1
- package/package.json +1 -1
package/lib/fs/index.d.ts
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
/** 文件编码类型 */
|
|
2
|
-
export type FsEncoding =
|
|
3
|
-
| 'ascii'
|
|
4
|
-
| 'base64'
|
|
5
|
-
| 'binary'
|
|
6
|
-
| 'hex'
|
|
7
|
-
| 'ucs2'
|
|
8
|
-
| 'ucs-2'
|
|
9
|
-
| 'utf16le'
|
|
10
|
-
| 'utf-16le'
|
|
11
|
-
| 'utf-8'
|
|
12
|
-
| 'utf8'
|
|
13
|
-
| 'latin1';
|
|
2
|
+
export type FsEncoding = 'ascii' | 'base64' | 'binary' | 'hex' | 'ucs2' | 'ucs-2' | 'utf16le' | 'utf-16le' | 'utf-8' | 'utf8' | 'latin1';
|
|
14
3
|
|
|
15
4
|
/** uni文件系统管理器(非H5平台) */
|
|
16
5
|
export const $fs: UniApp.FileSystemManager;
|
|
@@ -90,11 +79,15 @@ export interface ArraybufferTempPathOptions {
|
|
|
90
79
|
*/
|
|
91
80
|
export function getArraybufferTempPath(opts: ArraybufferTempPathOptions): Promise<any> | WriteFileResult | null;
|
|
92
81
|
|
|
82
|
+
interface TempFilePaths extends Array<string> {
|
|
83
|
+
/** 原始 tempFiles 数据(来自 uni.chooseMedia 的结果) */
|
|
84
|
+
_source: UniApp.MediaFile[];
|
|
85
|
+
}
|
|
93
86
|
/**
|
|
94
87
|
* 选择图片(优先uni.chooseMedia,降级uni.chooseImage,count默认1)
|
|
95
88
|
* @param { object } opts chooseMedia/chooseImage参数
|
|
96
89
|
*/
|
|
97
|
-
export function chooseImg(opts?: UniApp.ChooseMediaOption): Promise<
|
|
90
|
+
export function chooseImg(opts?: UniApp.ChooseMediaOption): Promise<TempFilePaths>;
|
|
98
91
|
|
|
99
92
|
/**
|
|
100
93
|
* 下载网络图片并保存到相册(非H5平台)
|
package/lib/fs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../_rollupPluginBabelHelpers-3cc6d021.js"),k=require("../http/index.js");require("../object/index.js");require("../magic/index.js");var M=k.createDownloadFile(),l=uni.getFileSystemManager(),F=["ascii","base64","binary","hex","ucs2","ucs-2","utf16le","utf-16le","utf-8","utf8","latin1"];function j(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"png";return"data:image/".concat(e,";base64,")}function v(e){var r=e.filePath,t=e.encoding,a=e.sync,n=e.opts,i=n===void 0?{}:n;if(!F.includes(t))throw"编码不符合";if(a===!0)try{var o=l.readFileSync(r,t,i.position,i.length);return o}catch(s){return console.error(s),null}return new Promise(function(s,m){l.readFile(c._objectSpread2(c._objectSpread2({filePath:r,encoding:t},i),{},{success:function(p){s(p)},fail:m}))})}v.sync=function(e){return v(c._objectSpread2(c._objectSpread2({},e),{},{sync:!0}))};function b(e){var r=e.filePath,t=e.data,a=e.encoding,n=e.sync,i=e.opts;if(a=a||"binary",!F.includes(a))throw"编码不符合";if(n===!0)try{return l.writeFileSync(r,t,a),{tempFilePath:r,unlink:function(){return l.unlinkSync(r)}}}catch(o){return console.error(o),null}return new Promise(function(o,s){l.writeFile(c._objectSpread2(c._objectSpread2({filePath:r,encoding:a,data:t},i),{},{success:function(
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../_rollupPluginBabelHelpers-3cc6d021.js"),k=require("../http/index.js");require("../object/index.js");require("../magic/index.js");var M=k.createDownloadFile(),l=uni.getFileSystemManager(),F=["ascii","base64","binary","hex","ucs2","ucs-2","utf16le","utf-16le","utf-8","utf8","latin1"];function j(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"png";return"data:image/".concat(e,";base64,")}function v(e){var r=e.filePath,t=e.encoding,a=e.sync,n=e.opts,i=n===void 0?{}:n;if(!F.includes(t))throw"编码不符合";if(a===!0)try{var o=l.readFileSync(r,t,i.position,i.length);return o}catch(s){return console.error(s),null}return new Promise(function(s,m){l.readFile(c._objectSpread2(c._objectSpread2({filePath:r,encoding:t},i),{},{success:function(p){s(p)},fail:m}))})}v.sync=function(e){return v(c._objectSpread2(c._objectSpread2({},e),{},{sync:!0}))};function b(e){var r=e.filePath,t=e.data,a=e.encoding,n=e.sync,i=e.opts;if(a=a||"binary",!F.includes(a))throw"编码不符合";if(n===!0)try{return l.writeFileSync(r,t,a),{tempFilePath:r,unlink:function(){return l.unlinkSync(r)}}}catch(o){return console.error(o),null}return new Promise(function(o,s){l.writeFile(c._objectSpread2(c._objectSpread2({filePath:r,encoding:a,data:t},i),{},{success:function(g){if(g.errMsg!=="writeFile:ok")return s(new Error(g.errMsg));o({tempFilePath:r,unlink:function(){return l.unlinkSync(r)}})},fail:s}))})}b.sync=function(e){return b(c._objectSpread2(c._objectSpread2({},e),{},{sync:!0}))};function B(e){var r=e.arraybuffer,t=e.fileType,a=e.method,n=e.canvasId,i=e.width,o=e.height,s=e.ctx,m=e.sync;if(c._typeof(r)!=="object"||r.toString().slice(8,-1)!=="ArrayBuffer")return reject(new Error("ArrayBuffer must be a ArrayBuffer"));if(a=a||"canvas",t=t||"png",a==="fs"){var g=wx.env.USER_DATA_PATH+"/"+Date.now()+"."+t;return b({filePath:g,data:r,sync:m})}if(a==="canvas")return new Promise(function(p,f){if(!["canvas","fs"].includes(a))return f(new Error("method must be canvas | fs"));var T="data:image/".concat(t,";base64,").concat(uni.arrayBufferToBase64(r));if(typeof n!="string")return f(new Error("canvasId must be a string [#id]"));var P=uni.createSelectorQuery();s&&P.in(s),P.select(n).fields({node:!0,size:!0}).exec(function(){var I=c._asyncToGenerator(c._regenerator().m(function S(d){var h,w,y;return c._regenerator().w(function(u){for(;;)switch(u.n){case 0:if(d=d[0],d){u.n=1;break}return u.a(2,f(new Error("No canvas nodes were obtained")));case 1:if(i=i||d.width,o=o||d.height,h=d.node,h){u.n=2;break}return u.a(2,f(new Error("No canvas instances were obtained")));case 2:return w=h.getContext("2d"),y=h.createImage(),u.n=3,new Promise(function(A){y.onload=A,y.src=T}).catch(f);case 3:w.clearRect(0,0,i,o),w.drawImage(y,0,0,i,o),uni.canvasToTempFilePath({canvas:h,width:i,height:o,fileType:t,success:p,fail:f});case 4:return u.a(2)}},S)}));return function(S){return I.apply(this,arguments)}}())})}var E=uni.canIUse("chooseMedia");function _(e){return e=c._objectSpread2({count:1},e),new Promise(function(r,t){E?uni.chooseMedia(c._objectSpread2(c._objectSpread2({mediaType:"image",sizeType:["original","compressed"]},e),{},{success:function(n){if(n.errMsg=="chooseMedia:ok"&&n.tempFiles[0]){var i=n.tempFiles.map(function(o){return o.tempFilePath});i._source=n.tempFiles,r(i)}else t(n.errMsg)},fail:function(n){t(n)}})):uni.chooseImage(c._objectSpread2(c._objectSpread2({},e),{},{success:function(n){r(n.tempFilePaths)},fail:function(n){t(n)}}))})}function q(e){return new Promise(function(r,t){M(e).then(function(a){uni.saveImageToPhotosAlbum({filePath:a.tempFilePath,success:function(i){uni.showToast({icon:"none",title:"保存成功"}),r(i)},fail:function(i){t(i)}})})})}exports.$fs=l;exports.chooseImg=_;exports.getArraybufferTempPath=B;exports.getImgBase64Prefix=j;exports.readFile=v;exports.saveImageToPhotosAlbum=q;exports.writeFile=b;
|
package/lib/magic/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
|
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 I(){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,d,h=arguments;return f._regenerator().w(function(g){for(;;)switch(g.n){case 0:for(y=h.length,P=new Array(y),d=0;d<y;d++)P[d]=h[d];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 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("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 U(){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,d,h=arguments;return f._regenerator().w(function(g){for(;;)switch(g.n){case 0:for(y=h.length,P=new Array(y),d=0;d<y;d++)P[d]=h[d];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(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 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,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 E(){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 d=P.split("&"),h=0;h<d.length;h++){var g=d[h];if(g){var p=g.indexOf("="),w=void 0,A=void 0;p===-1?(w=g,A=""):(w=g.slice(0,p),A=g.slice(p+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 R=m[C];R===void 0?m[C]=M?[b]:b:Array.isArray(R)?R.push(b):m[C]=[R,b]}}}}return m}function q(e){return typeof window=="undefined"?{}:E(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 E(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,p){p.forEach(function(w,A){l.push("".concat(g,"[").concat(A,"]=").concat(v(w)))})},brackets:function(g,p){p.forEach(function(w){l.push("".concat(g,"[]=").concat(v(w)))})},repeat:function(g,p){p.forEach(function(w){l.push("".concat(g,"=").concat(v(w)))})},comma:function(g,p){var w=p.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 p=v(h);if(Array.isArray(g)){var w=g.filter(function(S){return S!=null});if(w.length===0){m&&l.push("".concat(p,"="));return}P(p,w);return}var A=g;f._typeof(A)==="object"&&A!==null&&(A=JSON.stringify(A)),l.push("".concat(p,"=").concat(v(A)))}});var d=l.join("&");return n&&d?"?".concat(d):d}function Y(e){var t=decodeURIComponent(e.scene);return t&&(e=f._objectSpread2(f._objectSpread2({fromCode:!0},e),E(t))),e}exports.compareVersion=z;exports.compose=j;exports.composeAsync=I;exports.debounce=F;exports.debouncePromise=G;exports.decodeURIParams=J;exports.encodeURIParams=L;exports.getOnLoadParams=Y;exports.getPascalCase=N;exports.getQueryParams=E;exports.getQueryParamsFromHash=B;exports.getQueryParamsFromSearch=q;exports.getRandom=D;exports.getRandomStr=W;exports.pipe=O;exports.pipeAsync=U;exports.randomColor=V;exports.throttle=H;exports.toQueryString=X;
|