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.
Files changed (44) hide show
  1. package/README.md +3 -1
  2. package/dist/util-helpers.js +81 -88
  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/calculateCursorPosition.js +6 -7
  7. package/esm/formatBankCard.js +5 -5
  8. package/esm/formatMobile.js +4 -3
  9. package/esm/formatMoney.js +9 -10
  10. package/esm/isBankCard.js +5 -6
  11. package/esm/isChinese.js +5 -6
  12. package/esm/isIdCard.js +5 -6
  13. package/esm/isPassword.js +7 -8
  14. package/esm/isTWCard.js +3 -4
  15. package/esm/numberToChinese.js +14 -15
  16. package/esm/replaceChar.js +10 -9
  17. package/esm/utils/config.js +1 -1
  18. package/esm/validatePassword.js +7 -8
  19. package/lib/calculateCursorPosition.js +6 -7
  20. package/lib/formatBankCard.js +5 -5
  21. package/lib/formatMobile.js +4 -3
  22. package/lib/formatMoney.js +9 -10
  23. package/lib/isBankCard.js +5 -6
  24. package/lib/isChinese.js +5 -6
  25. package/lib/isIdCard.js +5 -6
  26. package/lib/isPassword.js +7 -8
  27. package/lib/isTWCard.js +3 -4
  28. package/lib/numberToChinese.js +14 -15
  29. package/lib/replaceChar.js +10 -9
  30. package/lib/utils/config.js +1 -1
  31. package/lib/validatePassword.js +7 -8
  32. package/package.json +2 -1
  33. package/types/calculateCursorPosition.d.ts +1 -1
  34. package/types/formatBankCard.d.ts +1 -1
  35. package/types/formatMobile.d.ts +1 -1
  36. package/types/formatMoney.d.ts +1 -1
  37. package/types/isBankCard.d.ts +1 -1
  38. package/types/isChinese.d.ts +1 -1
  39. package/types/isIdCard.d.ts +1 -1
  40. package/types/isPassword.d.ts +1 -1
  41. package/types/isTWCard.d.ts +1 -1
  42. package/types/numberToChinese.d.ts +1 -1
  43. package/types/replaceChar.d.ts +1 -1
  44. 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@latest/dist/) 下载到本地进行使用。或者直接使用 [UNPKG 线上版本](https://unpkg.com/util-helpers@latest/dist/util-helpers.min.js)<sup> _注意版本_ </sup>。
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
@@ -263,12 +263,11 @@
263
263
 
264
264
 
265
265
  function isIdCard(value) {
266
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
267
- _ref$loose = _ref.loose,
268
- loose = _ref$loose === void 0 ? false : _ref$loose,
269
- _ref$checkCode = _ref.checkCode,
270
- checkCode = _ref$checkCode === void 0 ? true : _ref$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 _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
429
- _ref$loose = _ref.loose,
430
- loose = _ref$loose === void 0 ? false : _ref$loose,
431
- _ref$luhn = _ref.luhn,
432
- luhn = _ref$luhn === void 0 ? false : _ref$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.8";
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 _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
783
- _ref$level = _ref.level,
784
- level = _ref$level === void 0 ? 2 : _ref$level,
785
- _ref$ignoreCase = _ref.ignoreCase,
786
- ignoreCase = _ref$ignoreCase === void 0 ? false : _ref$ignoreCase,
787
- _ref$special = _ref.special,
788
- special = _ref$special === void 0 ? '\\x21-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E' : _ref$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 _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
884
- _ref$level = _ref.level,
885
- level = _ref$level === void 0 ? 2 : _ref$level,
886
- _ref$ignoreCase = _ref.ignoreCase,
887
- ignoreCase = _ref$ignoreCase === void 0 ? false : _ref$ignoreCase,
888
- _ref$special = _ref.special,
889
- special = _ref$special === void 0 ? '\\x21-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E' : _ref$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 _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
978
- _ref$loose = _ref.loose,
979
- loose = _ref$loose === void 0 ? false : _ref$loose,
980
- _ref$useExtend = _ref.useExtend,
981
- useExtend = _ref$useExtend === void 0 ? false : _ref$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 _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
1445
- _ref$loose = _ref.loose,
1446
- loose = _ref$loose === void 0 ? false : _ref$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 _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
1875
- _ref$precision = _ref.precision,
1876
- precision = _ref$precision === void 0 ? 2 : _ref$precision,
1877
- symbol = _ref.symbol,
1878
- _ref$thousand = _ref.thousand,
1879
- thousand = _ref$thousand === void 0 ? ',' : _ref$thousand,
1880
- _ref$decimal = _ref.decimal,
1881
- decimal = _ref$decimal === void 0 ? '.' : _ref$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 _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
1941
- _ref$char = _ref["char"],
1942
- _char = _ref$char === void 0 ? ' ' : _ref$char,
1943
- _ref$length = _ref.length,
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 _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
1994
- _ref$start = _ref.start,
1995
- start = _ref$start === void 0 ? 3 : _ref$start,
1996
- _ref$end = _ref.end,
1997
- end = _ref$end === void 0 ? -4 : _ref$end,
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 _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
2210
- _ref$big = _ref.big5,
2211
- big5 = _ref$big === void 0 ? false : _ref$big,
2212
- _ref$unit = _ref.unit,
2213
- unit = _ref$unit === void 0 ? true : _ref$unit,
2214
- _ref$decimal = _ref.decimal,
2215
- decimal = _ref$decimal === void 0 ? '' : _ref$decimal,
2216
- _ref$zero = _ref.zero,
2217
- zero = _ref$zero === void 0 ? '' : _ref$zero,
2218
- _ref$negative = _ref.negative,
2219
- negative = _ref$negative === void 0 ? '负' : _ref$negative,
2220
- _ref$unitConfig = _ref.unitConfig,
2221
- unitConfig = _ref$unitConfig === void 0 ? {} : _ref$unitConfig;
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 _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
2591
- _ref$char = _ref["char"],
2592
- _char = _ref$char === void 0 ? ' ' : _ref$char;
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 _ref = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {},
2909
- _ref$placeholderChar = _ref.placeholderChar,
2910
- placeholderChar = _ref$placeholderChar === void 0 ? ' ' : _ref$placeholderChar,
2911
- _ref$maskReg = _ref.maskReg,
2912
- maskReg = _ref$maskReg === void 0 ? /\D/g : _ref$maskReg,
2913
- type = _ref.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];