util-helpers 5.3.0 → 5.4.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
@@ -111,6 +111,7 @@ formatBankCard('6228480402564890018', { spaceMark: '-' }); // 6228-4804-0256-489
111
111
  - [validatePassword](https://doly-dev.github.io/util-helpers/module-Validator.html#.validatePassword) - 验证密码
112
112
  - 其他
113
113
  - [calculateCursorPosition](https://doly-dev.github.io/util-helpers/module-Other.html#.calculateCursorPosition) - 计算光标位置
114
+ - [getExtname](https://doly-dev.github.io/util-helpers/module-Processor.html#.getExtname) - 获取路径扩展名
114
115
  - [randomString](https://doly-dev.github.io/util-helpers/module-Other.html#.randomString) - 随机字符串
115
116
  - [strlen](https://doly-dev.github.io/util-helpers/module-Other.html#.strlen) - 字符长度
116
117
  - Classes
@@ -272,6 +272,130 @@
272
272
  return decimalAdjust('round', number, precision);
273
273
  }
274
274
 
275
+ /******************************************************************************
276
+ Copyright (c) Microsoft Corporation.
277
+
278
+ Permission to use, copy, modify, and/or distribute this software for any
279
+ purpose with or without fee is hereby granted.
280
+
281
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
282
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
283
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
284
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
285
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
286
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
287
+ PERFORMANCE OF THIS SOFTWARE.
288
+ ***************************************************************************** */
289
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
290
+
291
+ var extendStatics = function(d, b) {
292
+ extendStatics = Object.setPrototypeOf ||
293
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
294
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
295
+ return extendStatics(d, b);
296
+ };
297
+
298
+ function __extends(d, b) {
299
+ if (typeof b !== "function" && b !== null)
300
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
301
+ extendStatics(d, b);
302
+ function __() { this.constructor = d; }
303
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
304
+ }
305
+
306
+ var __assign = function() {
307
+ __assign = Object.assign || function __assign(t) {
308
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
309
+ s = arguments[i];
310
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
311
+ }
312
+ return t;
313
+ };
314
+ return __assign.apply(this, arguments);
315
+ };
316
+
317
+ function __rest(s, e) {
318
+ var t = {};
319
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
320
+ t[p] = s[p];
321
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
322
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
323
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
324
+ t[p[i]] = s[p[i]];
325
+ }
326
+ return t;
327
+ }
328
+
329
+ function __awaiter(thisArg, _arguments, P, generator) {
330
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
331
+ return new (P || (P = Promise))(function (resolve, reject) {
332
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
333
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
334
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
335
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
336
+ });
337
+ }
338
+
339
+ function __generator(thisArg, body) {
340
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
341
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
342
+ function verb(n) { return function (v) { return step([n, v]); }; }
343
+ function step(op) {
344
+ if (f) throw new TypeError("Generator is already executing.");
345
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
346
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
347
+ if (y = 0, t) op = [op[0] & 2, t.value];
348
+ switch (op[0]) {
349
+ case 0: case 1: t = op; break;
350
+ case 4: _.label++; return { value: op[1], done: false };
351
+ case 5: _.label++; y = op[1]; op = [0]; continue;
352
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
353
+ default:
354
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
355
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
356
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
357
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
358
+ if (t[2]) _.ops.pop();
359
+ _.trys.pop(); continue;
360
+ }
361
+ op = body.call(thisArg, _);
362
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
363
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
364
+ }
365
+ }
366
+
367
+ function __read(o, n) {
368
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
369
+ if (!m) return o;
370
+ var i = m.call(o), r, ar = [], e;
371
+ try {
372
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
373
+ }
374
+ catch (error) { e = { error: error }; }
375
+ finally {
376
+ try {
377
+ if (r && !r.done && (m = i["return"])) m.call(i);
378
+ }
379
+ finally { if (e) throw e.error; }
380
+ }
381
+ return ar;
382
+ }
383
+
384
+ function __spreadArray(to, from, pack) {
385
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
386
+ if (ar || !(i in from)) {
387
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
388
+ ar[i] = from[i];
389
+ }
390
+ }
391
+ return to.concat(ar || Array.prototype.slice.call(from));
392
+ }
393
+
394
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
395
+ var e = new Error(message);
396
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
397
+ };
398
+
275
399
  function constant(value) {
276
400
  return function () {
277
401
  return value;
@@ -684,130 +808,6 @@
684
808
  return typeof ret === 'number' && !isNaN(ret);
685
809
  }
686
810
 
687
- /******************************************************************************
688
- Copyright (c) Microsoft Corporation.
689
-
690
- Permission to use, copy, modify, and/or distribute this software for any
691
- purpose with or without fee is hereby granted.
692
-
693
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
694
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
695
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
696
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
697
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
698
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
699
- PERFORMANCE OF THIS SOFTWARE.
700
- ***************************************************************************** */
701
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
702
-
703
- var extendStatics = function(d, b) {
704
- extendStatics = Object.setPrototypeOf ||
705
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
706
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
707
- return extendStatics(d, b);
708
- };
709
-
710
- function __extends(d, b) {
711
- if (typeof b !== "function" && b !== null)
712
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
713
- extendStatics(d, b);
714
- function __() { this.constructor = d; }
715
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
716
- }
717
-
718
- var __assign = function() {
719
- __assign = Object.assign || function __assign(t) {
720
- for (var s, i = 1, n = arguments.length; i < n; i++) {
721
- s = arguments[i];
722
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
723
- }
724
- return t;
725
- };
726
- return __assign.apply(this, arguments);
727
- };
728
-
729
- function __rest(s, e) {
730
- var t = {};
731
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
732
- t[p] = s[p];
733
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
734
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
735
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
736
- t[p[i]] = s[p[i]];
737
- }
738
- return t;
739
- }
740
-
741
- function __awaiter(thisArg, _arguments, P, generator) {
742
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
743
- return new (P || (P = Promise))(function (resolve, reject) {
744
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
745
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
746
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
747
- step((generator = generator.apply(thisArg, _arguments || [])).next());
748
- });
749
- }
750
-
751
- function __generator(thisArg, body) {
752
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
753
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
754
- function verb(n) { return function (v) { return step([n, v]); }; }
755
- function step(op) {
756
- if (f) throw new TypeError("Generator is already executing.");
757
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
758
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
759
- if (y = 0, t) op = [op[0] & 2, t.value];
760
- switch (op[0]) {
761
- case 0: case 1: t = op; break;
762
- case 4: _.label++; return { value: op[1], done: false };
763
- case 5: _.label++; y = op[1]; op = [0]; continue;
764
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
765
- default:
766
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
767
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
768
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
769
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
770
- if (t[2]) _.ops.pop();
771
- _.trys.pop(); continue;
772
- }
773
- op = body.call(thisArg, _);
774
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
775
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
776
- }
777
- }
778
-
779
- function __read(o, n) {
780
- var m = typeof Symbol === "function" && o[Symbol.iterator];
781
- if (!m) return o;
782
- var i = m.call(o), r, ar = [], e;
783
- try {
784
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
785
- }
786
- catch (error) { e = { error: error }; }
787
- finally {
788
- try {
789
- if (r && !r.done && (m = i["return"])) m.call(i);
790
- }
791
- finally { if (e) throw e.error; }
792
- }
793
- return ar;
794
- }
795
-
796
- function __spreadArray(to, from, pack) {
797
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
798
- if (ar || !(i in from)) {
799
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
800
- ar[i] = from[i];
801
- }
802
- }
803
- return to.concat(ar || Array.prototype.slice.call(from));
804
- }
805
-
806
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
807
- var e = new Error(message);
808
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
809
- };
810
-
811
811
  var radixReg = /^[-+]?0[b|o|x]\d+/i;
812
812
  var dotNumberStringReg = /^\.\d+/;
813
813
  function transformEffectiveNumber(value) {
@@ -1421,12 +1421,6 @@
1421
1421
  });
1422
1422
  }
1423
1423
 
1424
- function getExtname(name) {
1425
- return isString(name) && name.indexOf('.') > 0 ? '.' + nth(name.split('.'), -1) : '';
1426
- }
1427
- function testExt(name, ext) {
1428
- return !!name && getExtname(name) === ext;
1429
- }
1430
1424
  function isUploadFile(fileObj) {
1431
1425
  if (isObjectLike(fileObj) && isString(fileObj.name)) {
1432
1426
  return true;
@@ -1434,6 +1428,10 @@
1434
1428
  return false;
1435
1429
  }
1436
1430
 
1431
+ function getExtname(path) {
1432
+ return isString(path) && path.indexOf('.') > 0 ? '.' + nth(path.split('.'), -1) : '';
1433
+ }
1434
+
1437
1435
  function checkFileType(file, accept) {
1438
1436
  var _a, _b;
1439
1437
  var isFileType = isFile(file);
@@ -1453,7 +1451,7 @@
1453
1451
  var fileType = file.type || (!isFileType && ((_b = file.originFileObj) === null || _b === void 0 ? void 0 : _b.type)) || '';
1454
1452
  var fileUrl = (!isFileType && file.url) || '';
1455
1453
  types.some(function (type) {
1456
- if (type === '*' || fileType === type || (type.indexOf('.') === 0 && (testExt(fileName, type) || testExt(fileUrl, type)))) {
1454
+ if (type === '*' || fileType === type || (type.indexOf('.') === 0 && (getExtname(fileName) === type || getExtname(fileUrl) === type))) {
1457
1455
  ret = true;
1458
1456
  }
1459
1457
  else if (type.includes('/*') && fileType.includes('/')) {
@@ -1789,7 +1787,7 @@
1789
1787
  }
1790
1788
 
1791
1789
  function injectStyle(css, options) {
1792
- 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;
1790
+ 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, onBefore = _a.onBefore;
1793
1791
  var style = document.createElement('style');
1794
1792
  if (style.styleSheet) {
1795
1793
  style.styleSheet.cssText = css;
@@ -1797,6 +1795,9 @@
1797
1795
  else {
1798
1796
  style.appendChild(document.createTextNode(css));
1799
1797
  }
1798
+ if (typeof onBefore === 'function') {
1799
+ onBefore(style);
1800
+ }
1800
1801
  var atTop = insertAt === 'top';
1801
1802
  if (atTop && container.prepend) {
1802
1803
  container.prepend(style);
@@ -2151,7 +2152,7 @@
2151
2152
  return internalFindTreeSelect(tree, predicate, childrenField);
2152
2153
  }
2153
2154
 
2154
- var VERSION = "5.3.0";
2155
+ var VERSION = "5.4.0";
2155
2156
 
2156
2157
  /**
2157
2158
  * 事件触发器,支持浏览器端和 node 端。
@@ -3193,6 +3194,7 @@
3193
3194
  exports.formatMobile = formatMobile;
3194
3195
  exports.formatMoney = formatMoney;
3195
3196
  exports.gcd = gcd;
3197
+ exports.getExtname = getExtname;
3196
3198
  exports.getFileBlob = getFileBlob;
3197
3199
  exports.getFileType = getFileType;
3198
3200
  exports.getImageInfo = getImageInfo;