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.
- package/README.md +8 -1
- package/dist/util-helpers.js +133 -115
- 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 +7 -6
- package/esm/isIdCard.js +5 -6
- package/esm/isPassword.js +7 -8
- package/esm/isTWCard.js +3 -4
- package/esm/isUrl.js +28 -6
- 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 +7 -6
- package/lib/isIdCard.js +5 -6
- package/lib/isPassword.js +7 -8
- package/lib/isTWCard.js +3 -4
- package/lib/isUrl.js +28 -6
- 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 +1 -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 +3 -1
- package/types/isIdCard.d.ts +1 -1
- package/types/isPassword.d.ts +1 -1
- package/types/isTWCard.d.ts +1 -1
- package/types/isUrl.d.ts +12 -3
- package/types/numberToChinese.d.ts +1 -1
- package/types/replaceChar.d.ts +1 -1
- package/types/validatePassword.d.ts +1 -1
package/lib/replaceChar.js
CHANGED
|
@@ -48,16 +48,17 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
48
48
|
*
|
|
49
49
|
*/
|
|
50
50
|
function replaceChar(str) {
|
|
51
|
-
var
|
|
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
|
|
package/lib/utils/config.js
CHANGED
|
@@ -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.
|
|
9
|
+
var version = "4.13.0";
|
|
10
10
|
exports.version = version;
|
|
11
11
|
var config = {
|
|
12
12
|
// 禁用warning提示
|
package/lib/validatePassword.js
CHANGED
|
@@ -227,14 +227,13 @@ function hasUnallowableCharacter(val, chars) {
|
|
|
227
227
|
|
|
228
228
|
|
|
229
229
|
function validatePassword(value) {
|
|
230
|
-
var
|
|
231
|
-
|
|
232
|
-
level =
|
|
233
|
-
|
|
234
|
-
ignoreCase =
|
|
235
|
-
|
|
236
|
-
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
|
@@ -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,
|
|
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,
|
|
28
|
+
declare function formatBankCard(bankCardNo?: string, options?: {
|
|
29
29
|
char?: string | undefined;
|
|
30
30
|
length?: number | undefined;
|
|
31
31
|
} | undefined): string;
|
package/types/formatMobile.d.ts
CHANGED
|
@@ -24,6 +24,6 @@ export default formatMobile;
|
|
|
24
24
|
* formatMobile('13345678'); // 133 4567 8
|
|
25
25
|
*
|
|
26
26
|
*/
|
|
27
|
-
declare function formatMobile(mobileNo: string,
|
|
27
|
+
declare function formatMobile(mobileNo: string, options?: {
|
|
28
28
|
char?: string | undefined;
|
|
29
29
|
} | undefined): string;
|
package/types/formatMoney.d.ts
CHANGED
|
@@ -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,
|
|
39
|
+
declare function formatMoney(num: string | number, options?: {
|
|
40
40
|
precision?: string | number | undefined;
|
|
41
41
|
symbol?: string | undefined;
|
|
42
42
|
thousand?: string | undefined;
|
package/types/isBankCard.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export default isBankCard;
|
|
|
21
21
|
* isBankCard('123456789', { loose: true }); // true
|
|
22
22
|
*
|
|
23
23
|
*/
|
|
24
|
-
declare function isBankCard(value: any,
|
|
24
|
+
declare function isBankCard(value: any, options?: {
|
|
25
25
|
loose?: boolean | undefined;
|
|
26
26
|
luhn?: boolean | undefined;
|
|
27
27
|
} | undefined): boolean;
|
package/types/isChinese.d.ts
CHANGED
|
@@ -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,
|
|
33
|
+
declare function isChinese(value: any, options?: {
|
|
32
34
|
loose?: boolean | undefined;
|
|
33
35
|
useExtend?: boolean | undefined;
|
|
34
36
|
} | undefined): boolean;
|
package/types/isIdCard.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export default isIdCard;
|
|
|
25
25
|
* isIdCard('320311770706001', { loose: true }); // true
|
|
26
26
|
*
|
|
27
27
|
*/
|
|
28
|
-
declare function isIdCard(value: any,
|
|
28
|
+
declare function isIdCard(value: any, options?: {
|
|
29
29
|
loose?: boolean | undefined;
|
|
30
30
|
checkCode?: boolean | undefined;
|
|
31
31
|
} | undefined): boolean;
|
package/types/isPassword.d.ts
CHANGED
|
@@ -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,
|
|
35
|
+
declare function isPassword(value: any, options?: {
|
|
36
36
|
level?: number | undefined;
|
|
37
37
|
ignoreCase?: boolean | undefined;
|
|
38
38
|
special?: string | undefined;
|
package/types/isTWCard.d.ts
CHANGED
|
@@ -21,6 +21,6 @@ export default isTWCard;
|
|
|
21
21
|
* // 宽松模式,支持一次性短期通行证
|
|
22
22
|
* isTWCard('F290299977', { loose: true }); // true
|
|
23
23
|
*/
|
|
24
|
-
declare function isTWCard(value: any,
|
|
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('
|
|
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('
|
|
19
|
-
* isUrl('
|
|
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,
|
|
39
|
+
declare function numberToChinese(num: number, options?: {
|
|
40
40
|
big5?: boolean | undefined;
|
|
41
41
|
unit?: boolean | undefined;
|
|
42
42
|
decimal?: string | undefined;
|
package/types/replaceChar.d.ts
CHANGED
|
@@ -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,
|
|
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,
|
|
130
|
+
declare function validatePassword(value: string, options?: {
|
|
131
131
|
level?: number | undefined;
|
|
132
132
|
ignoreCase?: boolean | undefined;
|
|
133
133
|
special?: string | undefined;
|