util-helpers 4.18.0 → 4.19.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 +4 -3
- package/dist/util-helpers.js +51 -2
- 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/index.js +2 -1
- package/esm/loadScript.js +39 -0
- package/lib/VERSION.js +1 -1
- package/lib/index.js +3 -1
- package/lib/loadScript.js +41 -0
- package/package.json +2 -6
- package/types/index.d.ts +1 -0
- package/types/isPromiseLike.d.ts +1 -0
- package/types/loadScript.d.ts +30 -0
- package/types/normalizeString.d.ts +1 -0
- package/types/waitTime.d.ts +1 -0
package/README.md
CHANGED
|
@@ -56,7 +56,6 @@ formatBankCard('6228480402564890018', { spaceMark: '-' }); // 6228-4804-0256-489
|
|
|
56
56
|
- [formatMoney](https://doly-dev.github.io/util-helpers/module-Processor.html#.formatMoney) - 格式化金额
|
|
57
57
|
- [formatMobile](https://doly-dev.github.io/util-helpers/module-Processor.html#.formatMobile) - 格式化手机号码
|
|
58
58
|
- [formatBankCard](https://doly-dev.github.io/util-helpers/module-Processor.html#.formatBankCard) - 格式化银行卡
|
|
59
|
-
- [normalizeString](https://doly-dev.github.io/util-helpers/module-Processor.html#.normalizeString) - 规整化字符串,如果值为 `undefined` `null` 转为 '',如果不是字符串类型则转为字符串
|
|
60
59
|
- [numberToChinese](https://doly-dev.github.io/util-helpers/module-Processor.html#.numberToChinese) - 数字转中文数字
|
|
61
60
|
- [padZero](https://doly-dev.github.io/util-helpers/module-Processor.html#.padZero) - 前置补零
|
|
62
61
|
- [parseIdCard](https://doly-dev.github.io/util-helpers/module-Processor.html#.parseIdCard) - 解析身份证号码
|
|
@@ -87,7 +86,6 @@ formatBankCard('6228480402564890018', { spaceMark: '-' }); // 6228-4804-0256-489
|
|
|
87
86
|
- [isSwiftCode](https://doly-dev.github.io/util-helpers/module-Validator.html#.isSwiftCode) - Swift Code
|
|
88
87
|
- [isPassword](https://doly-dev.github.io/util-helpers/module-Validator.html#.isPassword) 密码强度
|
|
89
88
|
- [isPassport](https://doly-dev.github.io/util-helpers/module-Validator.html#.isPassport) - 护照号
|
|
90
|
-
- [isPromiseLike](https://doly-dev.github.io/util-helpers/module-Validator.html#.isPromiseLike) - 类似 Promise 对象
|
|
91
89
|
- [isChinese](https://doly-dev.github.io/util-helpers/module-Validator.html#.isChinese) - 中文
|
|
92
90
|
- [isIPv4](https://doly-dev.github.io/util-helpers/module-Validator.html#.isIPv4) - IPv4
|
|
93
91
|
- [isIPv6](https://doly-dev.github.io/util-helpers/module-Validator.html#.isIPv6) - IPv6
|
|
@@ -99,16 +97,18 @@ formatBankCard('6228480402564890018', { spaceMark: '-' }); // 6228-4804-0256-489
|
|
|
99
97
|
- [ajax](https://doly-dev.github.io/util-helpers/module-Other.html#.ajax) - 请求
|
|
100
98
|
- [calculateCursorPosition](https://doly-dev.github.io/util-helpers/module-Other.html#.calculateCursorPosition) - 计算光标位置
|
|
101
99
|
- [download](https://doly-dev.github.io/util-helpers/module-Other.html#.download) - 下载
|
|
100
|
+
- [loadScript](https://doly-dev.github.io/util-helpers/module-Other.html#.loadScript) - 加载 js 文件
|
|
102
101
|
- [randomString](https://doly-dev.github.io/util-helpers/module-Other.html#.randomString) - 随机字符串
|
|
103
102
|
- [strlen](https://doly-dev.github.io/util-helpers/module-Other.html#.strlen) - 字符长度
|
|
104
|
-
- [waitTime](https://doly-dev.github.io/util-helpers/module-Other.html#.waitTime) - 等待时间返回 Promise
|
|
105
103
|
|
|
106
104
|
## 精选第三方工具库
|
|
107
105
|
|
|
106
|
+
- [ut2] - 一个现代 JavaScript 实用工具库
|
|
108
107
|
- [lodash] - 封装了诸多对字符串、数组、对象等常见数据类型的处理函数
|
|
109
108
|
- [query-string] - URL 解析、序列化
|
|
110
109
|
- [qs] - URL 查询字符串解析和序列化库
|
|
111
110
|
- [js-cookie] - 一个简单,轻量级的 JavaScript API,用于处理 cookie
|
|
111
|
+
- [cache2] - 一个简单的 JavaScript 缓存管理,支持浏览器端和 node.js
|
|
112
112
|
- [store2] - 丰富了 localStorage 和 sessionStorage 功能(JSON,命名空间,扩展等)
|
|
113
113
|
- [dayjs] - 一个轻量的处理时间和日期的 JavaScript 库,和 Moment.js 的 API 设计保持完全一样
|
|
114
114
|
- [date-fns] - 提供了最全面、简单且一致的工具集,用于在浏览器和 Node.js 中操作 JavaScript 日期
|
|
@@ -122,6 +122,7 @@ formatBankCard('6228480402564890018', { spaceMark: '-' }); // 6228-4804-0256-489
|
|
|
122
122
|
- [JSZip] - 创建、读取和编辑 zip 文件
|
|
123
123
|
- [ua-parser-js] - 用于从用户代理数据中检测浏览器、引擎、操作系统、CPU 和设备类型/型号
|
|
124
124
|
|
|
125
|
+
[ut2]: https://www.npmjs.com/package/ut2
|
|
125
126
|
[lodash]: https://www.npmjs.com/package/lodash
|
|
126
127
|
[query-string]: https://www.npmjs.com/package/query-string
|
|
127
128
|
[qs]: https://www.npmjs.com/package/qs
|
package/dist/util-helpers.js
CHANGED
|
@@ -157,6 +157,18 @@
|
|
|
157
157
|
return __assign.apply(this, arguments);
|
|
158
158
|
};
|
|
159
159
|
|
|
160
|
+
function __rest(s, e) {
|
|
161
|
+
var t = {};
|
|
162
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
163
|
+
t[p] = s[p];
|
|
164
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
165
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
166
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
167
|
+
t[p[i]] = s[p[i]];
|
|
168
|
+
}
|
|
169
|
+
return t;
|
|
170
|
+
}
|
|
171
|
+
|
|
160
172
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
161
173
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
162
174
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -1407,6 +1419,42 @@
|
|
|
1407
1419
|
});
|
|
1408
1420
|
}
|
|
1409
1421
|
|
|
1422
|
+
function loadScript(src, options) {
|
|
1423
|
+
return new Promise(function (resolve, reject) {
|
|
1424
|
+
var head = document.head;
|
|
1425
|
+
var script = document.createElement('script');
|
|
1426
|
+
var _a = options || {}, attrs = _a.attrs, _b = _a.destroyOnError, destroyOnError = _b === void 0 ? true : _b, restOptions = __rest(_a, ["attrs", "destroyOnError"]);
|
|
1427
|
+
var props = __assign(__assign({ async: true, type: 'text/javascript' }, restOptions), { src: src });
|
|
1428
|
+
for (var key in props) {
|
|
1429
|
+
if (key === 'onload' || key === 'onerror') {
|
|
1430
|
+
continue;
|
|
1431
|
+
}
|
|
1432
|
+
script[key] = props[key];
|
|
1433
|
+
}
|
|
1434
|
+
if (typeof attrs === 'object') {
|
|
1435
|
+
Object.keys(attrs).forEach(function (key) {
|
|
1436
|
+
script.setAttribute(key, attrs[key]);
|
|
1437
|
+
});
|
|
1438
|
+
}
|
|
1439
|
+
script.onload = function (ev) {
|
|
1440
|
+
var _a;
|
|
1441
|
+
this.onerror = this.onload = null;
|
|
1442
|
+
(_a = props.onload) === null || _a === void 0 ? void 0 : _a.call(this, ev);
|
|
1443
|
+
resolve(script);
|
|
1444
|
+
};
|
|
1445
|
+
script.onerror = function (ev) {
|
|
1446
|
+
var _a;
|
|
1447
|
+
this.onerror = this.onload = null;
|
|
1448
|
+
(_a = props.onerror) === null || _a === void 0 ? void 0 : _a.call(this, ev);
|
|
1449
|
+
if (destroyOnError) {
|
|
1450
|
+
head.removeChild(script);
|
|
1451
|
+
}
|
|
1452
|
+
reject(new URIError('Failed to load ' + this.src));
|
|
1453
|
+
};
|
|
1454
|
+
head.appendChild(script);
|
|
1455
|
+
});
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1410
1458
|
var numberChars = '0123456789';
|
|
1411
1459
|
var letterChars = 'abcdefghijklmnopqrstuvwxyz';
|
|
1412
1460
|
var defaultChars = numberChars + letterChars + letterChars.toUpperCase();
|
|
@@ -1700,9 +1748,9 @@
|
|
|
1700
1748
|
return internalFindTreeSelect(tree, predicate, childrenField);
|
|
1701
1749
|
}
|
|
1702
1750
|
|
|
1703
|
-
var VERSION = "4.
|
|
1751
|
+
var VERSION = "4.19.0";
|
|
1704
1752
|
|
|
1705
|
-
var version = "4.
|
|
1753
|
+
var version = "4.19.0";
|
|
1706
1754
|
|
|
1707
1755
|
exports.VERSION = VERSION;
|
|
1708
1756
|
exports.ajax = ajax;
|
|
@@ -1743,6 +1791,7 @@
|
|
|
1743
1791
|
exports.isVehicle = isVehicle;
|
|
1744
1792
|
exports.isWX = isWX;
|
|
1745
1793
|
exports.listToTree = listToTree;
|
|
1794
|
+
exports.loadScript = loadScript;
|
|
1746
1795
|
exports.minus = minus;
|
|
1747
1796
|
exports.normalizeString = normalizeString;
|
|
1748
1797
|
exports.numberToChinese = numberToChinese;
|