util-helpers 4.12.9 → 4.13.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 (47) hide show
  1. package/README.md +8 -1
  2. package/dist/util-helpers.js +133 -115
  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 +7 -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/isUrl.js +28 -6
  16. package/esm/numberToChinese.js +14 -15
  17. package/esm/replaceChar.js +10 -9
  18. package/esm/utils/config.js +1 -1
  19. package/esm/validatePassword.js +7 -8
  20. package/lib/calculateCursorPosition.js +6 -7
  21. package/lib/formatBankCard.js +5 -5
  22. package/lib/formatMobile.js +4 -3
  23. package/lib/formatMoney.js +9 -10
  24. package/lib/isBankCard.js +5 -6
  25. package/lib/isChinese.js +7 -6
  26. package/lib/isIdCard.js +5 -6
  27. package/lib/isPassword.js +7 -8
  28. package/lib/isTWCard.js +3 -4
  29. package/lib/isUrl.js +28 -6
  30. package/lib/numberToChinese.js +14 -15
  31. package/lib/replaceChar.js +10 -9
  32. package/lib/utils/config.js +1 -1
  33. package/lib/validatePassword.js +7 -8
  34. package/package.json +1 -1
  35. package/types/calculateCursorPosition.d.ts +1 -1
  36. package/types/formatBankCard.d.ts +1 -1
  37. package/types/formatMobile.d.ts +1 -1
  38. package/types/formatMoney.d.ts +1 -1
  39. package/types/isBankCard.d.ts +1 -1
  40. package/types/isChinese.d.ts +3 -1
  41. package/types/isIdCard.d.ts +1 -1
  42. package/types/isPassword.d.ts +1 -1
  43. package/types/isTWCard.d.ts +1 -1
  44. package/types/isUrl.d.ts +12 -3
  45. package/types/numberToChinese.d.ts +1 -1
  46. package/types/replaceChar.d.ts +1 -1
  47. package/types/validatePassword.d.ts +1 -1
@@ -48,16 +48,17 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
48
48
  *
49
49
  */
50
50
  function replaceChar(str) {
51
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
52
- _ref$start = _ref.start,
53
- start = _ref$start === void 0 ? 3 : _ref$start,
54
- _ref$end = _ref.end,
55
- end = _ref$end === void 0 ? -4 : _ref$end,
56
- _ref$char = _ref["char"],
57
- _char = _ref$char === void 0 ? '*' : _ref$char,
58
- repeat = _ref.repeat,
59
- exclude = _ref.exclude;
51
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
60
52
 
53
+ var _options$char = options["char"],
54
+ _char = _options$char === void 0 ? '*' : _options$char,
55
+ exclude = options.exclude;
56
+
57
+ var _options$start = options.start,
58
+ start = _options$start === void 0 ? 3 : _options$start,
59
+ _options$end = options.end,
60
+ end = _options$end === void 0 ? -4 : _options$end,
61
+ repeat = options.repeat;
61
62
  var realStr = (0, _normalizeString["default"])(str);
62
63
  var strLen = realStr.length; // 开始位置超过str长度
63
64
 
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.setDisableWarning = setDisableWarning;
7
7
  exports.version = exports.config = void 0;
8
8
  // @ts-ignore
9
- var version = "4.12.9";
9
+ var version = "4.13.0";
10
10
  exports.version = version;
11
11
  var config = {
12
12
  // 禁用warning提示
@@ -227,14 +227,13 @@ function hasUnallowableCharacter(val, chars) {
227
227
 
228
228
 
229
229
  function validatePassword(value) {
230
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
231
- _ref$level = _ref.level,
232
- level = _ref$level === void 0 ? 2 : _ref$level,
233
- _ref$ignoreCase = _ref.ignoreCase,
234
- ignoreCase = _ref$ignoreCase === void 0 ? false : _ref$ignoreCase,
235
- _ref$special = _ref.special,
236
- special = _ref$special === void 0 ? '\\x21-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E' : _ref$special;
237
-
230
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
231
+ var _options$level = options.level,
232
+ level = _options$level === void 0 ? 2 : _options$level,
233
+ _options$ignoreCase = options.ignoreCase,
234
+ ignoreCase = _options$ignoreCase === void 0 ? false : _options$ignoreCase,
235
+ _options$special = options.special,
236
+ special = _options$special === void 0 ? '\\x21-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E' : _options$special;
238
237
  var valStr = value;
239
238
 
240
239
  if (typeof value !== 'string') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "util-helpers",
3
- "version": "4.12.9",
3
+ "version": "4.13.0",
4
4
  "description": "一个基于业务场景的工具方法库",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -19,7 +19,7 @@ export default calculateCursorPosition;
19
19
  * @param {'mobile'|'bankCard'} [options.type] 格式化类型,内置手机号码和银行卡号特殊处理
20
20
  * @returns {number} 格式化后的光标位置
21
21
  */
22
- declare function calculateCursorPosition(prevPos: number, prevCtrlValue: string, rawValue: string, ctrlValue: string, { placeholderChar, maskReg, type }?: {
22
+ declare function calculateCursorPosition(prevPos: number, prevCtrlValue: string, rawValue: string, ctrlValue: string, options?: {
23
23
  placeholderChar?: string | string[] | undefined;
24
24
  maskReg?: RegExp | undefined;
25
25
  type?: "mobile" | "bankCard" | undefined;
@@ -25,7 +25,7 @@ export default formatBankCard;
25
25
  * formatBankCard('6228480402564890', {char: '-'}); // 6228-4804-0256-4890
26
26
  *
27
27
  */
28
- declare function formatBankCard(bankCardNo?: string, { char, length }?: {
28
+ declare function formatBankCard(bankCardNo?: string, options?: {
29
29
  char?: string | undefined;
30
30
  length?: number | undefined;
31
31
  } | undefined): string;
@@ -24,6 +24,6 @@ export default formatMobile;
24
24
  * formatMobile('13345678'); // 133 4567 8
25
25
  *
26
26
  */
27
- declare function formatMobile(mobileNo: string, { char }?: {
27
+ declare function formatMobile(mobileNo: string, options?: {
28
28
  char?: string | undefined;
29
29
  } | undefined): string;
@@ -36,7 +36,7 @@ export default formatMoney;
36
36
  * formatMoney(1000.00, { decimal: '&' }); // 1,000&00
37
37
  *
38
38
  */
39
- declare function formatMoney(num: string | number, { precision, symbol, thousand, decimal }?: {
39
+ declare function formatMoney(num: string | number, options?: {
40
40
  precision?: string | number | undefined;
41
41
  symbol?: string | undefined;
42
42
  thousand?: string | undefined;
@@ -21,7 +21,7 @@ export default isBankCard;
21
21
  * isBankCard('123456789', { loose: true }); // true
22
22
  *
23
23
  */
24
- declare function isBankCard(value: any, { loose, luhn }?: {
24
+ declare function isBankCard(value: any, options?: {
25
25
  loose?: boolean | undefined;
26
26
  luhn?: boolean | undefined;
27
27
  } | undefined): boolean;
@@ -6,6 +6,8 @@ export default isChinese;
6
6
  * @alias module:Validator.isChinese
7
7
  * @since 1.1.0
8
8
  * @see 参考 {@link http://www.unicode.org/reports/tr38/#BlockListing|4.4 Listing of Characters Covered by the Unihan Database}
9
+ * @see 参考 {@link https://zh.wikipedia.org/wiki/Unicode字符平面映射|Unicode字符平面映射}
10
+ * @see 参考 {@link https://zh.wikipedia.org/wiki/Unicode區段|Unicode区段}
9
11
  * @param {*} value 要检测的值
10
12
  * @param {Object} [options] 配置项
11
13
  * @param {boolean} [options.loose=false] 宽松模式。如果为true,只要包含中文即为true
@@ -28,7 +30,7 @@ export default isChinese;
28
30
  * isChinese('𠮷aa', { useExtend: true, loose: true }); // true
29
31
  *
30
32
  */
31
- declare function isChinese(value: any, { loose, useExtend }?: {
33
+ declare function isChinese(value: any, options?: {
32
34
  loose?: boolean | undefined;
33
35
  useExtend?: boolean | undefined;
34
36
  } | undefined): boolean;
@@ -25,7 +25,7 @@ export default isIdCard;
25
25
  * isIdCard('320311770706001', { loose: true }); // true
26
26
  *
27
27
  */
28
- declare function isIdCard(value: any, { loose, checkCode }?: {
28
+ declare function isIdCard(value: any, options?: {
29
29
  loose?: boolean | undefined;
30
30
  checkCode?: boolean | undefined;
31
31
  } | undefined): boolean;
@@ -32,7 +32,7 @@ export default isPassword;
32
32
  * isPassword(' _Aa12345678', {level: 3, ignoreCase: true}); // false
33
33
  *
34
34
  */
35
- declare function isPassword(value: any, { level, ignoreCase, special }?: {
35
+ declare function isPassword(value: any, options?: {
36
36
  level?: number | undefined;
37
37
  ignoreCase?: boolean | undefined;
38
38
  special?: string | undefined;
@@ -21,6 +21,6 @@ export default isTWCard;
21
21
  * // 宽松模式,支持一次性短期通行证
22
22
  * isTWCard('F290299977', { loose: true }); // true
23
23
  */
24
- declare function isTWCard(value: any, { loose }?: {
24
+ declare function isTWCard(value: any, options?: {
25
25
  loose?: boolean | undefined;
26
26
  } | undefined): boolean;
package/types/isUrl.d.ts CHANGED
@@ -11,12 +11,21 @@ export default isUrl;
11
11
  * @example
12
12
  *
13
13
  * isUrl(''); // false
14
- * isUrl('8.8.8.8'); // false
14
+ * isUrl('/foo/bar'); // false
15
+ *
16
+ * isUrl('8.8.8.8'); // true
15
17
  * isUrl('example.com'); // true
16
18
  * isUrl('http://example.com'); // true
17
19
  * isUrl('https://example.com:8080'); // true
18
- * isUrl('http://www.example.com/test/123'); // true
19
- * isUrl('http://www.example.com/test/123?foo=bar'); // true
20
+ * isUrl('https://www.example.com/test/123'); // true
21
+ * isUrl('https://www.example.com/test/123?foo=bar'); // true
22
+ * isUrl('https://www.example.com/test/123?foo=中文#id'); // true
23
+ * isUrl('https://www.example.com/test/123?foo=中文#测试'); // true
24
+ * isUrl('ftp://127.0.0.1:8080/测试.tar'); // true
25
+ * isUrl('a.b'); // true
26
+ * isUrl('a.b:8080'); // true
27
+ * isUrl('p://a.b'); // true
28
+ * isUrl('p://a.b:8888'); // true
20
29
  *
21
30
  */
22
31
  declare function isUrl(value: any): boolean;
@@ -36,7 +36,7 @@ export default numberToChinese;
36
36
  * numberToChinese(1990, {unit: false, zero:'〇'}); // 一九九〇
37
37
  *
38
38
  */
39
- declare function numberToChinese(num: number, { big5, unit, decimal, zero, negative, unitConfig }?: {
39
+ declare function numberToChinese(num: number, options?: {
40
40
  big5?: boolean | undefined;
41
41
  unit?: boolean | undefined;
42
42
  decimal?: string | undefined;
@@ -37,7 +37,7 @@ export default replaceChar;
37
37
  * replaceChar('林某某某', {start: 1, end: Infinity, repeat: 2}); // 林**
38
38
  *
39
39
  */
40
- declare function replaceChar(str: string, { start, end, char, repeat, exclude }?: {
40
+ declare function replaceChar(str: string, options?: {
41
41
  start?: number | undefined;
42
42
  end?: number | undefined;
43
43
  char?: string | undefined;
@@ -127,7 +127,7 @@ export type ValidatePasswordReturn = {
127
127
  * }
128
128
  * }
129
129
  */
130
- declare function validatePassword(value: string, { level, ignoreCase, special }?: {
130
+ declare function validatePassword(value: string, options?: {
131
131
  level?: number | undefined;
132
132
  ignoreCase?: boolean | undefined;
133
133
  special?: string | undefined;