util-helpers 4.12.8 → 4.12.10
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 +3 -1
- package/dist/util-helpers.js +81 -88
- 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/calculateCursorPosition.js +6 -7
- package/esm/formatBankCard.js +5 -5
- package/esm/formatMobile.js +4 -3
- package/esm/formatMoney.js +9 -10
- package/esm/isBankCard.js +5 -6
- package/esm/isChinese.js +5 -6
- package/esm/isIdCard.js +5 -6
- package/esm/isPassword.js +7 -8
- package/esm/isTWCard.js +3 -4
- package/esm/numberToChinese.js +14 -15
- package/esm/replaceChar.js +10 -9
- package/esm/utils/config.js +1 -1
- package/esm/validatePassword.js +7 -8
- package/lib/calculateCursorPosition.js +6 -7
- package/lib/formatBankCard.js +5 -5
- package/lib/formatMobile.js +4 -3
- package/lib/formatMoney.js +9 -10
- package/lib/isBankCard.js +5 -6
- package/lib/isChinese.js +5 -6
- package/lib/isIdCard.js +5 -6
- package/lib/isPassword.js +7 -8
- package/lib/isTWCard.js +3 -4
- package/lib/numberToChinese.js +14 -15
- package/lib/replaceChar.js +10 -9
- package/lib/utils/config.js +1 -1
- package/lib/validatePassword.js +7 -8
- package/package.json +2 -1
- package/types/calculateCursorPosition.d.ts +1 -1
- package/types/formatBankCard.d.ts +1 -1
- package/types/formatMobile.d.ts +1 -1
- package/types/formatMoney.d.ts +1 -1
- package/types/isBankCard.d.ts +1 -1
- package/types/isChinese.d.ts +1 -1
- package/types/isIdCard.d.ts +1 -1
- package/types/isPassword.d.ts +1 -1
- package/types/isTWCard.d.ts +1 -1
- package/types/numberToChinese.d.ts +1 -1
- package/types/replaceChar.d.ts +1 -1
- package/types/validatePassword.d.ts +1 -1
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ yarn add util-helpers
|
|
|
24
24
|
|
|
25
25
|
如果你的项目使用的是原生方式开发,可以在浏览器中使用 `script` 标签直接引入文件,并使用全局变量 `utilHelpers` 。
|
|
26
26
|
|
|
27
|
-
`npm` 包的 `util-helpers/dist` 目录下提供了 `UMD` 包 `util-helpers.js` 以及 `util-helpers.min.js`。你也可以通过 [UNPKG](https://unpkg.com/util-helpers
|
|
27
|
+
`npm` 包的 `util-helpers/dist` 目录下提供了 `UMD` 包 `util-helpers.js` 以及 `util-helpers.min.js`。你也可以通过 [UNPKG](https://unpkg.com/browse/util-helpers/dist/) 下载到本地进行使用。或者直接使用 [UNPKG 线上版本](https://unpkg.com/util-helpers/dist/util-helpers.min.js)<sup> _注意版本_ </sup>。
|
|
28
28
|
|
|
29
29
|
## 示例
|
|
30
30
|
|
|
@@ -105,6 +105,7 @@ formatMoney('1000'); // => 1,000.00
|
|
|
105
105
|
- [store2] - 丰富了 localStorage 和 sessionStorage 功能(JSON,命名空间,扩展等)
|
|
106
106
|
- [uuid] - 生成通用唯一识别码(Universally Unique Identifier)
|
|
107
107
|
- [JSZip] - 创建、读取和编辑 zip 文件
|
|
108
|
+
- [ua-parser-js] - 用于从用户代理数据中检测浏览器、引擎、操作系统、CPU 和设备类型/型号
|
|
108
109
|
|
|
109
110
|
[lodash]: https://www.npmjs.com/package/lodash
|
|
110
111
|
[query-string]: https://www.npmjs.com/package/query-string
|
|
@@ -123,3 +124,4 @@ formatMoney('1000'); // => 1,000.00
|
|
|
123
124
|
[npm]: https://img.shields.io/npm/v/util-helpers.svg
|
|
124
125
|
[npm-url]: https://npmjs.com/package/util-helpers
|
|
125
126
|
[what is commitlint]: https://github.com/conventional-changelog/commitlint#what-is-commitlint
|
|
127
|
+
[ua-parser-js]: https://www.npmjs.com/package/ua-parser-js
|
package/dist/util-helpers.js
CHANGED
|
@@ -263,12 +263,11 @@
|
|
|
263
263
|
|
|
264
264
|
|
|
265
265
|
function isIdCard(value) {
|
|
266
|
-
var
|
|
267
|
-
|
|
268
|
-
loose =
|
|
269
|
-
|
|
270
|
-
checkCode =
|
|
271
|
-
|
|
266
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
267
|
+
var _options$loose = options.loose,
|
|
268
|
+
loose = _options$loose === void 0 ? false : _options$loose,
|
|
269
|
+
_options$checkCode = options.checkCode,
|
|
270
|
+
checkCode = _options$checkCode === void 0 ? true : _options$checkCode;
|
|
272
271
|
var valueStr = normalizeString(value);
|
|
273
272
|
|
|
274
273
|
if (valueStr.length === 15 && loose) {
|
|
@@ -425,12 +424,11 @@
|
|
|
425
424
|
|
|
426
425
|
|
|
427
426
|
function isBankCard(value) {
|
|
428
|
-
var
|
|
429
|
-
|
|
430
|
-
loose =
|
|
431
|
-
|
|
432
|
-
luhn =
|
|
433
|
-
|
|
427
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
428
|
+
var _options$loose = options.loose,
|
|
429
|
+
loose = _options$loose === void 0 ? false : _options$loose,
|
|
430
|
+
_options$luhn = options.luhn,
|
|
431
|
+
luhn = _options$luhn === void 0 ? false : _options$luhn;
|
|
434
432
|
var valueStr = normalizeString(value);
|
|
435
433
|
var validateResult = loose ? regLoose.test(valueStr) : reg$6.test(valueStr);
|
|
436
434
|
|
|
@@ -528,7 +526,7 @@
|
|
|
528
526
|
return lastCode === checkCode;
|
|
529
527
|
}
|
|
530
528
|
|
|
531
|
-
const version = "4.12.
|
|
529
|
+
const version = "4.12.10";
|
|
532
530
|
|
|
533
531
|
// @ts-ignore
|
|
534
532
|
var config = {
|
|
@@ -779,14 +777,13 @@
|
|
|
779
777
|
|
|
780
778
|
|
|
781
779
|
function validatePassword(value) {
|
|
782
|
-
var
|
|
783
|
-
|
|
784
|
-
level =
|
|
785
|
-
|
|
786
|
-
ignoreCase =
|
|
787
|
-
|
|
788
|
-
special =
|
|
789
|
-
|
|
780
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
781
|
+
var _options$level = options.level,
|
|
782
|
+
level = _options$level === void 0 ? 2 : _options$level,
|
|
783
|
+
_options$ignoreCase = options.ignoreCase,
|
|
784
|
+
ignoreCase = _options$ignoreCase === void 0 ? false : _options$ignoreCase,
|
|
785
|
+
_options$special = options.special,
|
|
786
|
+
special = _options$special === void 0 ? '\\x21-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E' : _options$special;
|
|
790
787
|
var valStr = value;
|
|
791
788
|
|
|
792
789
|
if (typeof value !== 'string') {
|
|
@@ -880,14 +877,13 @@
|
|
|
880
877
|
*/
|
|
881
878
|
|
|
882
879
|
function isPassword(value) {
|
|
883
|
-
var
|
|
884
|
-
|
|
885
|
-
level =
|
|
886
|
-
|
|
887
|
-
ignoreCase =
|
|
888
|
-
|
|
889
|
-
special =
|
|
890
|
-
|
|
880
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
881
|
+
var _options$level = options.level,
|
|
882
|
+
level = _options$level === void 0 ? 2 : _options$level,
|
|
883
|
+
_options$ignoreCase = options.ignoreCase,
|
|
884
|
+
ignoreCase = _options$ignoreCase === void 0 ? false : _options$ignoreCase,
|
|
885
|
+
_options$special = options.special,
|
|
886
|
+
special = _options$special === void 0 ? '\\x21-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E' : _options$special;
|
|
891
887
|
return validatePassword(value, {
|
|
892
888
|
level: level,
|
|
893
889
|
ignoreCase: ignoreCase,
|
|
@@ -974,12 +970,11 @@
|
|
|
974
970
|
*/
|
|
975
971
|
|
|
976
972
|
function isChinese(value) {
|
|
977
|
-
var
|
|
978
|
-
|
|
979
|
-
loose =
|
|
980
|
-
|
|
981
|
-
useExtend =
|
|
982
|
-
|
|
973
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
974
|
+
var _options$loose = options.loose,
|
|
975
|
+
loose = _options$loose === void 0 ? false : _options$loose,
|
|
976
|
+
_options$useExtend = options.useExtend,
|
|
977
|
+
useExtend = _options$useExtend === void 0 ? false : _options$useExtend;
|
|
983
978
|
var valueStr = normalizeString(value);
|
|
984
979
|
var basicRegExp = loose ? looseChineseRegExp : chineseRegExp;
|
|
985
980
|
var extendRegExp = loose ? looseChineseExtendRegExp : chineseExtendRegExp;
|
|
@@ -1441,10 +1436,9 @@
|
|
|
1441
1436
|
*/
|
|
1442
1437
|
|
|
1443
1438
|
function isTWCard(value) {
|
|
1444
|
-
var
|
|
1445
|
-
|
|
1446
|
-
loose =
|
|
1447
|
-
|
|
1439
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1440
|
+
var _options$loose = options.loose,
|
|
1441
|
+
loose = _options$loose === void 0 ? false : _options$loose;
|
|
1448
1442
|
var valueStr = normalizeString(value);
|
|
1449
1443
|
|
|
1450
1444
|
if (regTWCard.test(valueStr)) {
|
|
@@ -1871,17 +1865,16 @@
|
|
|
1871
1865
|
|
|
1872
1866
|
|
|
1873
1867
|
var formatMoney = function formatMoney(num) {
|
|
1874
|
-
var
|
|
1875
|
-
|
|
1876
|
-
precision =
|
|
1877
|
-
symbol =
|
|
1878
|
-
|
|
1879
|
-
thousand =
|
|
1880
|
-
|
|
1881
|
-
decimal =
|
|
1882
|
-
|
|
1883
|
-
// 数字参数不正确,返回空字符串
|
|
1868
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1869
|
+
var _options$precision = options.precision,
|
|
1870
|
+
precision = _options$precision === void 0 ? 2 : _options$precision,
|
|
1871
|
+
symbol = options.symbol,
|
|
1872
|
+
_options$thousand = options.thousand,
|
|
1873
|
+
thousand = _options$thousand === void 0 ? ',' : _options$thousand,
|
|
1874
|
+
_options$decimal = options.decimal,
|
|
1875
|
+
decimal = _options$decimal === void 0 ? '.' : _options$decimal; // 数字参数不正确,返回空字符串
|
|
1884
1876
|
// @ts-ignore
|
|
1877
|
+
|
|
1885
1878
|
if (!checkNumber(num)) {
|
|
1886
1879
|
return '';
|
|
1887
1880
|
} // 参数规整化
|
|
@@ -1936,12 +1929,12 @@
|
|
|
1936
1929
|
|
|
1937
1930
|
function formatBankCard() {
|
|
1938
1931
|
var bankCardNo = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
1932
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1939
1933
|
|
|
1940
|
-
var
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
length = _ref$length === void 0 ? 4 : _ref$length;
|
|
1934
|
+
var _options$char = options["char"],
|
|
1935
|
+
_char = _options$char === void 0 ? ' ' : _options$char,
|
|
1936
|
+
_options$length = options.length,
|
|
1937
|
+
length = _options$length === void 0 ? 4 : _options$length;
|
|
1945
1938
|
|
|
1946
1939
|
var reg = new RegExp("(.{".concat(length, "})"), 'g');
|
|
1947
1940
|
var regChar = new RegExp("".concat(_char), 'g');
|
|
@@ -1990,16 +1983,17 @@
|
|
|
1990
1983
|
*/
|
|
1991
1984
|
|
|
1992
1985
|
function replaceChar(str) {
|
|
1993
|
-
var
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
_ref$char = _ref["char"],
|
|
1999
|
-
_char = _ref$char === void 0 ? '*' : _ref$char,
|
|
2000
|
-
repeat = _ref.repeat,
|
|
2001
|
-
exclude = _ref.exclude;
|
|
1986
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1987
|
+
|
|
1988
|
+
var _options$char = options["char"],
|
|
1989
|
+
_char = _options$char === void 0 ? '*' : _options$char,
|
|
1990
|
+
exclude = options.exclude;
|
|
2002
1991
|
|
|
1992
|
+
var _options$start = options.start,
|
|
1993
|
+
start = _options$start === void 0 ? 3 : _options$start,
|
|
1994
|
+
_options$end = options.end,
|
|
1995
|
+
end = _options$end === void 0 ? -4 : _options$end,
|
|
1996
|
+
repeat = options.repeat;
|
|
2003
1997
|
var realStr = normalizeString(str);
|
|
2004
1998
|
var strLen = realStr.length; // 开始位置超过str长度
|
|
2005
1999
|
|
|
@@ -2206,21 +2200,20 @@
|
|
|
2206
2200
|
|
|
2207
2201
|
|
|
2208
2202
|
function numberToChinese(num) {
|
|
2209
|
-
var
|
|
2210
|
-
|
|
2211
|
-
big5 =
|
|
2212
|
-
|
|
2213
|
-
unit =
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
// 非数字 或 NaN 不处理
|
|
2203
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2204
|
+
var _options$big = options.big5,
|
|
2205
|
+
big5 = _options$big === void 0 ? false : _options$big,
|
|
2206
|
+
_options$unit = options.unit,
|
|
2207
|
+
unit = _options$unit === void 0 ? true : _options$unit,
|
|
2208
|
+
_options$zero = options.zero,
|
|
2209
|
+
zero = _options$zero === void 0 ? '' : _options$zero,
|
|
2210
|
+
_options$negative = options.negative,
|
|
2211
|
+
negative = _options$negative === void 0 ? '负' : _options$negative,
|
|
2212
|
+
_options$unitConfig = options.unitConfig,
|
|
2213
|
+
unitConfig = _options$unitConfig === void 0 ? {} : _options$unitConfig;
|
|
2214
|
+
var _options$decimal = options.decimal,
|
|
2215
|
+
decimal = _options$decimal === void 0 ? '' : _options$decimal; // 非数字 或 NaN 不处理
|
|
2216
|
+
|
|
2224
2217
|
if (typeof num !== 'number' || isNaN(num)) {
|
|
2225
2218
|
devWarn("\u53C2\u6570\u9519\u8BEF ".concat(num, "\uFF0C\u8BF7\u4F20\u5165\u6570\u5B57"));
|
|
2226
2219
|
return '';
|
|
@@ -2587,9 +2580,10 @@
|
|
|
2587
2580
|
*/
|
|
2588
2581
|
|
|
2589
2582
|
function formatMobile(mobileNo) {
|
|
2590
|
-
var
|
|
2591
|
-
|
|
2592
|
-
|
|
2583
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2584
|
+
|
|
2585
|
+
var _options$char = options["char"],
|
|
2586
|
+
_char = _options$char === void 0 ? ' ' : _options$char;
|
|
2593
2587
|
|
|
2594
2588
|
var regChar = new RegExp(_char, 'g');
|
|
2595
2589
|
var realValue = normalizeString(mobileNo).replace(regChar, '').substring(0, 11);
|
|
@@ -2905,13 +2899,12 @@
|
|
|
2905
2899
|
*/
|
|
2906
2900
|
|
|
2907
2901
|
function calculateCursorPosition(prevPos, prevCtrlValue, rawValue, ctrlValue) {
|
|
2908
|
-
var
|
|
2909
|
-
|
|
2910
|
-
placeholderChar =
|
|
2911
|
-
|
|
2912
|
-
maskReg =
|
|
2913
|
-
type =
|
|
2914
|
-
|
|
2902
|
+
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
2903
|
+
var _options$placeholderC = options.placeholderChar,
|
|
2904
|
+
placeholderChar = _options$placeholderC === void 0 ? ' ' : _options$placeholderC,
|
|
2905
|
+
_options$maskReg = options.maskReg,
|
|
2906
|
+
maskReg = _options$maskReg === void 0 ? /\D/g : _options$maskReg,
|
|
2907
|
+
type = options.type;
|
|
2915
2908
|
var realCtrlValue = normalizeString(prevCtrlValue);
|
|
2916
2909
|
var realRawValue = normalizeString(rawValue);
|
|
2917
2910
|
var placeholderChars = Array.isArray(placeholderChar) ? placeholderChar : [placeholderChar];
|