util-helpers 5.2.1 → 5.3.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 +19 -17
- package/dist/util-helpers.js +101 -73
- 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/checkFileType.js +6 -4
- package/esm/getMimeType.js +2 -2
- package/esm/index.js +4 -3
- package/esm/injectStyle.js +23 -0
- package/esm/loadScript.js +3 -3
- package/esm/utils/file.util.js +6 -3
- package/lib/VERSION.js +1 -1
- package/lib/checkFileType.js +6 -4
- package/lib/getMimeType.js +2 -2
- package/lib/index.js +8 -6
- package/lib/injectStyle.js +25 -0
- package/lib/loadScript.js +3 -3
- package/lib/utils/file.util.js +5 -1
- package/package.json +1 -1
- package/types/VERSION.d.ts +1 -2
- package/types/ajax.d.ts +2 -3
- package/types/bytesToSize.d.ts +0 -1
- package/types/calculateCursorPosition.d.ts +0 -1
- package/types/checkFileType.d.ts +3 -2
- package/types/compressImage.d.ts +1 -1
- package/types/dataURLToBlob.d.ts +1 -2
- package/types/divide.d.ts +0 -1
- package/types/download.d.ts +1 -2
- package/types/fileReader.d.ts +1 -1
- package/types/filterTree.d.ts +0 -1
- package/types/findTreeNode.d.ts +0 -1
- package/types/findTreeNodes.d.ts +0 -1
- package/types/findTreeSelect.d.ts +0 -1
- package/types/formatBankCard.d.ts +0 -1
- package/types/formatMobile.d.ts +0 -1
- package/types/formatMoney.d.ts +0 -1
- package/types/gcd.d.ts +0 -1
- package/types/getExtname.d.ts +0 -0
- package/types/getFileBlob.d.ts +1 -2
- package/types/getFileType.d.ts +1 -3
- package/types/getImageInfo.d.ts +1 -2
- package/types/getMimeType.d.ts +1 -1
- package/types/index.d.ts +13 -10
- package/types/injectStyle.d.ts +16 -0
- package/types/isBankCard.d.ts +0 -1
- package/types/isBusinessLicense.d.ts +0 -1
- package/types/isChinese.d.ts +0 -1
- package/types/isEmail.d.ts +0 -1
- package/types/isHMCard.d.ts +0 -1
- package/types/isIPv4.d.ts +0 -1
- package/types/isIPv6.d.ts +0 -1
- package/types/isIdCard.d.ts +0 -1
- package/types/isMobile.d.ts +0 -1
- package/types/isPassport.d.ts +0 -1
- package/types/isPassword.d.ts +0 -1
- package/types/isPostcode.d.ts +0 -1
- package/types/isQQ.d.ts +0 -1
- package/types/isSocialCreditCode.d.ts +0 -1
- package/types/isSwiftCode.d.ts +0 -1
- package/types/isTWCard.d.ts +0 -1
- package/types/isTelephone.d.ts +0 -1
- package/types/isUrl.d.ts +0 -1
- package/types/isValidNumber.d.ts +0 -1
- package/types/isVehicle.d.ts +0 -1
- package/types/isWX.d.ts +0 -1
- package/types/lcm.d.ts +0 -1
- package/types/listToTree.d.ts +0 -1
- package/types/loadImage.d.ts +1 -2
- package/types/loadImageWithBlob.d.ts +1 -1
- package/types/loadScript.d.ts +1 -2
- package/types/minus.d.ts +0 -1
- package/types/numberToChinese.d.ts +0 -1
- package/types/padZero.d.ts +0 -1
- package/types/parseIdCard.d.ts +0 -1
- package/types/plus.d.ts +0 -1
- package/types/replaceChar.d.ts +0 -1
- package/types/round.d.ts +0 -1
- package/types/setDataURLPrefix.d.ts +0 -1
- package/types/strlen.d.ts +0 -1
- package/types/times.d.ts +0 -1
- package/types/transformFieldNames.d.ts +0 -1
- package/types/transformObjectValue.d.ts +0 -1
- package/types/treeToList.d.ts +0 -1
- package/types/utils/config.d.ts +0 -1
- package/types/utils/file.util.d.ts +4 -0
- package/types/validatePassword.d.ts +0 -1
- package/types/BlobUrl.d.ts +0 -41
package/esm/VERSION.js
CHANGED
package/esm/checkFileType.js
CHANGED
|
@@ -2,7 +2,9 @@ import { isFile, isString, toString } from 'ut2';
|
|
|
2
2
|
import { isUploadFile, testExt } from './utils/file.util.js';
|
|
3
3
|
|
|
4
4
|
function checkFileType(file, accept) {
|
|
5
|
-
|
|
5
|
+
var _a, _b;
|
|
6
|
+
var isFileType = isFile(file);
|
|
7
|
+
if (!isFileType && !isUploadFile(file)) {
|
|
6
8
|
return false;
|
|
7
9
|
}
|
|
8
10
|
if (!isString(accept)) {
|
|
@@ -14,9 +16,9 @@ function checkFileType(file, accept) {
|
|
|
14
16
|
}
|
|
15
17
|
var ret = false;
|
|
16
18
|
var types = accept.toLowerCase().split(/,(?:\s+)?/);
|
|
17
|
-
var fileName = file.name.toLowerCase();
|
|
18
|
-
var fileType = file.type || '';
|
|
19
|
-
var fileUrl = file.url || '';
|
|
19
|
+
var fileName = (file.name || (!isFileType && (file.fileName || ((_a = file.originFileObj) === null || _a === void 0 ? void 0 : _a.name))) || '').toLowerCase();
|
|
20
|
+
var fileType = file.type || (!isFileType && ((_b = file.originFileObj) === null || _b === void 0 ? void 0 : _b.type)) || '';
|
|
21
|
+
var fileUrl = (!isFileType && file.url) || '';
|
|
20
22
|
types.some(function (type) {
|
|
21
23
|
if (type === '*' || fileType === type || (type.indexOf('.') === 0 && (testExt(fileName, type) || testExt(fileUrl, type)))) {
|
|
22
24
|
ret = true;
|
package/esm/getMimeType.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isString, nth } from 'ut2';
|
|
2
1
|
import { nativeUndefined } from './utils/native.js';
|
|
2
|
+
import { getExtname } from './utils/file.util.js';
|
|
3
3
|
|
|
4
4
|
var mimeTypes = [
|
|
5
5
|
['text/plain', ['txt']],
|
|
@@ -36,7 +36,7 @@ var mimeTypes = [
|
|
|
36
36
|
];
|
|
37
37
|
function getMimeType(fileName) {
|
|
38
38
|
var _a;
|
|
39
|
-
var ext =
|
|
39
|
+
var ext = getExtname(fileName).slice(1);
|
|
40
40
|
return ext ? (_a = mimeTypes.find(function (item) { return item[1].includes(ext); })) === null || _a === void 0 ? void 0 : _a[0] : nativeUndefined;
|
|
41
41
|
}
|
|
42
42
|
|
package/esm/index.js
CHANGED
|
@@ -26,8 +26,6 @@ export { default as replaceChar } from './replaceChar.js';
|
|
|
26
26
|
export { default as numberToChinese } from './numberToChinese.js';
|
|
27
27
|
export { default as bytesToSize } from './bytesToSize.js';
|
|
28
28
|
export { default as parseIdCard } from './parseIdCard.js';
|
|
29
|
-
export { default as fileReader } from './fileReader.js';
|
|
30
|
-
export { default as dataURLToBlob } from './dataURLToBlob.js';
|
|
31
29
|
export { default as setDataURLPrefix } from './setDataURLPrefix.js';
|
|
32
30
|
export { default as safeDate } from './safeDate.js';
|
|
33
31
|
export { default as formatMobile } from './formatMobile.js';
|
|
@@ -41,17 +39,20 @@ export { default as round } from './round.js';
|
|
|
41
39
|
export { default as gcd } from './gcd.js';
|
|
42
40
|
export { default as lcm } from './lcm.js';
|
|
43
41
|
export { default as ajax } from './ajax.js';
|
|
44
|
-
export { default as calculateCursorPosition } from './calculateCursorPosition.js';
|
|
45
42
|
export { default as checkFileType } from './checkFileType.js';
|
|
46
43
|
export { default as compressImage } from './compressImage.js';
|
|
44
|
+
export { default as dataURLToBlob } from './dataURLToBlob.js';
|
|
47
45
|
export { default as download } from './download.js';
|
|
46
|
+
export { default as fileReader } from './fileReader.js';
|
|
48
47
|
export { default as getFileBlob } from './getFileBlob.js';
|
|
49
48
|
export { default as getFileType } from './getFileType.js';
|
|
50
49
|
export { default as getImageInfo } from './getImageInfo.js';
|
|
51
50
|
export { default as getMimeType } from './getMimeType.js';
|
|
51
|
+
export { default as injectStyle } from './injectStyle.js';
|
|
52
52
|
export { default as loadImage } from './loadImage.js';
|
|
53
53
|
export { default as loadImageWithBlob } from './loadImageWithBlob.js';
|
|
54
54
|
export { default as loadScript } from './loadScript.js';
|
|
55
|
+
export { default as calculateCursorPosition } from './calculateCursorPosition.js';
|
|
55
56
|
export { default as randomString } from './randomString.js';
|
|
56
57
|
export { default as strlen } from './strlen.js';
|
|
57
58
|
export { default as transformFieldNames } from './transformFieldNames.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
function injectStyle(css, options) {
|
|
2
|
+
var _a = options || {}, _b = _a.container, container = _b === void 0 ? document.head || document.getElementsByTagName('head')[0] || document.body : _b, _c = _a.insertAt, insertAt = _c === void 0 ? 'top' : _c;
|
|
3
|
+
var style = document.createElement('style');
|
|
4
|
+
if (style.styleSheet) {
|
|
5
|
+
style.styleSheet.cssText = css;
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
style.appendChild(document.createTextNode(css));
|
|
9
|
+
}
|
|
10
|
+
var atTop = insertAt === 'top';
|
|
11
|
+
if (atTop && container.prepend) {
|
|
12
|
+
container.prepend(style);
|
|
13
|
+
}
|
|
14
|
+
else if (atTop && container.firstChild) {
|
|
15
|
+
container.insertBefore(style, container.firstChild);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
container.appendChild(style);
|
|
19
|
+
}
|
|
20
|
+
return style;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { injectStyle as default };
|
package/esm/loadScript.js
CHANGED
|
@@ -3,7 +3,7 @@ import { objectKeys } from './utils/native.js';
|
|
|
3
3
|
|
|
4
4
|
function loadScript(src, options) {
|
|
5
5
|
return new Promise(function (resolve, reject) {
|
|
6
|
-
var
|
|
6
|
+
var container = document.head || document.getElementsByTagName('head')[0] || document.body;
|
|
7
7
|
var script = document.createElement('script');
|
|
8
8
|
var _a = options || {}, attrs = _a.attrs, _b = _a.destroyOnError, destroyOnError = _b === void 0 ? true : _b, restOptions = __rest(_a, ["attrs", "destroyOnError"]);
|
|
9
9
|
var props = __assign(__assign({ async: true, type: 'text/javascript' }, restOptions), { src: src });
|
|
@@ -29,11 +29,11 @@ function loadScript(src, options) {
|
|
|
29
29
|
this.onerror = this.onload = null;
|
|
30
30
|
(_a = props.onerror) === null || _a === void 0 ? void 0 : _a.call(this, ev);
|
|
31
31
|
if (destroyOnError) {
|
|
32
|
-
|
|
32
|
+
container.removeChild(script);
|
|
33
33
|
}
|
|
34
34
|
reject(new URIError('Failed to load ' + this.src));
|
|
35
35
|
};
|
|
36
|
-
|
|
36
|
+
container.appendChild(script);
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
|
package/esm/utils/file.util.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isString, nth, isObjectLike } from 'ut2';
|
|
2
2
|
|
|
3
|
+
function getExtname(name) {
|
|
4
|
+
return isString(name) && name.indexOf('.') > 0 ? '.' + nth(name.split('.'), -1) : '';
|
|
5
|
+
}
|
|
3
6
|
function testExt(name, ext) {
|
|
4
|
-
return !!name && name
|
|
7
|
+
return !!name && getExtname(name) === ext;
|
|
5
8
|
}
|
|
6
9
|
function isUploadFile(fileObj) {
|
|
7
10
|
if (isObjectLike(fileObj) && isString(fileObj.name)) {
|
|
@@ -10,4 +13,4 @@ function isUploadFile(fileObj) {
|
|
|
10
13
|
return false;
|
|
11
14
|
}
|
|
12
15
|
|
|
13
|
-
export { isUploadFile, testExt };
|
|
16
|
+
export { getExtname, isUploadFile, testExt };
|
package/lib/VERSION.js
CHANGED
package/lib/checkFileType.js
CHANGED
|
@@ -4,7 +4,9 @@ var ut2 = require('ut2');
|
|
|
4
4
|
var file_util = require('./utils/file.util.js');
|
|
5
5
|
|
|
6
6
|
function checkFileType(file, accept) {
|
|
7
|
-
|
|
7
|
+
var _a, _b;
|
|
8
|
+
var isFileType = ut2.isFile(file);
|
|
9
|
+
if (!isFileType && !file_util.isUploadFile(file)) {
|
|
8
10
|
return false;
|
|
9
11
|
}
|
|
10
12
|
if (!ut2.isString(accept)) {
|
|
@@ -16,9 +18,9 @@ function checkFileType(file, accept) {
|
|
|
16
18
|
}
|
|
17
19
|
var ret = false;
|
|
18
20
|
var types = accept.toLowerCase().split(/,(?:\s+)?/);
|
|
19
|
-
var fileName = file.name.toLowerCase();
|
|
20
|
-
var fileType = file.type || '';
|
|
21
|
-
var fileUrl = file.url || '';
|
|
21
|
+
var fileName = (file.name || (!isFileType && (file.fileName || ((_a = file.originFileObj) === null || _a === void 0 ? void 0 : _a.name))) || '').toLowerCase();
|
|
22
|
+
var fileType = file.type || (!isFileType && ((_b = file.originFileObj) === null || _b === void 0 ? void 0 : _b.type)) || '';
|
|
23
|
+
var fileUrl = (!isFileType && file.url) || '';
|
|
22
24
|
types.some(function (type) {
|
|
23
25
|
if (type === '*' || fileType === type || (type.indexOf('.') === 0 && (file_util.testExt(fileName, type) || file_util.testExt(fileUrl, type)))) {
|
|
24
26
|
ret = true;
|
package/lib/getMimeType.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var ut2 = require('ut2');
|
|
4
3
|
var native = require('./utils/native.js');
|
|
4
|
+
var file_util = require('./utils/file.util.js');
|
|
5
5
|
|
|
6
6
|
var mimeTypes = [
|
|
7
7
|
['text/plain', ['txt']],
|
|
@@ -38,7 +38,7 @@ var mimeTypes = [
|
|
|
38
38
|
];
|
|
39
39
|
function getMimeType(fileName) {
|
|
40
40
|
var _a;
|
|
41
|
-
var ext =
|
|
41
|
+
var ext = file_util.getExtname(fileName).slice(1);
|
|
42
42
|
return ext ? (_a = mimeTypes.find(function (item) { return item[1].includes(ext); })) === null || _a === void 0 ? void 0 : _a[0] : native.nativeUndefined;
|
|
43
43
|
}
|
|
44
44
|
|
package/lib/index.js
CHANGED
|
@@ -28,8 +28,6 @@ var replaceChar = require('./replaceChar.js');
|
|
|
28
28
|
var numberToChinese = require('./numberToChinese.js');
|
|
29
29
|
var bytesToSize = require('./bytesToSize.js');
|
|
30
30
|
var parseIdCard = require('./parseIdCard.js');
|
|
31
|
-
var fileReader = require('./fileReader.js');
|
|
32
|
-
var dataURLToBlob = require('./dataURLToBlob.js');
|
|
33
31
|
var setDataURLPrefix = require('./setDataURLPrefix.js');
|
|
34
32
|
var safeDate = require('./safeDate.js');
|
|
35
33
|
var formatMobile = require('./formatMobile.js');
|
|
@@ -43,17 +41,20 @@ var round = require('./round.js');
|
|
|
43
41
|
var gcd = require('./gcd.js');
|
|
44
42
|
var lcm = require('./lcm.js');
|
|
45
43
|
var ajax = require('./ajax.js');
|
|
46
|
-
var calculateCursorPosition = require('./calculateCursorPosition.js');
|
|
47
44
|
var checkFileType = require('./checkFileType.js');
|
|
48
45
|
var compressImage = require('./compressImage.js');
|
|
46
|
+
var dataURLToBlob = require('./dataURLToBlob.js');
|
|
49
47
|
var download = require('./download.js');
|
|
48
|
+
var fileReader = require('./fileReader.js');
|
|
50
49
|
var getFileBlob = require('./getFileBlob.js');
|
|
51
50
|
var getFileType = require('./getFileType.js');
|
|
52
51
|
var getImageInfo = require('./getImageInfo.js');
|
|
53
52
|
var getMimeType = require('./getMimeType.js');
|
|
53
|
+
var injectStyle = require('./injectStyle.js');
|
|
54
54
|
var loadImage = require('./loadImage.js');
|
|
55
55
|
var loadImageWithBlob = require('./loadImageWithBlob.js');
|
|
56
56
|
var loadScript = require('./loadScript.js');
|
|
57
|
+
var calculateCursorPosition = require('./calculateCursorPosition.js');
|
|
57
58
|
var randomString = require('./randomString.js');
|
|
58
59
|
var strlen = require('./strlen.js');
|
|
59
60
|
var transformFieldNames = require('./transformFieldNames.js');
|
|
@@ -97,8 +98,6 @@ exports.replaceChar = replaceChar;
|
|
|
97
98
|
exports.numberToChinese = numberToChinese;
|
|
98
99
|
exports.bytesToSize = bytesToSize;
|
|
99
100
|
exports.parseIdCard = parseIdCard;
|
|
100
|
-
exports.fileReader = fileReader;
|
|
101
|
-
exports.dataURLToBlob = dataURLToBlob;
|
|
102
101
|
exports.setDataURLPrefix = setDataURLPrefix;
|
|
103
102
|
exports.safeDate = safeDate;
|
|
104
103
|
exports.formatMobile = formatMobile;
|
|
@@ -112,17 +111,20 @@ exports.round = round;
|
|
|
112
111
|
exports.gcd = gcd;
|
|
113
112
|
exports.lcm = lcm;
|
|
114
113
|
exports.ajax = ajax;
|
|
115
|
-
exports.calculateCursorPosition = calculateCursorPosition;
|
|
116
114
|
exports.checkFileType = checkFileType;
|
|
117
115
|
exports.compressImage = compressImage;
|
|
116
|
+
exports.dataURLToBlob = dataURLToBlob;
|
|
118
117
|
exports.download = download;
|
|
118
|
+
exports.fileReader = fileReader;
|
|
119
119
|
exports.getFileBlob = getFileBlob;
|
|
120
120
|
exports.getFileType = getFileType;
|
|
121
121
|
exports.getImageInfo = getImageInfo;
|
|
122
122
|
exports.getMimeType = getMimeType;
|
|
123
|
+
exports.injectStyle = injectStyle;
|
|
123
124
|
exports.loadImage = loadImage;
|
|
124
125
|
exports.loadImageWithBlob = loadImageWithBlob;
|
|
125
126
|
exports.loadScript = loadScript;
|
|
127
|
+
exports.calculateCursorPosition = calculateCursorPosition;
|
|
126
128
|
exports.randomString = randomString;
|
|
127
129
|
exports.strlen = strlen;
|
|
128
130
|
exports.transformFieldNames = transformFieldNames;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function injectStyle(css, options) {
|
|
4
|
+
var _a = options || {}, _b = _a.container, container = _b === void 0 ? document.head || document.getElementsByTagName('head')[0] || document.body : _b, _c = _a.insertAt, insertAt = _c === void 0 ? 'top' : _c;
|
|
5
|
+
var style = document.createElement('style');
|
|
6
|
+
if (style.styleSheet) {
|
|
7
|
+
style.styleSheet.cssText = css;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
style.appendChild(document.createTextNode(css));
|
|
11
|
+
}
|
|
12
|
+
var atTop = insertAt === 'top';
|
|
13
|
+
if (atTop && container.prepend) {
|
|
14
|
+
container.prepend(style);
|
|
15
|
+
}
|
|
16
|
+
else if (atTop && container.firstChild) {
|
|
17
|
+
container.insertBefore(style, container.firstChild);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
container.appendChild(style);
|
|
21
|
+
}
|
|
22
|
+
return style;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = injectStyle;
|
package/lib/loadScript.js
CHANGED
|
@@ -5,7 +5,7 @@ var native = require('./utils/native.js');
|
|
|
5
5
|
|
|
6
6
|
function loadScript(src, options) {
|
|
7
7
|
return new Promise(function (resolve, reject) {
|
|
8
|
-
var
|
|
8
|
+
var container = document.head || document.getElementsByTagName('head')[0] || document.body;
|
|
9
9
|
var script = document.createElement('script');
|
|
10
10
|
var _a = options || {}, attrs = _a.attrs, _b = _a.destroyOnError, destroyOnError = _b === void 0 ? true : _b, restOptions = tslib.__rest(_a, ["attrs", "destroyOnError"]);
|
|
11
11
|
var props = tslib.__assign(tslib.__assign({ async: true, type: 'text/javascript' }, restOptions), { src: src });
|
|
@@ -31,11 +31,11 @@ function loadScript(src, options) {
|
|
|
31
31
|
this.onerror = this.onload = null;
|
|
32
32
|
(_a = props.onerror) === null || _a === void 0 ? void 0 : _a.call(this, ev);
|
|
33
33
|
if (destroyOnError) {
|
|
34
|
-
|
|
34
|
+
container.removeChild(script);
|
|
35
35
|
}
|
|
36
36
|
reject(new URIError('Failed to load ' + this.src));
|
|
37
37
|
};
|
|
38
|
-
|
|
38
|
+
container.appendChild(script);
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
|
package/lib/utils/file.util.js
CHANGED
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
var ut2 = require('ut2');
|
|
4
4
|
|
|
5
|
+
function getExtname(name) {
|
|
6
|
+
return ut2.isString(name) && name.indexOf('.') > 0 ? '.' + ut2.nth(name.split('.'), -1) : '';
|
|
7
|
+
}
|
|
5
8
|
function testExt(name, ext) {
|
|
6
|
-
return !!name && name
|
|
9
|
+
return !!name && getExtname(name) === ext;
|
|
7
10
|
}
|
|
8
11
|
function isUploadFile(fileObj) {
|
|
9
12
|
if (ut2.isObjectLike(fileObj) && ut2.isString(fileObj.name)) {
|
|
@@ -12,5 +15,6 @@ function isUploadFile(fileObj) {
|
|
|
12
15
|
return false;
|
|
13
16
|
}
|
|
14
17
|
|
|
18
|
+
exports.getExtname = getExtname;
|
|
15
19
|
exports.isUploadFile = isUploadFile;
|
|
16
20
|
exports.testExt = testExt;
|
package/package.json
CHANGED
package/types/VERSION.d.ts
CHANGED
package/types/ajax.d.ts
CHANGED
|
@@ -44,12 +44,11 @@ type AjaxOptions = {
|
|
|
44
44
|
*
|
|
45
45
|
* <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
|
|
46
46
|
*
|
|
47
|
-
* @
|
|
48
|
-
* @alias module:Other.ajax
|
|
47
|
+
* @alias module:Browser.ajax
|
|
49
48
|
* @since 4.16.0
|
|
50
49
|
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest | XMLHttpRequest}
|
|
51
50
|
* @param {string} url 地址
|
|
52
|
-
* @param {
|
|
51
|
+
* @param {AjaxOptions} [options] 配置项
|
|
53
52
|
* @param {string} [options.method="get"] 创建请求时使用的方法。默认 `'get'`。
|
|
54
53
|
* @param {boolean} [options.async=true] 是否异步执行操作。默认 `true`。
|
|
55
54
|
* @param {string|null} [options.user=null] 用户名,用于认证用途。默认 `null`。
|
package/types/bytesToSize.d.ts
CHANGED
package/types/checkFileType.d.ts
CHANGED
|
@@ -2,8 +2,9 @@ import { UploadFile } from './utils/file.util';
|
|
|
2
2
|
/**
|
|
3
3
|
* 检查文件是否符合 `accept` 类型说明符。
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* 通过 `file.type` `file.name` `file.url` 与 `accept` 进行匹配。
|
|
6
|
+
*
|
|
7
|
+
* @alias module:Browser.checkFileType
|
|
7
8
|
* @since 5.1.0
|
|
8
9
|
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/input/file#唯一文件类型说明符 | 唯一文件类型说明符}
|
|
9
10
|
* @see {@link https://www.iana.org/assignments/media-types/media-types.xhtml | Media Types}
|
package/types/compressImage.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ interface CompressImage {
|
|
|
35
35
|
* <em style="font-weight: bold;">如果是半透明图片并且导出 `image/png` 格式,建议将背景变成透明 `background=transparent`,避免出现白边。注意正常图片压缩导出 `image/png` 格式后文件可能会比原图大。</em>
|
|
36
36
|
*
|
|
37
37
|
* @function
|
|
38
|
-
* @alias module:
|
|
38
|
+
* @alias module:Browser.compressImage
|
|
39
39
|
* @since 4.20.0
|
|
40
40
|
* @see {@link https://sytpwg.csb.app/ | 在线示例}
|
|
41
41
|
* @param {string | Blob} img 图片地址或 blob 对象
|
package/types/dataURLToBlob.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 将 DataURL 转为 Blob 对象
|
|
3
3
|
*
|
|
4
|
-
* @
|
|
5
|
-
* @alias module:Processor.dataURLToBlob
|
|
4
|
+
* @alias module:Browser.dataURLToBlob
|
|
6
5
|
* @since 4.1.0
|
|
7
6
|
* @see {@link https://developer.mozilla.org/zh-CN/docs/Glossary/Base64 | Base64}
|
|
8
7
|
* @param {string} data data: 协议的URL
|
package/types/divide.d.ts
CHANGED
package/types/download.d.ts
CHANGED
|
@@ -19,8 +19,7 @@ type DownloadOptions = {
|
|
|
19
19
|
*
|
|
20
20
|
* <em>响应头中有 "Content-Disposition" 字段,客户端获取不到?</em> 请参考查阅 [Access-Control-Expose-Headers](https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Expose-Headers) 。
|
|
21
21
|
*
|
|
22
|
-
* @
|
|
23
|
-
* @alias module:Other.download
|
|
22
|
+
* @alias module:Browser.download
|
|
24
23
|
* @since 4.16.0
|
|
25
24
|
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Expose-Headers | Access-Control-Expose-Headers}
|
|
26
25
|
* @see {@link https://zh.wikipedia.org/wiki/多用途互聯網郵件擴展 | MIME}
|
package/types/fileReader.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ interface FileReader {
|
|
|
15
15
|
* <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
|
|
16
16
|
*
|
|
17
17
|
* @function
|
|
18
|
-
* @alias module:
|
|
18
|
+
* @alias module:Browser.fileReader
|
|
19
19
|
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader | FileReader}
|
|
20
20
|
* @since 4.16.0
|
|
21
21
|
* @param {Blob} blob Blob 或 File 对象
|
package/types/filterTree.d.ts
CHANGED
package/types/findTreeNode.d.ts
CHANGED
package/types/findTreeNodes.d.ts
CHANGED
package/types/formatMobile.d.ts
CHANGED
package/types/formatMoney.d.ts
CHANGED
package/types/gcd.d.ts
CHANGED
|
File without changes
|
package/types/getFileBlob.d.ts
CHANGED
|
@@ -2,8 +2,7 @@ import ajax from './ajax';
|
|
|
2
2
|
/**
|
|
3
3
|
* 获取文件 Blob 。
|
|
4
4
|
*
|
|
5
|
-
* @
|
|
6
|
-
* @alias module:Other.getFileBlob
|
|
5
|
+
* @alias module:Browser.getFileBlob
|
|
7
6
|
* @since 4.21.0
|
|
8
7
|
* @param {string | Blob} file 文件地址或对象。
|
|
9
8
|
* @param {AjaxOptions} [ajaxOptions] ajax 请求配置项,当传入的图片为字符串时才会触发请求。
|
package/types/getFileType.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { UploadFile } from './utils/file.util';
|
|
2
2
|
/**
|
|
3
3
|
* @summary 获取文件类型。
|
|
4
|
-
*
|
|
5
|
-
* @static
|
|
6
|
-
* @alias module:Other.getFileType
|
|
4
|
+
* @alias module:Browser.getFileType
|
|
7
5
|
* @since 5.1.0
|
|
8
6
|
* @requires Other.checkFileType
|
|
9
7
|
* @param {File} file 文件对象。支持 antd `UploadFile` 对象。
|
package/types/getImageInfo.d.ts
CHANGED
|
@@ -15,8 +15,7 @@ import loadImageWithBlob from './loadImageWithBlob';
|
|
|
15
15
|
*
|
|
16
16
|
* <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
|
|
17
17
|
*
|
|
18
|
-
* @
|
|
19
|
-
* @alias module:Other.getImageInfo
|
|
18
|
+
* @alias module:Browser.getImageInfo
|
|
20
19
|
* @since 4.20.0
|
|
21
20
|
* @param {string | Blob} img 图片地址或 blob 对象。
|
|
22
21
|
* @param {AjaxOptions} [ajaxOptions] ajax 请求配置项,当传入的图片为字符串时才会触发请求。
|
package/types/getMimeType.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @summary 获取常用的 MIME 类型。通过文件名后缀查找对应的 MIME 类型。
|
|
3
3
|
*
|
|
4
|
-
* @alias module:
|
|
4
|
+
* @alias module:Browser.getMimeType
|
|
5
5
|
* @since 5.2.0
|
|
6
6
|
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/MIME_types | MIME 类型(IANA 媒体类型)}
|
|
7
7
|
* @see {@link https://www.iana.org/assignments/media-types/media-types.xhtml | Media Types}
|
package/types/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* 数据验证
|
|
3
3
|
*
|
|
4
4
|
* @module Validator
|
|
5
|
-
* @since 1.1.0
|
|
6
5
|
*/
|
|
7
6
|
export { default as isMobile } from './isMobile';
|
|
8
7
|
export { default as isTelephone } from './isTelephone';
|
|
@@ -30,7 +29,6 @@ export { default as isValidNumber } from './isValidNumber';
|
|
|
30
29
|
* 数据处理
|
|
31
30
|
*
|
|
32
31
|
* @module Processor
|
|
33
|
-
* @since 1.1.0
|
|
34
32
|
*/
|
|
35
33
|
export { default as formatMoney } from './formatMoney';
|
|
36
34
|
export { default as formatBankCard } from './formatBankCard';
|
|
@@ -38,8 +36,6 @@ export { default as replaceChar } from './replaceChar';
|
|
|
38
36
|
export { default as numberToChinese } from './numberToChinese';
|
|
39
37
|
export { default as bytesToSize } from './bytesToSize';
|
|
40
38
|
export { default as parseIdCard } from './parseIdCard';
|
|
41
|
-
export { default as fileReader } from './fileReader';
|
|
42
|
-
export { default as dataURLToBlob } from './dataURLToBlob';
|
|
43
39
|
export { default as setDataURLPrefix } from './setDataURLPrefix';
|
|
44
40
|
export { default as safeDate } from './safeDate';
|
|
45
41
|
export { default as formatMobile } from './formatMobile';
|
|
@@ -49,7 +45,6 @@ export { default as transformObjectValue } from './transformObjectValue';
|
|
|
49
45
|
* 数学计算,修正浮点数计算问题
|
|
50
46
|
*
|
|
51
47
|
* @module Math
|
|
52
|
-
* @since 3.1.0
|
|
53
48
|
* @see {@link https://github.com/camsong/blog/issues/9 | JavaScript 浮点数陷阱及解法}
|
|
54
49
|
* @see {@link https://2zbuy.csb.app/ | JS浮点数计算测试}
|
|
55
50
|
* @example
|
|
@@ -92,30 +87,38 @@ export { default as round } from './round';
|
|
|
92
87
|
export { default as gcd } from './gcd';
|
|
93
88
|
export { default as lcm } from './lcm';
|
|
94
89
|
/**
|
|
95
|
-
*
|
|
90
|
+
* 浏览器
|
|
96
91
|
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
92
|
+
* <em style="font-weight: bold;">下列方法仅适用于浏览器端。</em>
|
|
93
|
+
*
|
|
94
|
+
* @module Browser
|
|
99
95
|
*/
|
|
100
96
|
export { default as ajax } from './ajax';
|
|
101
|
-
export { default as calculateCursorPosition } from './calculateCursorPosition';
|
|
102
97
|
export { default as checkFileType } from './checkFileType';
|
|
103
98
|
export { default as compressImage } from './compressImage';
|
|
99
|
+
export { default as dataURLToBlob } from './dataURLToBlob';
|
|
104
100
|
export { default as download } from './download';
|
|
101
|
+
export { default as fileReader } from './fileReader';
|
|
105
102
|
export { default as getFileBlob } from './getFileBlob';
|
|
106
103
|
export { default as getFileType } from './getFileType';
|
|
107
104
|
export { default as getImageInfo } from './getImageInfo';
|
|
108
105
|
export { default as getMimeType } from './getMimeType';
|
|
106
|
+
export { default as injectStyle } from './injectStyle';
|
|
109
107
|
export { default as loadImage } from './loadImage';
|
|
110
108
|
export { default as loadImageWithBlob } from './loadImageWithBlob';
|
|
111
109
|
export { default as loadScript } from './loadScript';
|
|
110
|
+
/**
|
|
111
|
+
* 其他
|
|
112
|
+
*
|
|
113
|
+
* @module Other
|
|
114
|
+
*/
|
|
115
|
+
export { default as calculateCursorPosition } from './calculateCursorPosition';
|
|
112
116
|
export { default as randomString } from './randomString';
|
|
113
117
|
export { default as strlen } from './strlen';
|
|
114
118
|
/**
|
|
115
119
|
* 树结构数据查询、过滤、转换等处理方法
|
|
116
120
|
*
|
|
117
121
|
* @module Tree
|
|
118
|
-
* @since 4.14.0
|
|
119
122
|
*/
|
|
120
123
|
export { default as transformFieldNames } from './transformFieldNames';
|
|
121
124
|
export { default as listToTree } from './listToTree';
|