util-helpers 5.1.0 → 5.1.2
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/dist/util-helpers.js +25 -9
- 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 -7
- package/esm/formatMoney.js +4 -5
- package/esm/getFileType.js +2 -1
- package/esm/utils/file.util.js +13 -0
- package/lib/VERSION.js +1 -1
- package/lib/checkFileType.js +5 -6
- package/lib/formatMoney.js +3 -4
- package/lib/getFileType.js +2 -1
- package/lib/utils/file.util.js +16 -0
- package/package.json +2 -2
- package/types/checkFileType.d.ts +23 -2
- package/types/formatMoney.d.ts +2 -0
- package/types/getFileType.d.ts +12 -2
- package/types/utils/file.util.d.ts +8 -0
package/dist/util-helpers.js
CHANGED
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
var symbolTag = '[object Symbol]';
|
|
35
35
|
var functionTags = ['Function', 'AsyncFunction', 'GeneratorFunction', 'Proxy'].map(function (item) { return '[object ' + item + ']'; });
|
|
36
36
|
var blobTag = '[object Blob]';
|
|
37
|
+
var fileTag = '[object File]';
|
|
37
38
|
var objectTag = '[object Object]';
|
|
38
39
|
|
|
39
40
|
function isArray(value) {
|
|
@@ -215,6 +216,14 @@
|
|
|
215
216
|
return typeof Ctor === 'function' && Ctor instanceof Ctor && functionProtoToString.call(Ctor) === objectCtorString;
|
|
216
217
|
}
|
|
217
218
|
|
|
219
|
+
var fileExisted = typeof File !== stringUndefined;
|
|
220
|
+
function isFile(value) {
|
|
221
|
+
if (fileExisted && value instanceof File) {
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
return getTag(value) === fileTag;
|
|
225
|
+
}
|
|
226
|
+
|
|
218
227
|
var freeGlobalThis = globalThisExisted && globalThis.Object === Object && globalThis;
|
|
219
228
|
var freeGlobal = globalExisted && global.Object === Object && global;
|
|
220
229
|
var freeSelf = selfExisted && self.Object === Object && self;
|
|
@@ -893,10 +902,9 @@
|
|
|
893
902
|
return decimal + ret;
|
|
894
903
|
}
|
|
895
904
|
var formatMoney = function (num, options) {
|
|
896
|
-
if (num === void 0) { num = ''; }
|
|
897
905
|
if (options === void 0) { options = {}; }
|
|
898
|
-
var _a = options.precision, precision = _a === void 0 ? 2 : _a, symbol = options.symbol, _b = options.thousand, thousand = _b === void 0 ? ',' : _b, _c = options.decimal, decimal = _c === void 0 ? '.' : _c;
|
|
899
|
-
if (!checkNumber(num)) {
|
|
906
|
+
var _a = options.precision, precision = _a === void 0 ? 2 : _a, symbol = options.symbol, _b = options.thousand, thousand = _b === void 0 ? ',' : _b, _c = options.decimal, decimal = _c === void 0 ? '.' : _c, _d = options.strict, strict = _d === void 0 ? true : _d;
|
|
907
|
+
if (!checkNumber(num) || (strict && (!isString(num) || num === '') && !isNumber(num))) {
|
|
900
908
|
return '';
|
|
901
909
|
}
|
|
902
910
|
if (typeof num === 'number' && !isFinite(num)) {
|
|
@@ -912,7 +920,7 @@
|
|
|
912
920
|
thousand = typeof thousand === 'string' ? thousand : ',';
|
|
913
921
|
decimal = typeof decimal === 'string' ? decimal : '.';
|
|
914
922
|
var strNum = transformEffectiveNumber(num) + '';
|
|
915
|
-
var
|
|
923
|
+
var _e = __read(strNum.split('.'), 2), intStr = _e[0], decStr = _e[1];
|
|
916
924
|
return symbol + formatInt(intStr, thousand) + formatDec(decStr, precision, decimal);
|
|
917
925
|
};
|
|
918
926
|
|
|
@@ -1471,8 +1479,15 @@
|
|
|
1471
1479
|
function testExt(name, ext) {
|
|
1472
1480
|
return !!name && name.slice(-ext.length) === ext;
|
|
1473
1481
|
}
|
|
1482
|
+
function isUploadFile(fileObj) {
|
|
1483
|
+
if (isObjectLike(fileObj) && isString(fileObj.uid) && isString(fileObj.name)) {
|
|
1484
|
+
return true;
|
|
1485
|
+
}
|
|
1486
|
+
return false;
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1474
1489
|
function checkFileType(file, accept) {
|
|
1475
|
-
if (!
|
|
1490
|
+
if (!isFile(file) && !isUploadFile(file)) {
|
|
1476
1491
|
return false;
|
|
1477
1492
|
}
|
|
1478
1493
|
if (!isString(accept)) {
|
|
@@ -1485,9 +1500,10 @@
|
|
|
1485
1500
|
var ret = false;
|
|
1486
1501
|
var types = accept.toLowerCase().split(/,(?:\s+)?/);
|
|
1487
1502
|
var fileName = file.name.toLowerCase();
|
|
1488
|
-
var fileType = file.type;
|
|
1503
|
+
var fileType = file.type || '';
|
|
1504
|
+
var fileUrl = file.url || '';
|
|
1489
1505
|
types.some(function (type) {
|
|
1490
|
-
if (fileType === type || (type.indexOf('.') === 0 && testExt(fileName, type))) {
|
|
1506
|
+
if (type === '*' || fileType === type || (type.indexOf('.') === 0 && (testExt(fileName, type) || testExt(fileUrl, type)))) {
|
|
1491
1507
|
ret = true;
|
|
1492
1508
|
}
|
|
1493
1509
|
else if (type.includes('/*') && fileType.includes('/')) {
|
|
@@ -1717,7 +1733,7 @@
|
|
|
1717
1733
|
};
|
|
1718
1734
|
function getFileType(file) {
|
|
1719
1735
|
var type;
|
|
1720
|
-
if (isBlob(file)) {
|
|
1736
|
+
if (isBlob(file) || isUploadFile(file)) {
|
|
1721
1737
|
forEach(config, function (accept, fileType) {
|
|
1722
1738
|
if (checkFileType(file, accept)) {
|
|
1723
1739
|
type = fileType;
|
|
@@ -2060,7 +2076,7 @@
|
|
|
2060
2076
|
return internalFindTreeSelect(tree, predicate, childrenField);
|
|
2061
2077
|
}
|
|
2062
2078
|
|
|
2063
|
-
var VERSION = "5.1.
|
|
2079
|
+
var VERSION = "5.1.2";
|
|
2064
2080
|
|
|
2065
2081
|
var EmitterPro = /** @class */ (function () {
|
|
2066
2082
|
function EmitterPro() {
|