util-helpers 4.20.7 → 4.21.0
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/README.md +1 -0
- package/dist/util-helpers.js +35 -27
- package/dist/util-helpers.js.map +1 -1
- package/dist/util-helpers.min.js +1 -1
- package/dist/util-helpers.min.js.map +1 -1
- package/esm/VERSION.js +1 -1
- package/esm/getFileBlob.js +32 -0
- package/esm/index.js +2 -1
- package/esm/loadImageWithBlob.js +2 -30
- package/esm/utils/native.js +3 -2
- package/esm/utils/setup.js +3 -0
- package/lib/VERSION.js +1 -1
- package/lib/getFileBlob.js +34 -0
- package/lib/index.js +3 -1
- package/lib/loadImageWithBlob.js +2 -30
- package/lib/utils/native.js +3 -2
- package/lib/utils/setup.js +3 -0
- package/package.json +2 -2
- package/types/getFileBlob.d.ts +22 -0
- package/types/index.d.ts +1 -0
- package/types/loadImageWithBlob.d.ts +2 -2
- package/types/utils/setup.d.ts +1 -0
package/esm/VERSION.js
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { __assign } from 'tslib';
|
|
2
|
+
import { isBlob } from 'ut2';
|
|
3
|
+
import ajax from './ajax.js';
|
|
4
|
+
|
|
5
|
+
var SuccessResponseStatus = [200, 304];
|
|
6
|
+
function getFileBlob(file, ajaxOptions) {
|
|
7
|
+
return new Promise(function (resolve, reject) {
|
|
8
|
+
if (isBlob(file)) {
|
|
9
|
+
resolve(file);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
ajax(file, __assign({ responseType: 'blob' }, ajaxOptions))
|
|
13
|
+
.then(function (ev) {
|
|
14
|
+
var responseStatus = ev.target.status;
|
|
15
|
+
if (SuccessResponseStatus.indexOf(responseStatus) !== -1) {
|
|
16
|
+
resolve(ev.target.response);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
var err = new Error("The file does not support get requests, responseStatus ".concat(responseStatus, ", '").concat(file, "'."));
|
|
20
|
+
console.error(err);
|
|
21
|
+
reject(err);
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
.catch(function (err) {
|
|
25
|
+
console.error(new Error("Failed to request file. ".concat(err)));
|
|
26
|
+
reject(err);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { getFileBlob as default };
|
package/esm/index.js
CHANGED
|
@@ -46,6 +46,7 @@ export { default as ajax } from './ajax.js';
|
|
|
46
46
|
export { default as calculateCursorPosition } from './calculateCursorPosition.js';
|
|
47
47
|
export { default as compressImage } from './compressImage.js';
|
|
48
48
|
export { default as download } from './download.js';
|
|
49
|
+
export { default as getFileBlob } from './getFileBlob.js';
|
|
49
50
|
export { default as getImageInfo } from './getImageInfo.js';
|
|
50
51
|
export { default as loadImage } from './loadImage.js';
|
|
51
52
|
export { default as loadImageWithBlob } from './loadImageWithBlob.js';
|
|
@@ -63,6 +64,6 @@ export { default as findTreeSelect } from './findTreeSelect.js';
|
|
|
63
64
|
export { setDisableWarning } from './utils/config.js';
|
|
64
65
|
export { default as VERSION } from './VERSION.js';
|
|
65
66
|
|
|
66
|
-
var version = "4.
|
|
67
|
+
var version = "4.21.0";
|
|
67
68
|
|
|
68
69
|
export { version };
|
package/esm/loadImageWithBlob.js
CHANGED
|
@@ -1,34 +1,6 @@
|
|
|
1
|
-
import { __assign } from 'tslib';
|
|
2
|
-
import { isBlob } from 'ut2';
|
|
3
|
-
import ajax from './ajax.js';
|
|
4
1
|
import { createObjectURL, revokeObjectURL } from './utils/native.js';
|
|
2
|
+
import getFileBlob from './getFileBlob.js';
|
|
5
3
|
|
|
6
|
-
var SuccessResponseStatus = [200, 304];
|
|
7
|
-
function getBlob(img, ajaxOptions) {
|
|
8
|
-
return new Promise(function (resolve, reject) {
|
|
9
|
-
if (isBlob(img)) {
|
|
10
|
-
resolve(img);
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
ajax(img, __assign({ responseType: 'blob' }, ajaxOptions))
|
|
14
|
-
.then(function (ev) {
|
|
15
|
-
var responseStatus = ev.target.status;
|
|
16
|
-
if (SuccessResponseStatus.indexOf(responseStatus) !== -1) {
|
|
17
|
-
resolve(ev.target.response);
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
var err = new Error("[loadImageWithBlob] The image does not support get requests, responseStatus ".concat(responseStatus, ", '").concat(img, "'."));
|
|
21
|
-
console.error(err);
|
|
22
|
-
reject(err);
|
|
23
|
-
}
|
|
24
|
-
})
|
|
25
|
-
.catch(function (err) {
|
|
26
|
-
console.error(new Error("[loadImageWithBlob] Failed to request image. ".concat(err)));
|
|
27
|
-
reject(err);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
4
|
var cacheImage;
|
|
33
5
|
var cacheResult;
|
|
34
6
|
function loadImageWithBlob(img, useCache, ajaxOptions) {
|
|
@@ -38,7 +10,7 @@ function loadImageWithBlob(img, useCache, ajaxOptions) {
|
|
|
38
10
|
resolve(cacheResult);
|
|
39
11
|
}
|
|
40
12
|
else {
|
|
41
|
-
|
|
13
|
+
getFileBlob(img, ajaxOptions)
|
|
42
14
|
.then(function (blob) {
|
|
43
15
|
var url = createObjectURL(blob);
|
|
44
16
|
var image = new Image();
|
package/esm/utils/native.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { constant, noop } from 'ut2';
|
|
2
|
+
import { URLExisted } from './setup.js';
|
|
2
3
|
|
|
3
4
|
var objectKeys = Object.keys;
|
|
4
|
-
var createObjectURL =
|
|
5
|
-
var revokeObjectURL =
|
|
5
|
+
var createObjectURL = URLExisted ? URL.createObjectURL : constant('');
|
|
6
|
+
var revokeObjectURL = URLExisted ? URL.revokeObjectURL : noop;
|
|
6
7
|
|
|
7
8
|
export { createObjectURL, objectKeys, revokeObjectURL };
|
package/lib/VERSION.js
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tslib = require('tslib');
|
|
4
|
+
var ut2 = require('ut2');
|
|
5
|
+
var ajax = require('./ajax.js');
|
|
6
|
+
|
|
7
|
+
var SuccessResponseStatus = [200, 304];
|
|
8
|
+
function getFileBlob(file, ajaxOptions) {
|
|
9
|
+
return new Promise(function (resolve, reject) {
|
|
10
|
+
if (ut2.isBlob(file)) {
|
|
11
|
+
resolve(file);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
ajax(file, tslib.__assign({ responseType: 'blob' }, ajaxOptions))
|
|
15
|
+
.then(function (ev) {
|
|
16
|
+
var responseStatus = ev.target.status;
|
|
17
|
+
if (SuccessResponseStatus.indexOf(responseStatus) !== -1) {
|
|
18
|
+
resolve(ev.target.response);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
var err = new Error("The file does not support get requests, responseStatus ".concat(responseStatus, ", '").concat(file, "'."));
|
|
22
|
+
console.error(err);
|
|
23
|
+
reject(err);
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
.catch(function (err) {
|
|
27
|
+
console.error(new Error("Failed to request file. ".concat(err)));
|
|
28
|
+
reject(err);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = getFileBlob;
|
package/lib/index.js
CHANGED
|
@@ -48,6 +48,7 @@ var ajax = require('./ajax.js');
|
|
|
48
48
|
var calculateCursorPosition = require('./calculateCursorPosition.js');
|
|
49
49
|
var compressImage = require('./compressImage.js');
|
|
50
50
|
var download = require('./download.js');
|
|
51
|
+
var getFileBlob = require('./getFileBlob.js');
|
|
51
52
|
var getImageInfo = require('./getImageInfo.js');
|
|
52
53
|
var loadImage = require('./loadImage.js');
|
|
53
54
|
var loadImageWithBlob = require('./loadImageWithBlob.js');
|
|
@@ -65,7 +66,7 @@ var findTreeSelect = require('./findTreeSelect.js');
|
|
|
65
66
|
var config = require('./utils/config.js');
|
|
66
67
|
var VERSION = require('./VERSION.js');
|
|
67
68
|
|
|
68
|
-
exports.version = "4.
|
|
69
|
+
exports.version = "4.21.0";
|
|
69
70
|
|
|
70
71
|
exports.isMobile = isMobile;
|
|
71
72
|
exports.isTelephone = isTelephone;
|
|
@@ -115,6 +116,7 @@ exports.ajax = ajax;
|
|
|
115
116
|
exports.calculateCursorPosition = calculateCursorPosition;
|
|
116
117
|
exports.compressImage = compressImage;
|
|
117
118
|
exports.download = download;
|
|
119
|
+
exports.getFileBlob = getFileBlob;
|
|
118
120
|
exports.getImageInfo = getImageInfo;
|
|
119
121
|
exports.loadImage = loadImage;
|
|
120
122
|
exports.loadImageWithBlob = loadImageWithBlob;
|
package/lib/loadImageWithBlob.js
CHANGED
|
@@ -1,36 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var tslib = require('tslib');
|
|
4
|
-
var ut2 = require('ut2');
|
|
5
|
-
var ajax = require('./ajax.js');
|
|
6
3
|
var native = require('./utils/native.js');
|
|
4
|
+
var getFileBlob = require('./getFileBlob.js');
|
|
7
5
|
|
|
8
|
-
var SuccessResponseStatus = [200, 304];
|
|
9
|
-
function getBlob(img, ajaxOptions) {
|
|
10
|
-
return new Promise(function (resolve, reject) {
|
|
11
|
-
if (ut2.isBlob(img)) {
|
|
12
|
-
resolve(img);
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
ajax(img, tslib.__assign({ responseType: 'blob' }, ajaxOptions))
|
|
16
|
-
.then(function (ev) {
|
|
17
|
-
var responseStatus = ev.target.status;
|
|
18
|
-
if (SuccessResponseStatus.indexOf(responseStatus) !== -1) {
|
|
19
|
-
resolve(ev.target.response);
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
var err = new Error("[loadImageWithBlob] The image does not support get requests, responseStatus ".concat(responseStatus, ", '").concat(img, "'."));
|
|
23
|
-
console.error(err);
|
|
24
|
-
reject(err);
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
.catch(function (err) {
|
|
28
|
-
console.error(new Error("[loadImageWithBlob] Failed to request image. ".concat(err)));
|
|
29
|
-
reject(err);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
6
|
var cacheImage;
|
|
35
7
|
var cacheResult;
|
|
36
8
|
function loadImageWithBlob(img, useCache, ajaxOptions) {
|
|
@@ -40,7 +12,7 @@ function loadImageWithBlob(img, useCache, ajaxOptions) {
|
|
|
40
12
|
resolve(cacheResult);
|
|
41
13
|
}
|
|
42
14
|
else {
|
|
43
|
-
|
|
15
|
+
getFileBlob(img, ajaxOptions)
|
|
44
16
|
.then(function (blob) {
|
|
45
17
|
var url = native.createObjectURL(blob);
|
|
46
18
|
var image = new Image();
|
package/lib/utils/native.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var ut2 = require('ut2');
|
|
4
|
+
var setup = require('./setup.js');
|
|
4
5
|
|
|
5
6
|
exports.objectKeys = Object.keys;
|
|
6
|
-
exports.createObjectURL =
|
|
7
|
-
exports.revokeObjectURL =
|
|
7
|
+
exports.createObjectURL = setup.URLExisted ? URL.createObjectURL : ut2.constant('');
|
|
8
|
+
exports.revokeObjectURL = setup.URLExisted ? URL.revokeObjectURL : ut2.noop;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "util-helpers",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.21.0",
|
|
4
4
|
"description": "一个基于业务场景的工具方法库",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -91,6 +91,6 @@
|
|
|
91
91
|
},
|
|
92
92
|
"dependencies": {
|
|
93
93
|
"tslib": "^2.6.2",
|
|
94
|
-
"ut2": "^1.
|
|
94
|
+
"ut2": "^1.5.2"
|
|
95
95
|
}
|
|
96
96
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import ajax from './ajax';
|
|
2
|
+
/**
|
|
3
|
+
* 获取文件 Blob 。
|
|
4
|
+
*
|
|
5
|
+
* @static
|
|
6
|
+
* @alias module:Other.getFileBlob
|
|
7
|
+
* @since 4.21.0
|
|
8
|
+
* @param {string | Blob} file 文件地址或对象。
|
|
9
|
+
* @param {AjaxOptions} [ajaxOptions] ajax 请求配置项,当传入的图片为字符串时才会触发请求。
|
|
10
|
+
* @returns {Promise<Blob>} 文件 Blob 。
|
|
11
|
+
* @example
|
|
12
|
+
*
|
|
13
|
+
* getFileBlob(file).then((blob)=>{
|
|
14
|
+
* // do something
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* getFileBlob('https://dummyimage.com/200x300').then((blob)=>{
|
|
18
|
+
* // do something
|
|
19
|
+
* });
|
|
20
|
+
*/
|
|
21
|
+
declare function getFileBlob(file: string | Blob, ajaxOptions?: Parameters<typeof ajax>[1]): Promise<Blob>;
|
|
22
|
+
export default getFileBlob;
|
package/types/index.d.ts
CHANGED
|
@@ -103,6 +103,7 @@ export { default as ajax } from './ajax';
|
|
|
103
103
|
export { default as calculateCursorPosition } from './calculateCursorPosition';
|
|
104
104
|
export { default as compressImage } from './compressImage';
|
|
105
105
|
export { default as download } from './download';
|
|
106
|
+
export { default as getFileBlob } from './getFileBlob';
|
|
106
107
|
export { default as getImageInfo } from './getImageInfo';
|
|
107
108
|
export { default as loadImage } from './loadImage';
|
|
108
109
|
export { default as loadImageWithBlob } from './loadImageWithBlob';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import getFileBlob from './getFileBlob';
|
|
2
2
|
/**
|
|
3
3
|
* @typedef {Object} ImageWithBlob HTML图片元素和 blob 对象
|
|
4
4
|
* @property {HTMLImageElement} image HTML图片元素
|
|
@@ -31,7 +31,7 @@ import ajax from './ajax';
|
|
|
31
31
|
* });
|
|
32
32
|
*
|
|
33
33
|
*/
|
|
34
|
-
declare function loadImageWithBlob(img: string | Blob, useCache?: boolean, ajaxOptions?: Parameters<typeof
|
|
34
|
+
declare function loadImageWithBlob(img: string | Blob, useCache?: boolean, ajaxOptions?: Parameters<typeof getFileBlob>[1]): Promise<{
|
|
35
35
|
image: HTMLImageElement;
|
|
36
36
|
blob: Blob;
|
|
37
37
|
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const URLExisted: boolean;
|