util-helpers 5.4.1 → 5.5.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.
Files changed (62) hide show
  1. package/README.md +1 -0
  2. package/dist/util-helpers.js +52 -3
  3. package/dist/util-helpers.js.map +1 -1
  4. package/dist/util-helpers.min.js +1 -1
  5. package/dist/util-helpers.min.js.map +1 -1
  6. package/esm/AsyncMemo.js +1 -2
  7. package/esm/VERSION.js +2 -3
  8. package/esm/checkResult.js +27 -0
  9. package/esm/compressImage.js +1 -2
  10. package/esm/fileReader.js +1 -2
  11. package/esm/formatMoney.js +1 -2
  12. package/esm/index.js +1 -0
  13. package/esm/numberToChinese.js +2 -2
  14. package/esm/randomString.js +1 -2
  15. package/esm/safeDate.js +1 -2
  16. package/esm/transformObjectValue.js +1 -2
  17. package/lib/AsyncMemo.js +1 -2
  18. package/lib/VERSION.js +2 -3
  19. package/lib/checkResult.js +29 -0
  20. package/lib/compressImage.js +1 -2
  21. package/lib/fileReader.js +1 -2
  22. package/lib/formatMoney.js +1 -2
  23. package/lib/index.js +2 -0
  24. package/lib/numberToChinese.js +2 -2
  25. package/lib/randomString.js +1 -2
  26. package/lib/safeDate.js +1 -2
  27. package/lib/transformObjectValue.js +1 -2
  28. package/lib/utils/config.js +3 -2
  29. package/lib/utils/native.js +11 -5
  30. package/lib/utils/setup.js +3 -1
  31. package/package.json +5 -11
  32. package/types/AsyncMemo.d.ts +1 -1
  33. package/types/ajax.d.ts +2 -2
  34. package/types/calculateCursorPosition.d.ts +2 -2
  35. package/types/checkFileType.d.ts +2 -2
  36. package/types/checkResult.d.ts +34 -0
  37. package/types/compressImage.d.ts +1 -1
  38. package/types/dataURLToBlob.d.ts +1 -1
  39. package/types/download.d.ts +3 -3
  40. package/types/fileReader.d.ts +1 -1
  41. package/types/gcd.d.ts +1 -1
  42. package/types/getExtname.d.ts +1 -1
  43. package/types/getMimeType.d.ts +2 -2
  44. package/types/index.d.ts +3 -2
  45. package/types/isBankCard.d.ts +1 -1
  46. package/types/isBusinessLicense.d.ts +1 -1
  47. package/types/isChinese.d.ts +3 -3
  48. package/types/isHMCard.d.ts +1 -1
  49. package/types/isIdCard.d.ts +2 -2
  50. package/types/isPassport.d.ts +1 -1
  51. package/types/isPassword.d.ts +1 -1
  52. package/types/isSocialCreditCode.d.ts +1 -1
  53. package/types/isSwiftCode.d.ts +1 -1
  54. package/types/isTWCard.d.ts +1 -1
  55. package/types/isUrl.d.ts +1 -1
  56. package/types/isVehicle.d.ts +1 -1
  57. package/types/lcm.d.ts +1 -1
  58. package/types/numberToChinese.d.ts +1 -1
  59. package/types/parseIdCard.d.ts +1 -1
  60. package/types/safeDate.d.ts +1 -1
  61. package/types/setDataURLPrefix.d.ts +2 -2
  62. package/types/validatePassword.d.ts +1 -1
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
+ - [checkResult](https://doly-dev.github.io/util-helpers/module-Other.html#.checkResult) - 检查函数执行结果
114
115
  - [getExtname](https://doly-dev.github.io/util-helpers/module-Processor.html#.getExtname) - 获取路径扩展名
115
116
  - [randomString](https://doly-dev.github.io/util-helpers/module-Other.html#.randomString) - 随机字符串
116
117
  - [strlen](https://doly-dev.github.io/util-helpers/module-Other.html#.strlen) - 字符长度
@@ -404,6 +404,31 @@
404
404
 
405
405
  function noop() { }
406
406
 
407
+ var tryit = function (fn) {
408
+ return function () {
409
+ var args = [];
410
+ for (var _i = 0; _i < arguments.length; _i++) {
411
+ args[_i] = arguments[_i];
412
+ }
413
+ try {
414
+ var result = fn.apply(void 0, __spreadArray([], __read(args), false));
415
+ if (isPromiseLike(result)) {
416
+ return result
417
+ .then(function (res) {
418
+ return [null, res];
419
+ })
420
+ .catch(function (err) {
421
+ return [err, nativeUndefined$1];
422
+ });
423
+ }
424
+ return [null, result];
425
+ }
426
+ catch (err) {
427
+ return [err, nativeUndefined$1];
428
+ }
429
+ };
430
+ };
431
+
407
432
  var idCounter = 0;
408
433
  '_' + mathRandom().toString(36).substring(2, 4);
409
434
  function uniqueId(prefix) {
@@ -808,6 +833,29 @@
808
833
  return typeof ret === 'number' && !isNaN(ret);
809
834
  }
810
835
 
836
+ var checkResult = function () {
837
+ var args_1 = [];
838
+ for (var _i = 0; _i < arguments.length; _i++) {
839
+ args_1[_i] = arguments[_i];
840
+ }
841
+ return __awaiter(void 0, __spreadArray([], __read(args_1), false), void 0, function (fn) {
842
+ var _a, _b, err, ret;
843
+ if (fn === void 0) { fn = function () { return true; }; }
844
+ var args = [];
845
+ for (_a = 1; _a < arguments.length; _a++) {
846
+ args[_a - 1] = arguments[_a];
847
+ }
848
+ return __generator(this, function (_c) {
849
+ switch (_c.label) {
850
+ case 0: return [4, tryit(fn).apply(void 0, __spreadArray([], __read(args), false))];
851
+ case 1:
852
+ _b = __read.apply(void 0, [_c.sent(), 2]), err = _b[0], ret = _b[1];
853
+ return [2, !err && ret !== false];
854
+ }
855
+ });
856
+ });
857
+ };
858
+
811
859
  var radixReg = /^[-+]?0[b|o|x]\d+/i;
812
860
  var dotNumberStringReg = /^\.\d+/;
813
861
  function transformEffectiveNumber(value) {
@@ -1061,8 +1109,8 @@
1061
1109
  unitChar = chnUnitChar.slice();
1062
1110
  decimal = decimal || '点';
1063
1111
  }
1064
- var unitWan = (unitConfig === null || unitConfig === void 0 ? void 0 : unitConfig.w) || '万';
1065
- var unitYi = (unitConfig === null || unitConfig === void 0 ? void 0 : unitConfig.y) || '亿';
1112
+ var unitWan = unitConfig.w || '万';
1113
+ var unitYi = unitConfig.y || '亿';
1066
1114
  var unitWanYi = unitWan + unitYi;
1067
1115
  unitSection = ['', unitWan, unitYi, unitWanYi];
1068
1116
  if (zero) {
@@ -2152,7 +2200,7 @@
2152
2200
  return internalFindTreeSelect(tree, predicate, childrenField);
2153
2201
  }
2154
2202
 
2155
- var VERSION = "5.4.1";
2203
+ var VERSION = "5.5.0";
2156
2204
 
2157
2205
  /**
2158
2206
  * 事件触发器,支持浏览器端和 node 端。
@@ -3181,6 +3229,7 @@
3181
3229
  exports.bytesToSize = bytesToSize;
3182
3230
  exports.calculateCursorPosition = calculateCursorPosition;
3183
3231
  exports.checkFileType = checkFileType;
3232
+ exports.checkResult = checkResult;
3184
3233
  exports.compressImage = compressImage;
3185
3234
  exports.dataURLToBlob = dataURLToBlob;
3186
3235
  exports.divide = divide;