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 CHANGED
@@ -100,6 +100,7 @@ formatBankCard('6228480402564890018', { spaceMark: '-' }); // 6228-4804-0256-489
100
100
  - [calculateCursorPosition](https://doly-dev.github.io/util-helpers/module-Other.html#.calculateCursorPosition) - 计算光标位置
101
101
  - [compressImage](https://doly-dev.github.io/util-helpers/module-Other.html#.compressImage) - 压缩图片
102
102
  - [download](https://doly-dev.github.io/util-helpers/module-Other.html#.download) - 下载
103
+ - [getFileBlob](https://doly-dev.github.io/util-helpers/module-Other.html#.getFileBlob) - 获取文件 Blob
103
104
  - [getImageInfo](https://doly-dev.github.io/util-helpers/module-Other.html#.getImageInfo) - 获取图片信息
104
105
  - [loadImage](https://doly-dev.github.io/util-helpers/module-Other.html#.loadImage) - 加载图片
105
106
  - [loadImageWithBlob](https://doly-dev.github.io/util-helpers/module-Other.html#.loadImageWithBlob) - 加载图片和 blob 对象
@@ -4,15 +4,15 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.utilHelpers = {}));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
- function isArray(value) {
8
- return Array.isArray(value);
9
- }
10
-
11
7
  var objectProto = Object.prototype;
12
- var objectToString = objectProto.toString;
8
+ var objectProtoToString = objectProto.toString;
13
9
  var symbolExisted = typeof Symbol !== 'undefined';
14
10
  var symbolProto = symbolExisted ? Symbol.prototype : undefined;
11
+ var mathMin = Math.min;
15
12
  var numberIsFinite = Number.isFinite;
13
+ var globalThisExisted = typeof globalThis === 'object' && globalThis;
14
+ var globalExisted = typeof global === 'object' && global;
15
+ var selfExisted = typeof self === 'object' && self;
16
16
  var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
17
17
  var MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER || -9007199254740991;
18
18
  var numberTag = '[object Number]';
@@ -20,13 +20,17 @@
20
20
  var symbolTag = '[object Symbol]';
21
21
  var blobTag = '[object Blob]';
22
22
 
23
+ function isArray(value) {
24
+ return Array.isArray(value);
25
+ }
26
+
23
27
  function isObject(value) {
24
28
  var type = typeof value;
25
29
  return value != null && (type === 'object' || type === 'function');
26
30
  }
27
31
 
28
32
  function isSymbol(value) {
29
- return typeof value === 'symbol' || objectToString.call(value) === symbolTag;
33
+ return typeof value === 'symbol' || objectProtoToString.call(value) === symbolTag;
30
34
  }
31
35
 
32
36
  var reIsBinary = /^0b[01]+$/i;
@@ -81,26 +85,26 @@
81
85
  return value == null ? '' : baseToString(value);
82
86
  }
83
87
 
84
- var freeGlobalThis = typeof globalThis === 'object' && globalThis && globalThis.Object === Object && globalThis;
85
- var freeGlobal = typeof global === 'object' && global && global.Object === Object && global;
86
- var freeSelf = typeof self === 'object' && self && self.Object === Object && self;
87
- var root = freeGlobalThis || freeGlobal || freeSelf || Function('return this')() || {};
88
- var root$1 = root;
89
-
90
88
  var blobExisted = typeof Blob !== 'undefined';
91
89
  function isBlob(value) {
92
90
  if (blobExisted && value instanceof Blob) {
93
91
  return true;
94
92
  }
95
- return objectToString.call(value) === blobTag;
93
+ return objectProtoToString.call(value) === blobTag;
96
94
  }
97
95
 
96
+ var freeGlobalThis = globalThisExisted && globalThis.Object === Object && globalThis;
97
+ var freeGlobal = globalExisted && global.Object === Object && global;
98
+ var freeSelf = selfExisted && self.Object === Object && self;
99
+ var root = freeGlobalThis || freeGlobal || freeSelf || Function('return this')();
100
+ var root$1 = root;
101
+
98
102
  function isFinite$1(value) {
99
103
  return numberIsFinite ? numberIsFinite(value) : typeof value === 'number' && root$1.isFinite(value);
100
104
  }
101
105
 
102
106
  function isNumber(value) {
103
- return typeof value === 'number' || objectToString.call(value) === numberTag;
107
+ return typeof value === 'number' || objectProtoToString.call(value) === numberTag;
104
108
  }
105
109
 
106
110
  function isNaN(value) {
@@ -112,14 +116,14 @@
112
116
  }
113
117
 
114
118
  function isString(value) {
115
- return typeof value === 'string' || objectToString.call(value) === stringTag;
119
+ return typeof value === 'string' || objectProtoToString.call(value) === stringTag;
116
120
  }
117
121
 
118
122
  function decimalAdjust(type, value, precision) {
119
123
  if (precision === void 0) { precision = 0; }
120
124
  var func = Math[type];
121
125
  value = toNumber(value);
122
- precision = Math.min(toInteger(precision), 292);
126
+ precision = mathMin(toInteger(precision), 292);
123
127
  if (precision === 0 || !isFinite$1(value)) {
124
128
  return func(value);
125
129
  }
@@ -1292,9 +1296,11 @@
1292
1296
  return divide(product, gcd.apply(void 0, __spreadArray([], __read(args), false)));
1293
1297
  }
1294
1298
 
1299
+ var URLExisted = typeof URL !== 'undefined';
1300
+
1295
1301
  var objectKeys = Object.keys;
1296
- var createObjectURL = typeof URL !== 'undefined' ? URL.createObjectURL : constant('');
1297
- var revokeObjectURL = typeof URL !== 'undefined' ? URL.revokeObjectURL : noop;
1302
+ var createObjectURL = URLExisted ? URL.createObjectURL : constant('');
1303
+ var revokeObjectURL = URLExisted ? URL.revokeObjectURL : noop;
1298
1304
 
1299
1305
  function ajax(url, options) {
1300
1306
  var _a = options || {}, _b = _a.method, method = _b === void 0 ? 'get' : _b, _c = _a.data, data = _c === void 0 ? null : _c, timeout = _a.timeout, headers = _a.headers, _d = _a.withCredentials, withCredentials = _d === void 0 ? false : _d, _e = _a.async, async = _e === void 0 ? true : _e, _f = _a.user, user = _f === void 0 ? null : _f, _g = _a.password, password = _g === void 0 ? null : _g, responseType = _a.responseType, onReadyStateChange = _a.onReadyStateChange, onLoadStart = _a.onLoadStart, onProgress = _a.onProgress, onAbort = _a.onAbort, onTimeout = _a.onTimeout, onError = _a.onError, onLoad = _a.onLoad, onLoadEnd = _a.onLoadEnd;
@@ -1379,31 +1385,32 @@
1379
1385
  }
1380
1386
 
1381
1387
  var SuccessResponseStatus = [200, 304];
1382
- function getBlob(img, ajaxOptions) {
1388
+ function getFileBlob(file, ajaxOptions) {
1383
1389
  return new Promise(function (resolve, reject) {
1384
- if (isBlob(img)) {
1385
- resolve(img);
1390
+ if (isBlob(file)) {
1391
+ resolve(file);
1386
1392
  }
1387
1393
  else {
1388
- ajax(img, __assign({ responseType: 'blob' }, ajaxOptions))
1394
+ ajax(file, __assign({ responseType: 'blob' }, ajaxOptions))
1389
1395
  .then(function (ev) {
1390
1396
  var responseStatus = ev.target.status;
1391
1397
  if (SuccessResponseStatus.indexOf(responseStatus) !== -1) {
1392
1398
  resolve(ev.target.response);
1393
1399
  }
1394
1400
  else {
1395
- var err = new Error("[loadImageWithBlob] The image does not support get requests, responseStatus ".concat(responseStatus, ", '").concat(img, "'."));
1401
+ var err = new Error("The file does not support get requests, responseStatus ".concat(responseStatus, ", '").concat(file, "'."));
1396
1402
  console.error(err);
1397
1403
  reject(err);
1398
1404
  }
1399
1405
  })
1400
1406
  .catch(function (err) {
1401
- console.error(new Error("[loadImageWithBlob] Failed to request image. ".concat(err)));
1407
+ console.error(new Error("Failed to request file. ".concat(err)));
1402
1408
  reject(err);
1403
1409
  });
1404
1410
  }
1405
1411
  });
1406
1412
  }
1413
+
1407
1414
  var cacheImage$2;
1408
1415
  var cacheResult$2;
1409
1416
  function loadImageWithBlob(img, useCache, ajaxOptions) {
@@ -1413,7 +1420,7 @@
1413
1420
  resolve(cacheResult$2);
1414
1421
  }
1415
1422
  else {
1416
- getBlob(img, ajaxOptions)
1423
+ getFileBlob(img, ajaxOptions)
1417
1424
  .then(function (blob) {
1418
1425
  var url = createObjectURL(blob);
1419
1426
  var image = new Image();
@@ -1984,9 +1991,9 @@
1984
1991
  return internalFindTreeSelect(tree, predicate, childrenField);
1985
1992
  }
1986
1993
 
1987
- var VERSION = "4.20.7";
1994
+ var VERSION = "4.21.0";
1988
1995
 
1989
- var version = "4.20.7";
1996
+ var version = "4.21.0";
1990
1997
 
1991
1998
  exports.VERSION = VERSION;
1992
1999
  exports.ajax = ajax;
@@ -2006,6 +2013,7 @@
2006
2013
  exports.formatMobile = formatMobile;
2007
2014
  exports.formatMoney = formatMoney;
2008
2015
  exports.gcd = gcd;
2016
+ exports.getFileBlob = getFileBlob;
2009
2017
  exports.getImageInfo = getImageInfo;
2010
2018
  exports.isBankCard = isBankCard;
2011
2019
  exports.isBusinessLicense = isBusinessLicense;