util-helpers 4.21.4 → 4.21.5

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
@@ -44,20 +44,32 @@ formatBankCard('6228480402564890018', { spaceMark: '-' }); // 6228-4804-0256-489
44
44
  > 数学计算,修正了浮点数计算问题,适用于金额计算。参考:[JS 浮点数计算测试](https://2zbuy.csb.app/)
45
45
 
46
46
  - 数学计算
47
- - [plus](https://doly-dev.github.io/util-helpers/module-Math.html#.plus) - 加
48
- - [minus](https://doly-dev.github.io/util-helpers/module-Math.html#.minus) - 减
49
- - [times](https://doly-dev.github.io/util-helpers/module-Math.html#.times) - 乘
50
47
  - [divide](https://doly-dev.github.io/util-helpers/module-Math.html#.divide) - 除
51
- - [round](https://doly-dev.github.io/util-helpers/module-Math.html#.round) - 四舍五入
52
48
  - [gcd](https://doly-dev.github.io/util-helpers/module-Math.html#.gcd) - 最大公约数
53
49
  - [lcm](https://doly-dev.github.io/util-helpers/module-Math.html#.lcm) - 最小公倍数
50
+ - [minus](https://doly-dev.github.io/util-helpers/module-Math.html#.minus) - 减
51
+ - [plus](https://doly-dev.github.io/util-helpers/module-Math.html#.plus) - 加
52
+ - [round](https://doly-dev.github.io/util-helpers/module-Math.html#.round) - 四舍五入
53
+ - [times](https://doly-dev.github.io/util-helpers/module-Math.html#.times) - 乘
54
+ - 其他
55
+ - [ajax](https://doly-dev.github.io/util-helpers/module-Other.html#.ajax) - 请求
56
+ - [calculateCursorPosition](https://doly-dev.github.io/util-helpers/module-Other.html#.calculateCursorPosition) - 计算光标位置
57
+ - [compressImage](https://doly-dev.github.io/util-helpers/module-Other.html#.compressImage) - 压缩图片
58
+ - [download](https://doly-dev.github.io/util-helpers/module-Other.html#.download) - 下载
59
+ - [getFileBlob](https://doly-dev.github.io/util-helpers/module-Other.html#.getFileBlob) - 获取文件 Blob
60
+ - [getImageInfo](https://doly-dev.github.io/util-helpers/module-Other.html#.getImageInfo) - 获取图片信息
61
+ - [loadImage](https://doly-dev.github.io/util-helpers/module-Other.html#.loadImage) - 加载图片
62
+ - [loadImageWithBlob](https://doly-dev.github.io/util-helpers/module-Other.html#.loadImageWithBlob) - 加载图片和 blob 对象
63
+ - [loadScript](https://doly-dev.github.io/util-helpers/module-Other.html#.loadScript) - 加载 js 文件
64
+ - [randomString](https://doly-dev.github.io/util-helpers/module-Other.html#.randomString) - 随机字符串
65
+ - [strlen](https://doly-dev.github.io/util-helpers/module-Other.html#.strlen) - 字符长度
54
66
  - 数据处理
55
67
  - [bytesToSize](https://doly-dev.github.io/util-helpers/module-Processor.html#.bytesToSize) - 字节转换为存储单位
56
68
  - [dataURLToBlob](https://doly-dev.github.io/util-helpers/module-Processor.html#.dataURLToBlob) - 将 DataURL 转为 Blob 对象
57
69
  - [fileReader](https://doly-dev.github.io/util-helpers/module-Processor.html#.fileReader) - 读取 Blob 或 File 对象,转为 Base64/String/ArrayBuffer
58
- - [formatMoney](https://doly-dev.github.io/util-helpers/module-Processor.html#.formatMoney) - 格式化金额
59
- - [formatMobile](https://doly-dev.github.io/util-helpers/module-Processor.html#.formatMobile) - 格式化手机号码
60
70
  - [formatBankCard](https://doly-dev.github.io/util-helpers/module-Processor.html#.formatBankCard) - 格式化银行卡
71
+ - [formatMobile](https://doly-dev.github.io/util-helpers/module-Processor.html#.formatMobile) - 格式化手机号码
72
+ - [formatMoney](https://doly-dev.github.io/util-helpers/module-Processor.html#.formatMoney) - 格式化金额
61
73
  - [numberToChinese](https://doly-dev.github.io/util-helpers/module-Processor.html#.numberToChinese) - 数字转中文数字
62
74
  - [padZero](https://doly-dev.github.io/util-helpers/module-Processor.html#.padZero) - 前置补零
63
75
  - [parseIdCard](https://doly-dev.github.io/util-helpers/module-Processor.html#.parseIdCard) - 解析身份证号码
@@ -65,48 +77,36 @@ formatBankCard('6228480402564890018', { spaceMark: '-' }); // 6228-4804-0256-489
65
77
  - [safeDate](https://doly-dev.github.io/util-helpers/module-Processor.html#.safeDate) - 创建一个 Date 实例,同 new Date
66
78
  - [setDataURLPrefix](https://doly-dev.github.io/util-helpers/module-Processor.html#.setDataURLPrefix) - 设置 DataURL 前缀、MIME 类型、base64 标识
67
79
  - 树结构数据操作
80
+ - [filterTree](https://doly-dev.github.io/util-helpers/module-Processor.html#.filterTree) - 过滤树节点
68
81
  - [findTreeNode](https://doly-dev.github.io/util-helpers/module-Other.html#.findTreeNode) - 查找树结构数据节点
69
82
  - [findTreeNodes](https://doly-dev.github.io/util-helpers/module-Other.html#.findTreeNodes) - 查找树结构数据多个节点
70
83
  - [findTreeSelect](https://doly-dev.github.io/util-helpers/module-Other.html#.findTreeSelect) - 查找包含当前节点的所有父级节点
71
- - [filterTree](https://doly-dev.github.io/util-helpers/module-Processor.html#.filterTree) - 过滤树节点
72
84
  - [listToTree](https://doly-dev.github.io/util-helpers/module-Processor.html#.listToTree) - 列表数据转树结构
73
85
  - [transformFieldNames](https://doly-dev.github.io/util-helpers/module-Processor.html#.transformFieldNames) - 转换字段名
74
86
  - [treeToList](https://doly-dev.github.io/util-helpers/module-Processor.html#.treeToList) - 树结构转列表数据
75
87
  - 数据验证
76
- - [isMobile](https://doly-dev.github.io/util-helpers/module-Validator.html#.isMobile) - 手机号码
77
- - [isTelephone](https://doly-dev.github.io/util-helpers/module-Validator.html#.isTelephone) - 固定电话
78
- - [isPostcode](https://doly-dev.github.io/util-helpers/module-Validator.html#.isPostcode) - 邮政编码
88
+ - [isBankCard](https://doly-dev.github.io/util-helpers/module-Validator.html#.isBankCard) - 银行卡
89
+ - [isBusinessLicense](https://doly-dev.github.io/util-helpers/module-Validator.html#.isBusinessLicense) - 营业执照,也叫工商注册号
90
+ - [isChinese](https://doly-dev.github.io/util-helpers/module-Validator.html#.isChinese) - 中文
91
+ - [isEmail](https://doly-dev.github.io/util-helpers/module-Validator.html#.isEmail) - 邮箱
79
92
  - [isHMCard](https://doly-dev.github.io/util-helpers/module-Validator.html#.isHMCard) - 港澳居民来往内地通行证,俗称回乡证或回乡卡
80
- - [isTWCard](https://doly-dev.github.io/util-helpers/module-Validator.html#.isTWCard) - 台湾居民来往大陆通行证,俗称台胞证
93
+ - [isIPv4](https://doly-dev.github.io/util-helpers/module-Validator.html#.isIPv4) - IPv4
94
+ - [isIPv6](https://doly-dev.github.io/util-helpers/module-Validator.html#.isIPv6) - IPv6
81
95
  - [isIdCard](https://doly-dev.github.io/util-helpers/module-Validator.html#.isIdCard) - 身份证号
82
- - [isEmail](https://doly-dev.github.io/util-helpers/module-Validator.html#.isEmail) - 邮箱
96
+ - [isMobile](https://doly-dev.github.io/util-helpers/module-Validator.html#.isMobile) - 手机号码
97
+ - [isPassport](https://doly-dev.github.io/util-helpers/module-Validator.html#.isPassport) - 护照号
98
+ - [isPassword](https://doly-dev.github.io/util-helpers/module-Validator.html#.isPassword) 密码强度
99
+ - [isPostcode](https://doly-dev.github.io/util-helpers/module-Validator.html#.isPostcode) - 邮政编码
83
100
  - [isQQ](https://doly-dev.github.io/util-helpers/module-Validator.html#.isQQ) - QQ 号
84
- - [isWX](https://doly-dev.github.io/util-helpers/module-Validator.html#.isWX) - 微信号
85
- - [isVehicle](https://doly-dev.github.io/util-helpers/module-Validator.html#.isVehicle) - 车牌号
86
- - [isBankCard](https://doly-dev.github.io/util-helpers/module-Validator.html#.isBankCard) - 银行卡
87
101
  - [isSocialCreditCode](https://doly-dev.github.io/util-helpers/module-Validator.html#.isSocialCreditCode) - 统一社会信用代码,也叫三证合一组织代码
88
102
  - [isSwiftCode](https://doly-dev.github.io/util-helpers/module-Validator.html#.isSwiftCode) - Swift Code
89
- - [isPassword](https://doly-dev.github.io/util-helpers/module-Validator.html#.isPassword) 密码强度
90
- - [isPassport](https://doly-dev.github.io/util-helpers/module-Validator.html#.isPassport) - 护照号
91
- - [isChinese](https://doly-dev.github.io/util-helpers/module-Validator.html#.isChinese) - 中文
92
- - [isIPv4](https://doly-dev.github.io/util-helpers/module-Validator.html#.isIPv4) - IPv4
93
- - [isIPv6](https://doly-dev.github.io/util-helpers/module-Validator.html#.isIPv6) - IPv6
103
+ - [isTWCard](https://doly-dev.github.io/util-helpers/module-Validator.html#.isTWCard) - 台湾居民来往大陆通行证,俗称台胞证
104
+ - [isTelephone](https://doly-dev.github.io/util-helpers/module-Validator.html#.isTelephone) - 固定电话
94
105
  - [isUrl](https://doly-dev.github.io/util-helpers/module-Validator.html#.isUrl) - URL
95
106
  - [isValidNumber](https://doly-dev.github.io/util-helpers/module-Validator.html#.isValidNumber) - 有效数字
96
- - [isBusinessLicense](https://doly-dev.github.io/util-helpers/module-Validator.html#.isBusinessLicense) - 营业执照,也叫工商注册号
107
+ - [isVehicle](https://doly-dev.github.io/util-helpers/module-Validator.html#.isVehicle) - 车牌号
108
+ - [isWX](https://doly-dev.github.io/util-helpers/module-Validator.html#.isWX) - 微信号
97
109
  - [validatePassword](https://doly-dev.github.io/util-helpers/module-Validator.html#.validatePassword) - 验证密码
98
- - 其他
99
- - [ajax](https://doly-dev.github.io/util-helpers/module-Other.html#.ajax) - 请求
100
- - [calculateCursorPosition](https://doly-dev.github.io/util-helpers/module-Other.html#.calculateCursorPosition) - 计算光标位置
101
- - [compressImage](https://doly-dev.github.io/util-helpers/module-Other.html#.compressImage) - 压缩图片
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
104
- - [getImageInfo](https://doly-dev.github.io/util-helpers/module-Other.html#.getImageInfo) - 获取图片信息
105
- - [loadImage](https://doly-dev.github.io/util-helpers/module-Other.html#.loadImage) - 加载图片
106
- - [loadImageWithBlob](https://doly-dev.github.io/util-helpers/module-Other.html#.loadImageWithBlob) - 加载图片和 blob 对象
107
- - [loadScript](https://doly-dev.github.io/util-helpers/module-Other.html#.loadScript) - 加载 js 文件
108
- - [randomString](https://doly-dev.github.io/util-helpers/module-Other.html#.randomString) - 随机字符串
109
- - [strlen](https://doly-dev.github.io/util-helpers/module-Other.html#.strlen) - 字符长度
110
110
 
111
111
  ## 精选第三方工具库
112
112
 
@@ -1152,7 +1152,7 @@
1152
1152
  dataURL: 'readAsDataURL',
1153
1153
  text: 'readAsText'
1154
1154
  };
1155
- function fileReader(blob, type) {
1155
+ var fileReader = function (blob, type) {
1156
1156
  if (type === void 0) { type = 'dataURL'; }
1157
1157
  var method = FileReaderMethodMap[type];
1158
1158
  if (!method) {
@@ -1164,7 +1164,7 @@
1164
1164
  reader.onload = function () { return resolve(reader.result); };
1165
1165
  reader.onerror = function (error) { return reject(error); };
1166
1166
  });
1167
- }
1167
+ };
1168
1168
 
1169
1169
  function blobToDataURL(blob) {
1170
1170
  return fileReader(blob);
@@ -1194,7 +1194,7 @@
1194
1194
  return toString(value);
1195
1195
  }
1196
1196
 
1197
- function safeDate(value) {
1197
+ var safeDate = function (value) {
1198
1198
  var args = [];
1199
1199
  for (var _i = 1; _i < arguments.length; _i++) {
1200
1200
  args[_i - 1] = arguments[_i];
@@ -1204,7 +1204,7 @@
1204
1204
  return new (Date.bind.apply(Date, __spreadArray([void 0, safeValue], __read(args), false)))();
1205
1205
  }
1206
1206
  return typeof safeValue === 'undefined' ? new Date() : new Date(safeValue);
1207
- }
1207
+ };
1208
1208
 
1209
1209
  function formatMobile(mobileNo, options) {
1210
1210
  if (mobileNo === void 0) { mobileNo = ''; }
@@ -1490,72 +1490,98 @@
1490
1490
 
1491
1491
  var EmitterPro = /** @class */ (function () {
1492
1492
  function EmitterPro() {
1493
- this.handler = {};
1493
+ this.handlers = {};
1494
1494
  }
1495
1495
  EmitterPro.prototype.eventNames = function () {
1496
- return Object.keys(this.handler);
1496
+ var _a;
1497
+ var symbols = ((_a = Object.getOwnPropertySymbols) === null || _a === void 0 ? void 0 : _a.call(Object, this.handlers)) || [];
1498
+ var keys = Object.keys(this.handlers);
1499
+ return keys.concat(symbols);
1500
+ };
1501
+ EmitterPro.prototype.rawListeners = function (eventName) {
1502
+ var handler = this.handlers[eventName];
1503
+ return handler ? handler.map(function (item) { return item.raw; }) : [];
1497
1504
  };
1498
1505
  EmitterPro.prototype.listeners = function (eventName) {
1499
- return this.handler[eventName] || [];
1506
+ var handler = this.handlers[eventName];
1507
+ return handler ? handler.map(function (item) { return item.wrap; }) : [];
1500
1508
  };
1501
1509
  EmitterPro.prototype.hasListener = function (eventName, listener) {
1502
- return this.listeners(eventName).some(function (item) { return item === listener; });
1510
+ return this.rawListeners(eventName).some(function (item) { return item === listener; });
1503
1511
  };
1504
- EmitterPro.prototype.on = function (eventName, listener) {
1505
- if (!this.handler[eventName]) {
1506
- this.handler[eventName] = [listener];
1512
+ EmitterPro.prototype._on = function (eventName, raw, wrap, context, dir) {
1513
+ if (context === void 0) { context = null; }
1514
+ if (dir === void 0) { dir = 1; }
1515
+ var currentListener = { raw: raw, wrap: wrap, context: context };
1516
+ if (!this.handlers[eventName]) {
1517
+ this.handlers[eventName] = [currentListener];
1507
1518
  }
1508
1519
  else {
1509
- // 不允许添加相同的方法
1510
- if (!this.hasListener(eventName, listener)) {
1511
- this.handler[eventName].push(listener);
1512
- }
1520
+ var appendMethod = dir === 1 ? 'push' : 'unshift';
1521
+ this.handlers[eventName][appendMethod](currentListener);
1513
1522
  }
1514
1523
  return this;
1515
1524
  };
1525
+ EmitterPro.prototype.prependListener = function (eventName, listener, context) {
1526
+ return this._on(eventName, listener, listener, context, 0);
1527
+ };
1528
+ EmitterPro.prototype.on = function (eventName, listener, context) {
1529
+ return this._on(eventName, listener, listener, context);
1530
+ };
1531
+ EmitterPro.prototype._wrapOnce = function (eventName, listener, context) {
1532
+ var _this = this;
1533
+ if (context === void 0) { context = null; }
1534
+ var wrap = (function () {
1535
+ var args = [];
1536
+ for (var _i = 0; _i < arguments.length; _i++) {
1537
+ args[_i] = arguments[_i];
1538
+ }
1539
+ listener.apply(context, args);
1540
+ _this.off(eventName, wrap);
1541
+ });
1542
+ return wrap;
1543
+ };
1544
+ EmitterPro.prototype.once = function (eventName, listener, context) {
1545
+ var wrap = this._wrapOnce(eventName, listener, context);
1546
+ return this._on(eventName, listener, wrap, context);
1547
+ };
1548
+ EmitterPro.prototype.prependOnceListener = function (eventName, listener, context) {
1549
+ var wrap = this._wrapOnce(eventName, listener, context);
1550
+ return this._on(eventName, listener, wrap, context, 0);
1551
+ };
1516
1552
  EmitterPro.prototype.off = function (eventName, listener) {
1517
- if (this.handler[eventName]) {
1518
- if (typeof listener === 'function') {
1519
- this.handler[eventName] = this.handler[eventName].filter(function (item) { return item !== listener; });
1553
+ var handler = this.handlers[eventName];
1554
+ if (handler) {
1555
+ if (listener) {
1556
+ var index = handler.findIndex(function (item) { return item.wrap === listener || item.raw === listener; });
1557
+ if (index !== -1) {
1558
+ handler.splice(index, 1);
1559
+ }
1520
1560
  }
1521
1561
  else {
1522
- delete this.handler[eventName];
1562
+ delete this.handlers[eventName];
1523
1563
  }
1524
1564
  }
1525
1565
  return this;
1526
1566
  };
1567
+ EmitterPro.prototype.offAll = function () {
1568
+ this.handlers = {};
1569
+ return this;
1570
+ };
1527
1571
  EmitterPro.prototype.emit = function (eventName) {
1528
1572
  var args = [];
1529
1573
  for (var _i = 1; _i < arguments.length; _i++) {
1530
1574
  args[_i - 1] = arguments[_i];
1531
1575
  }
1532
- var listeners = this.listeners(eventName);
1533
- if (listeners.length > 0) {
1534
- listeners.forEach(function (listener) {
1535
- // eslint-disable-next-line prefer-spread
1536
- listener.apply(void 0, args);
1576
+ var handler = this.handlers[eventName];
1577
+ if (handler && handler.length > 0) {
1578
+ handler.forEach(function (listener) {
1579
+ listener.wrap.apply(listener.context, args);
1537
1580
  });
1538
1581
  return true;
1539
1582
  }
1540
1583
  return false;
1541
1584
  };
1542
- EmitterPro.prototype.once = function (eventName, listener) {
1543
- var _this = this;
1544
- var wrap = function () {
1545
- var args = [];
1546
- for (var _i = 0; _i < arguments.length; _i++) {
1547
- args[_i] = arguments[_i];
1548
- }
1549
- // eslint-disable-next-line prefer-spread
1550
- listener.apply(void 0, args);
1551
- _this.off(eventName, wrap);
1552
- };
1553
- return this.on(eventName, wrap);
1554
- };
1555
- EmitterPro.prototype.offAll = function () {
1556
- this.handler = {};
1557
- return this;
1558
- };
1559
1585
  return EmitterPro;
1560
1586
  }());
1561
1587
 
@@ -1654,7 +1680,7 @@
1654
1680
  }, type, quality);
1655
1681
  });
1656
1682
  }
1657
- function compressImage(img, options) {
1683
+ var compressImage = function (img, options) {
1658
1684
  if (options === void 0) { options = {}; }
1659
1685
  return new Promise(function (resolve, reject) {
1660
1686
  var width = options.width, height = options.height, rotate = options.rotate, _a = options.offset, offset = _a === void 0 ? [0, 0] : _a, _b = options.cacheImage, cacheImage = _b === void 0 ? true : _b, _c = options.background, background = _c === void 0 ? '#fff' : _c, canvasWidth = options.canvasWidth, canvasHeight = options.canvasHeight, _d = options.format, format = _d === void 0 ? 'blob' : _d, _e = options.type, type = _e === void 0 ? 'image/jpeg' : _e, _f = options.quality, quality = _f === void 0 ? 0.8 : _f, beforeCompress = options.beforeCompress, beforeDraw = options.beforeDraw, afterDraw = options.afterDraw, ajaxOptions = options.ajaxOptions;
@@ -1711,7 +1737,7 @@
1711
1737
  })
1712
1738
  .catch(reject);
1713
1739
  });
1714
- }
1740
+ };
1715
1741
 
1716
1742
  function saver(blobUrl, fileName) {
1717
1743
  if (fileName === void 0) { fileName = ''; }
@@ -2231,9 +2257,9 @@
2231
2257
  return internalFindTreeSelect(tree, predicate, childrenField);
2232
2258
  }
2233
2259
 
2234
- var VERSION = "4.21.4";
2260
+ var VERSION = "4.21.5";
2235
2261
 
2236
- var version = "4.21.4";
2262
+ var version = "4.21.5";
2237
2263
 
2238
2264
  exports.VERSION = VERSION;
2239
2265
  exports.ajax = ajax;