phecda-core 2.0.0-alpha.1 → 2.0.0-alpha.3
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/dist/index.d.ts +3 -1
- package/dist/index.global.js +103 -1
- package/dist/index.js +121 -1
- package/dist/index.mjs +103 -1
- package/dist/pipe-5d060247.d.ts +21 -0
- package/dist/preset/index.d.ts +1 -20
- package/dist/preset/index.global.js +20 -15
- package/dist/preset/index.js +21 -15
- package/dist/preset/index.mjs +20 -15
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { a as isArray, b as isBoolean, k as isCnName, m as isDate, l as isEnName, o as isHexColor, j as isIdCard, g as isLandline, h as isMailBox, f as isMobile, c as isNumber, e as isObject, i as isOption, p as isPostalCode, d as isString, n as isWechat, t as toNumber, q as toString } from './pipe-5d060247.js';
|
|
2
|
+
|
|
1
3
|
interface NameSpace {
|
|
2
4
|
[name: string]: Phecda;
|
|
3
5
|
}
|
|
@@ -77,7 +79,7 @@ declare function addDecoToClass<M extends new (...args: any) => any>(c: M, key:
|
|
|
77
79
|
|
|
78
80
|
declare function Init(target: any, key: PropertyKey): void;
|
|
79
81
|
declare function Bind(value: any): (target: any, k: PropertyKey) => void;
|
|
80
|
-
declare function Rule(rule: RegExp | string |
|
|
82
|
+
declare function Rule(rule: RegExp | string | ((arg: any) => boolean | 'ok') | number, info: string | ((k: string) => string), meta?: any): (obj: any, key: PropertyKey) => void;
|
|
81
83
|
declare function Ignore(target: any, key: PropertyKey): void;
|
|
82
84
|
declare function Clear(target: any, key: PropertyKey): void;
|
|
83
85
|
declare function Err<Fn extends (...args: any) => any>(cb: Fn): (target: any, key: PropertyKey) => void;
|
package/dist/index.global.js
CHANGED
|
@@ -59,7 +59,23 @@ var Phecda = (() => {
|
|
|
59
59
|
getTag: () => getTag,
|
|
60
60
|
init: () => init,
|
|
61
61
|
injectProperty: () => injectProperty,
|
|
62
|
+
isArray: () => isArray,
|
|
63
|
+
isBoolean: () => isBoolean,
|
|
64
|
+
isCnName: () => isCnName,
|
|
65
|
+
isDate: () => isDate,
|
|
66
|
+
isEnName: () => isEnName,
|
|
67
|
+
isHexColor: () => isHexColor,
|
|
68
|
+
isIdCard: () => isIdCard,
|
|
69
|
+
isLandline: () => isLandline,
|
|
70
|
+
isMailBox: () => isMailBox,
|
|
71
|
+
isMobile: () => isMobile,
|
|
72
|
+
isNumber: () => isNumber,
|
|
73
|
+
isObject: () => isObject,
|
|
74
|
+
isOption: () => isOption,
|
|
62
75
|
isPhecda: () => isPhecda,
|
|
76
|
+
isPostalCode: () => isPostalCode,
|
|
77
|
+
isString: () => isString,
|
|
78
|
+
isWechat: () => isWechat,
|
|
63
79
|
plainToClass: () => plainToClass,
|
|
64
80
|
regisHandler: () => regisHandler,
|
|
65
81
|
regisInitEvent: () => regisInitEvent,
|
|
@@ -71,6 +87,8 @@ var Phecda = (() => {
|
|
|
71
87
|
setState: () => setState,
|
|
72
88
|
snapShot: () => snapShot,
|
|
73
89
|
to: () => to,
|
|
90
|
+
toNumber: () => toNumber,
|
|
91
|
+
toString: () => toString,
|
|
74
92
|
validate: () => validate
|
|
75
93
|
});
|
|
76
94
|
|
|
@@ -411,7 +429,10 @@ var Phecda = (() => {
|
|
|
411
429
|
if (options.collectError !== false) {
|
|
412
430
|
for (const handler of handlers) {
|
|
413
431
|
const rule = handler.rule;
|
|
414
|
-
|
|
432
|
+
const ret = await validate(rule, data[item]);
|
|
433
|
+
if (ret === "ok")
|
|
434
|
+
break;
|
|
435
|
+
if (rule && !ret) {
|
|
415
436
|
err.push(typeof handler.info === "function" ? handler.info(item) : handler.info);
|
|
416
437
|
if (!options.collectError)
|
|
417
438
|
break;
|
|
@@ -564,5 +585,86 @@ var Phecda = (() => {
|
|
|
564
585
|
};
|
|
565
586
|
}
|
|
566
587
|
__name(Storage, "Storage");
|
|
588
|
+
|
|
589
|
+
// src/preset/rule.ts
|
|
590
|
+
function isOption() {
|
|
591
|
+
return Rule((param) => param === void 0 ? "ok" : true, "");
|
|
592
|
+
}
|
|
593
|
+
__name(isOption, "isOption");
|
|
594
|
+
function isArray(info) {
|
|
595
|
+
return Rule((param) => Array.isArray(param), info || ((k) => `'${k}' should be an array`));
|
|
596
|
+
}
|
|
597
|
+
__name(isArray, "isArray");
|
|
598
|
+
function isBoolean(info) {
|
|
599
|
+
return Rule((param) => [
|
|
600
|
+
true,
|
|
601
|
+
false
|
|
602
|
+
].includes(param), info || ((k) => `'${k}' should be boolean`));
|
|
603
|
+
}
|
|
604
|
+
__name(isBoolean, "isBoolean");
|
|
605
|
+
function isNumber(info) {
|
|
606
|
+
return Rule((param) => typeof param === "number", info || ((k) => `'${k}' should be number`));
|
|
607
|
+
}
|
|
608
|
+
__name(isNumber, "isNumber");
|
|
609
|
+
function isString(info) {
|
|
610
|
+
return Rule((param) => typeof param === "string", info || ((k) => `'${k}' should be a string`));
|
|
611
|
+
}
|
|
612
|
+
__name(isString, "isString");
|
|
613
|
+
function isObject(info) {
|
|
614
|
+
return Rule((param) => {
|
|
615
|
+
return Object.prototype.toString.call(param) === "[object Object]";
|
|
616
|
+
}, info || ((k) => `'${k}' should be an object`));
|
|
617
|
+
}
|
|
618
|
+
__name(isObject, "isObject");
|
|
619
|
+
function isMobile(info) {
|
|
620
|
+
return Rule(/^((\+|00)86)?1((3[\d])|(4[5,6,7,9])|(5[0-3,5-9])|(6[5-7])|(7[0-8])|(8[\d])|(9[1,8,9]))\d{8}$/, info || ((k) => `'${k}' should be a mobile phone number`));
|
|
621
|
+
}
|
|
622
|
+
__name(isMobile, "isMobile");
|
|
623
|
+
function isLandline(info) {
|
|
624
|
+
return Rule(/\d{3}-\d{8}|\d{4}-\d{7}/, info || ((k) => `'${k}' should be a landline`));
|
|
625
|
+
}
|
|
626
|
+
__name(isLandline, "isLandline");
|
|
627
|
+
function isMailBox(info) {
|
|
628
|
+
return Rule(/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/, info || ((k) => `'${k}' should be a mailbox`));
|
|
629
|
+
}
|
|
630
|
+
__name(isMailBox, "isMailBox");
|
|
631
|
+
function isIdCard(info) {
|
|
632
|
+
return Rule(/(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/, info || ((k) => `'${k}' should be an identity card number`));
|
|
633
|
+
}
|
|
634
|
+
__name(isIdCard, "isIdCard");
|
|
635
|
+
function isCnName(info) {
|
|
636
|
+
return Rule(/^([\u4E00-\u9FA5·]{2,16})$/, info || ((k) => `'${k}' \u9700\u8981\u662F\u4E00\u4E2A\u5408\u7406\u7684\u4E2D\u6587\u540D\u5B57`));
|
|
637
|
+
}
|
|
638
|
+
__name(isCnName, "isCnName");
|
|
639
|
+
function isEnName(info) {
|
|
640
|
+
return Rule(/(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/, info || ((k) => `'${k}' should be a valid en-name`));
|
|
641
|
+
}
|
|
642
|
+
__name(isEnName, "isEnName");
|
|
643
|
+
function isDate(info) {
|
|
644
|
+
return Rule(/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/, info || ((k) => `'${k}' should be a valid date`));
|
|
645
|
+
}
|
|
646
|
+
__name(isDate, "isDate");
|
|
647
|
+
function isWechat(info) {
|
|
648
|
+
return Rule(/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/, info || ((k) => `'${k}' should be a valid wechat`));
|
|
649
|
+
}
|
|
650
|
+
__name(isWechat, "isWechat");
|
|
651
|
+
function isHexColor(info) {
|
|
652
|
+
return Rule(/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/, info || ((k) => `'${k}' should be a valid hex-color`));
|
|
653
|
+
}
|
|
654
|
+
__name(isHexColor, "isHexColor");
|
|
655
|
+
function isPostalCode(info) {
|
|
656
|
+
return Rule(/^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/, info || ((k) => `'${k}' should be a valid postal code`));
|
|
657
|
+
}
|
|
658
|
+
__name(isPostalCode, "isPostalCode");
|
|
659
|
+
|
|
660
|
+
// src/preset/pipe.ts
|
|
661
|
+
function toNumber() {
|
|
662
|
+
return Pipe(to((param) => Number(param)));
|
|
663
|
+
}
|
|
664
|
+
__name(toNumber, "toNumber");
|
|
665
|
+
function toString() {
|
|
666
|
+
return Pipe(to((param) => String(param)));
|
|
667
|
+
}
|
|
668
|
+
__name(toString, "toString");
|
|
567
669
|
return __toCommonJS(src_exports);
|
|
568
670
|
})();
|
package/dist/index.js
CHANGED
|
@@ -58,7 +58,23 @@ __export(src_exports, {
|
|
|
58
58
|
getTag: () => getTag,
|
|
59
59
|
init: () => init,
|
|
60
60
|
injectProperty: () => injectProperty,
|
|
61
|
+
isArray: () => isArray,
|
|
62
|
+
isBoolean: () => isBoolean,
|
|
63
|
+
isCnName: () => isCnName,
|
|
64
|
+
isDate: () => isDate,
|
|
65
|
+
isEnName: () => isEnName,
|
|
66
|
+
isHexColor: () => isHexColor,
|
|
67
|
+
isIdCard: () => isIdCard,
|
|
68
|
+
isLandline: () => isLandline,
|
|
69
|
+
isMailBox: () => isMailBox,
|
|
70
|
+
isMobile: () => isMobile,
|
|
71
|
+
isNumber: () => isNumber,
|
|
72
|
+
isObject: () => isObject,
|
|
73
|
+
isOption: () => isOption,
|
|
61
74
|
isPhecda: () => isPhecda,
|
|
75
|
+
isPostalCode: () => isPostalCode,
|
|
76
|
+
isString: () => isString,
|
|
77
|
+
isWechat: () => isWechat,
|
|
62
78
|
plainToClass: () => plainToClass,
|
|
63
79
|
regisHandler: () => regisHandler,
|
|
64
80
|
regisInitEvent: () => regisInitEvent,
|
|
@@ -70,6 +86,8 @@ __export(src_exports, {
|
|
|
70
86
|
setState: () => setState,
|
|
71
87
|
snapShot: () => snapShot,
|
|
72
88
|
to: () => to,
|
|
89
|
+
toNumber: () => toNumber,
|
|
90
|
+
toString: () => toString,
|
|
73
91
|
validate: () => validate
|
|
74
92
|
});
|
|
75
93
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -411,7 +429,10 @@ async function plainToClass(Model, input, options = {}) {
|
|
|
411
429
|
if (options.collectError !== false) {
|
|
412
430
|
for (const handler of handlers) {
|
|
413
431
|
const rule = handler.rule;
|
|
414
|
-
|
|
432
|
+
const ret = await validate(rule, data[item]);
|
|
433
|
+
if (ret === "ok")
|
|
434
|
+
break;
|
|
435
|
+
if (rule && !ret) {
|
|
415
436
|
err.push(typeof handler.info === "function" ? handler.info(item) : handler.info);
|
|
416
437
|
if (!options.collectError)
|
|
417
438
|
break;
|
|
@@ -564,6 +585,87 @@ function Storage(storeKey) {
|
|
|
564
585
|
};
|
|
565
586
|
}
|
|
566
587
|
__name(Storage, "Storage");
|
|
588
|
+
|
|
589
|
+
// src/preset/rule.ts
|
|
590
|
+
function isOption() {
|
|
591
|
+
return Rule((param) => param === void 0 ? "ok" : true, "");
|
|
592
|
+
}
|
|
593
|
+
__name(isOption, "isOption");
|
|
594
|
+
function isArray(info) {
|
|
595
|
+
return Rule((param) => Array.isArray(param), info || ((k) => `'${k}' should be an array`));
|
|
596
|
+
}
|
|
597
|
+
__name(isArray, "isArray");
|
|
598
|
+
function isBoolean(info) {
|
|
599
|
+
return Rule((param) => [
|
|
600
|
+
true,
|
|
601
|
+
false
|
|
602
|
+
].includes(param), info || ((k) => `'${k}' should be boolean`));
|
|
603
|
+
}
|
|
604
|
+
__name(isBoolean, "isBoolean");
|
|
605
|
+
function isNumber(info) {
|
|
606
|
+
return Rule((param) => typeof param === "number", info || ((k) => `'${k}' should be number`));
|
|
607
|
+
}
|
|
608
|
+
__name(isNumber, "isNumber");
|
|
609
|
+
function isString(info) {
|
|
610
|
+
return Rule((param) => typeof param === "string", info || ((k) => `'${k}' should be a string`));
|
|
611
|
+
}
|
|
612
|
+
__name(isString, "isString");
|
|
613
|
+
function isObject(info) {
|
|
614
|
+
return Rule((param) => {
|
|
615
|
+
return Object.prototype.toString.call(param) === "[object Object]";
|
|
616
|
+
}, info || ((k) => `'${k}' should be an object`));
|
|
617
|
+
}
|
|
618
|
+
__name(isObject, "isObject");
|
|
619
|
+
function isMobile(info) {
|
|
620
|
+
return Rule(/^((\+|00)86)?1((3[\d])|(4[5,6,7,9])|(5[0-3,5-9])|(6[5-7])|(7[0-8])|(8[\d])|(9[1,8,9]))\d{8}$/, info || ((k) => `'${k}' should be a mobile phone number`));
|
|
621
|
+
}
|
|
622
|
+
__name(isMobile, "isMobile");
|
|
623
|
+
function isLandline(info) {
|
|
624
|
+
return Rule(/\d{3}-\d{8}|\d{4}-\d{7}/, info || ((k) => `'${k}' should be a landline`));
|
|
625
|
+
}
|
|
626
|
+
__name(isLandline, "isLandline");
|
|
627
|
+
function isMailBox(info) {
|
|
628
|
+
return Rule(/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/, info || ((k) => `'${k}' should be a mailbox`));
|
|
629
|
+
}
|
|
630
|
+
__name(isMailBox, "isMailBox");
|
|
631
|
+
function isIdCard(info) {
|
|
632
|
+
return Rule(/(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/, info || ((k) => `'${k}' should be an identity card number`));
|
|
633
|
+
}
|
|
634
|
+
__name(isIdCard, "isIdCard");
|
|
635
|
+
function isCnName(info) {
|
|
636
|
+
return Rule(/^([\u4E00-\u9FA5·]{2,16})$/, info || ((k) => `'${k}' \u9700\u8981\u662F\u4E00\u4E2A\u5408\u7406\u7684\u4E2D\u6587\u540D\u5B57`));
|
|
637
|
+
}
|
|
638
|
+
__name(isCnName, "isCnName");
|
|
639
|
+
function isEnName(info) {
|
|
640
|
+
return Rule(/(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/, info || ((k) => `'${k}' should be a valid en-name`));
|
|
641
|
+
}
|
|
642
|
+
__name(isEnName, "isEnName");
|
|
643
|
+
function isDate(info) {
|
|
644
|
+
return Rule(/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/, info || ((k) => `'${k}' should be a valid date`));
|
|
645
|
+
}
|
|
646
|
+
__name(isDate, "isDate");
|
|
647
|
+
function isWechat(info) {
|
|
648
|
+
return Rule(/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/, info || ((k) => `'${k}' should be a valid wechat`));
|
|
649
|
+
}
|
|
650
|
+
__name(isWechat, "isWechat");
|
|
651
|
+
function isHexColor(info) {
|
|
652
|
+
return Rule(/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/, info || ((k) => `'${k}' should be a valid hex-color`));
|
|
653
|
+
}
|
|
654
|
+
__name(isHexColor, "isHexColor");
|
|
655
|
+
function isPostalCode(info) {
|
|
656
|
+
return Rule(/^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/, info || ((k) => `'${k}' should be a valid postal code`));
|
|
657
|
+
}
|
|
658
|
+
__name(isPostalCode, "isPostalCode");
|
|
659
|
+
|
|
660
|
+
// src/preset/pipe.ts
|
|
661
|
+
function toNumber() {
|
|
662
|
+
return Pipe(to((param) => Number(param)));
|
|
663
|
+
}
|
|
664
|
+
__name(toNumber, "toNumber");
|
|
665
|
+
function toString() {
|
|
666
|
+
return Pipe(to((param) => String(param)));
|
|
667
|
+
}
|
|
668
|
+
__name(toString, "toString");
|
|
567
669
|
// Annotate the CommonJS export names for ESM import in node:
|
|
568
670
|
0 && (module.exports = {
|
|
569
671
|
Assign,
|
|
@@ -603,7 +705,23 @@ __name(Storage, "Storage");
|
|
|
603
705
|
getTag,
|
|
604
706
|
init,
|
|
605
707
|
injectProperty,
|
|
708
|
+
isArray,
|
|
709
|
+
isBoolean,
|
|
710
|
+
isCnName,
|
|
711
|
+
isDate,
|
|
712
|
+
isEnName,
|
|
713
|
+
isHexColor,
|
|
714
|
+
isIdCard,
|
|
715
|
+
isLandline,
|
|
716
|
+
isMailBox,
|
|
717
|
+
isMobile,
|
|
718
|
+
isNumber,
|
|
719
|
+
isObject,
|
|
720
|
+
isOption,
|
|
606
721
|
isPhecda,
|
|
722
|
+
isPostalCode,
|
|
723
|
+
isString,
|
|
724
|
+
isWechat,
|
|
607
725
|
plainToClass,
|
|
608
726
|
regisHandler,
|
|
609
727
|
regisInitEvent,
|
|
@@ -615,5 +733,7 @@ __name(Storage, "Storage");
|
|
|
615
733
|
setState,
|
|
616
734
|
snapShot,
|
|
617
735
|
to,
|
|
736
|
+
toNumber,
|
|
737
|
+
toString,
|
|
618
738
|
validate
|
|
619
739
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -338,7 +338,10 @@ async function plainToClass(Model, input, options = {}) {
|
|
|
338
338
|
if (options.collectError !== false) {
|
|
339
339
|
for (const handler of handlers) {
|
|
340
340
|
const rule = handler.rule;
|
|
341
|
-
|
|
341
|
+
const ret = await validate(rule, data[item]);
|
|
342
|
+
if (ret === "ok")
|
|
343
|
+
break;
|
|
344
|
+
if (rule && !ret) {
|
|
342
345
|
err.push(typeof handler.info === "function" ? handler.info(item) : handler.info);
|
|
343
346
|
if (!options.collectError)
|
|
344
347
|
break;
|
|
@@ -491,6 +494,87 @@ function Storage(storeKey) {
|
|
|
491
494
|
};
|
|
492
495
|
}
|
|
493
496
|
__name(Storage, "Storage");
|
|
497
|
+
|
|
498
|
+
// src/preset/rule.ts
|
|
499
|
+
function isOption() {
|
|
500
|
+
return Rule((param) => param === void 0 ? "ok" : true, "");
|
|
501
|
+
}
|
|
502
|
+
__name(isOption, "isOption");
|
|
503
|
+
function isArray(info) {
|
|
504
|
+
return Rule((param) => Array.isArray(param), info || ((k) => `'${k}' should be an array`));
|
|
505
|
+
}
|
|
506
|
+
__name(isArray, "isArray");
|
|
507
|
+
function isBoolean(info) {
|
|
508
|
+
return Rule((param) => [
|
|
509
|
+
true,
|
|
510
|
+
false
|
|
511
|
+
].includes(param), info || ((k) => `'${k}' should be boolean`));
|
|
512
|
+
}
|
|
513
|
+
__name(isBoolean, "isBoolean");
|
|
514
|
+
function isNumber(info) {
|
|
515
|
+
return Rule((param) => typeof param === "number", info || ((k) => `'${k}' should be number`));
|
|
516
|
+
}
|
|
517
|
+
__name(isNumber, "isNumber");
|
|
518
|
+
function isString(info) {
|
|
519
|
+
return Rule((param) => typeof param === "string", info || ((k) => `'${k}' should be a string`));
|
|
520
|
+
}
|
|
521
|
+
__name(isString, "isString");
|
|
522
|
+
function isObject(info) {
|
|
523
|
+
return Rule((param) => {
|
|
524
|
+
return Object.prototype.toString.call(param) === "[object Object]";
|
|
525
|
+
}, info || ((k) => `'${k}' should be an object`));
|
|
526
|
+
}
|
|
527
|
+
__name(isObject, "isObject");
|
|
528
|
+
function isMobile(info) {
|
|
529
|
+
return Rule(/^((\+|00)86)?1((3[\d])|(4[5,6,7,9])|(5[0-3,5-9])|(6[5-7])|(7[0-8])|(8[\d])|(9[1,8,9]))\d{8}$/, info || ((k) => `'${k}' should be a mobile phone number`));
|
|
530
|
+
}
|
|
531
|
+
__name(isMobile, "isMobile");
|
|
532
|
+
function isLandline(info) {
|
|
533
|
+
return Rule(/\d{3}-\d{8}|\d{4}-\d{7}/, info || ((k) => `'${k}' should be a landline`));
|
|
534
|
+
}
|
|
535
|
+
__name(isLandline, "isLandline");
|
|
536
|
+
function isMailBox(info) {
|
|
537
|
+
return Rule(/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/, info || ((k) => `'${k}' should be a mailbox`));
|
|
538
|
+
}
|
|
539
|
+
__name(isMailBox, "isMailBox");
|
|
540
|
+
function isIdCard(info) {
|
|
541
|
+
return Rule(/(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/, info || ((k) => `'${k}' should be an identity card number`));
|
|
542
|
+
}
|
|
543
|
+
__name(isIdCard, "isIdCard");
|
|
544
|
+
function isCnName(info) {
|
|
545
|
+
return Rule(/^([\u4E00-\u9FA5·]{2,16})$/, info || ((k) => `'${k}' \u9700\u8981\u662F\u4E00\u4E2A\u5408\u7406\u7684\u4E2D\u6587\u540D\u5B57`));
|
|
546
|
+
}
|
|
547
|
+
__name(isCnName, "isCnName");
|
|
548
|
+
function isEnName(info) {
|
|
549
|
+
return Rule(/(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/, info || ((k) => `'${k}' should be a valid en-name`));
|
|
550
|
+
}
|
|
551
|
+
__name(isEnName, "isEnName");
|
|
552
|
+
function isDate(info) {
|
|
553
|
+
return Rule(/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/, info || ((k) => `'${k}' should be a valid date`));
|
|
554
|
+
}
|
|
555
|
+
__name(isDate, "isDate");
|
|
556
|
+
function isWechat(info) {
|
|
557
|
+
return Rule(/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/, info || ((k) => `'${k}' should be a valid wechat`));
|
|
558
|
+
}
|
|
559
|
+
__name(isWechat, "isWechat");
|
|
560
|
+
function isHexColor(info) {
|
|
561
|
+
return Rule(/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/, info || ((k) => `'${k}' should be a valid hex-color`));
|
|
562
|
+
}
|
|
563
|
+
__name(isHexColor, "isHexColor");
|
|
564
|
+
function isPostalCode(info) {
|
|
565
|
+
return Rule(/^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/, info || ((k) => `'${k}' should be a valid postal code`));
|
|
566
|
+
}
|
|
567
|
+
__name(isPostalCode, "isPostalCode");
|
|
568
|
+
|
|
569
|
+
// src/preset/pipe.ts
|
|
570
|
+
function toNumber() {
|
|
571
|
+
return Pipe(to((param) => Number(param)));
|
|
572
|
+
}
|
|
573
|
+
__name(toNumber, "toNumber");
|
|
574
|
+
function toString() {
|
|
575
|
+
return Pipe(to((param) => String(param)));
|
|
576
|
+
}
|
|
577
|
+
__name(toString, "toString");
|
|
494
578
|
export {
|
|
495
579
|
Assign,
|
|
496
580
|
Bind,
|
|
@@ -529,7 +613,23 @@ export {
|
|
|
529
613
|
getTag,
|
|
530
614
|
init,
|
|
531
615
|
injectProperty,
|
|
616
|
+
isArray,
|
|
617
|
+
isBoolean,
|
|
618
|
+
isCnName,
|
|
619
|
+
isDate,
|
|
620
|
+
isEnName,
|
|
621
|
+
isHexColor,
|
|
622
|
+
isIdCard,
|
|
623
|
+
isLandline,
|
|
624
|
+
isMailBox,
|
|
625
|
+
isMobile,
|
|
626
|
+
isNumber,
|
|
627
|
+
isObject,
|
|
628
|
+
isOption,
|
|
532
629
|
isPhecda,
|
|
630
|
+
isPostalCode,
|
|
631
|
+
isString,
|
|
632
|
+
isWechat,
|
|
533
633
|
plainToClass,
|
|
534
634
|
regisHandler,
|
|
535
635
|
regisInitEvent,
|
|
@@ -541,5 +641,7 @@ export {
|
|
|
541
641
|
setState,
|
|
542
642
|
snapShot,
|
|
543
643
|
to,
|
|
644
|
+
toNumber,
|
|
645
|
+
toString,
|
|
544
646
|
validate
|
|
545
647
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare function isOption(): (obj: any, key: PropertyKey) => void;
|
|
2
|
+
declare function isArray(info?: string): (obj: any, key: PropertyKey) => void;
|
|
3
|
+
declare function isBoolean(info?: string): (obj: any, key: PropertyKey) => void;
|
|
4
|
+
declare function isNumber(info?: string): (obj: any, key: PropertyKey) => void;
|
|
5
|
+
declare function isString(info?: string): (obj: any, key: PropertyKey) => void;
|
|
6
|
+
declare function isObject(info?: string): (obj: any, key: PropertyKey) => void;
|
|
7
|
+
declare function isMobile(info?: string): (obj: any, key: PropertyKey) => void;
|
|
8
|
+
declare function isLandline(info?: string): (obj: any, key: PropertyKey) => void;
|
|
9
|
+
declare function isMailBox(info?: string): (obj: any, key: PropertyKey) => void;
|
|
10
|
+
declare function isIdCard(info?: string): (obj: any, key: PropertyKey) => void;
|
|
11
|
+
declare function isCnName(info?: string): (obj: any, key: PropertyKey) => void;
|
|
12
|
+
declare function isEnName(info?: string): (obj: any, key: PropertyKey) => void;
|
|
13
|
+
declare function isDate(info?: string): (obj: any, key: PropertyKey) => void;
|
|
14
|
+
declare function isWechat(info?: string): (obj: any, key: PropertyKey) => void;
|
|
15
|
+
declare function isHexColor(info?: string): (obj: any, key: PropertyKey) => void;
|
|
16
|
+
declare function isPostalCode(info?: string): (obj: any, key: PropertyKey) => void;
|
|
17
|
+
|
|
18
|
+
declare function toNumber(): (obj: any, key: PropertyKey) => void;
|
|
19
|
+
declare function toString(): (obj: any, key: PropertyKey) => void;
|
|
20
|
+
|
|
21
|
+
export { isArray as a, isBoolean as b, isNumber as c, isString as d, isObject as e, isMobile as f, isLandline as g, isMailBox as h, isOption as i, isIdCard as j, isCnName as k, isEnName as l, isDate as m, isWechat as n, isHexColor as o, isPostalCode as p, toString as q, toNumber as t };
|
package/dist/preset/index.d.ts
CHANGED
|
@@ -1,20 +1 @@
|
|
|
1
|
-
|
|
2
|
-
declare function isBoolean(info?: string): (obj: any, key: PropertyKey) => void;
|
|
3
|
-
declare function isNumber(info?: string): (obj: any, key: PropertyKey) => void;
|
|
4
|
-
declare function isString(info?: string): (obj: any, key: PropertyKey) => void;
|
|
5
|
-
declare function isObject(info?: string): (obj: any, key: PropertyKey) => void;
|
|
6
|
-
declare function isMobile(info?: string): (obj: any, key: PropertyKey) => void;
|
|
7
|
-
declare function isLandline(info?: string): (obj: any, key: PropertyKey) => void;
|
|
8
|
-
declare function isMailBox(info?: string): (obj: any, key: PropertyKey) => void;
|
|
9
|
-
declare function isIdCard(info?: string): (obj: any, key: PropertyKey) => void;
|
|
10
|
-
declare function isCnName(info?: string): (obj: any, key: PropertyKey) => void;
|
|
11
|
-
declare function isEnName(info?: string): (obj: any, key: PropertyKey) => void;
|
|
12
|
-
declare function isDate(info?: string): (obj: any, key: PropertyKey) => void;
|
|
13
|
-
declare function isWechat(info?: string): (obj: any, key: PropertyKey) => void;
|
|
14
|
-
declare function isHexColor(info?: string): (obj: any, key: PropertyKey) => void;
|
|
15
|
-
declare function isPostalCode(info?: string): (obj: any, key: PropertyKey) => void;
|
|
16
|
-
|
|
17
|
-
declare function toNumber(): (obj: any, key: PropertyKey) => void;
|
|
18
|
-
declare function toString(): (obj: any, key: PropertyKey) => void;
|
|
19
|
-
|
|
20
|
-
export { isArray, isBoolean, isCnName, isDate, isEnName, isHexColor, isIdCard, isLandline, isMailBox, isMobile, isNumber, isObject, isPostalCode, isString, isWechat, toNumber, toString };
|
|
1
|
+
export { a as isArray, b as isBoolean, k as isCnName, m as isDate, l as isEnName, o as isHexColor, j as isIdCard, g as isLandline, h as isMailBox, f as isMobile, c as isNumber, e as isObject, i as isOption, p as isPostalCode, d as isString, n as isWechat, t as toNumber, q as toString } from '../pipe-5d060247.js';
|
|
@@ -34,6 +34,7 @@ var Phecda = (() => {
|
|
|
34
34
|
isMobile: () => isMobile,
|
|
35
35
|
isNumber: () => isNumber,
|
|
36
36
|
isObject: () => isObject,
|
|
37
|
+
isOption: () => isOption,
|
|
37
38
|
isPostalCode: () => isPostalCode,
|
|
38
39
|
isString: () => isString,
|
|
39
40
|
isWechat: () => isWechat,
|
|
@@ -106,69 +107,73 @@ var Phecda = (() => {
|
|
|
106
107
|
__name(Pipe, "Pipe");
|
|
107
108
|
|
|
108
109
|
// src/preset/rule.ts
|
|
110
|
+
function isOption() {
|
|
111
|
+
return Rule((param) => param === void 0 ? "ok" : true, "");
|
|
112
|
+
}
|
|
113
|
+
__name(isOption, "isOption");
|
|
109
114
|
function isArray(info) {
|
|
110
|
-
return Rule((param) => Array.isArray(param), info ||
|
|
115
|
+
return Rule((param) => Array.isArray(param), info || ((k) => `'${k}' should be an array`));
|
|
111
116
|
}
|
|
112
117
|
__name(isArray, "isArray");
|
|
113
118
|
function isBoolean(info) {
|
|
114
119
|
return Rule((param) => [
|
|
115
120
|
true,
|
|
116
121
|
false
|
|
117
|
-
].includes(param), info ||
|
|
122
|
+
].includes(param), info || ((k) => `'${k}' should be boolean`));
|
|
118
123
|
}
|
|
119
124
|
__name(isBoolean, "isBoolean");
|
|
120
125
|
function isNumber(info) {
|
|
121
|
-
return Rule((param) => typeof param === "number", info ||
|
|
126
|
+
return Rule((param) => typeof param === "number", info || ((k) => `'${k}' should be number`));
|
|
122
127
|
}
|
|
123
128
|
__name(isNumber, "isNumber");
|
|
124
129
|
function isString(info) {
|
|
125
|
-
return Rule((param) => typeof param === "string", info ||
|
|
130
|
+
return Rule((param) => typeof param === "string", info || ((k) => `'${k}' should be a string`));
|
|
126
131
|
}
|
|
127
132
|
__name(isString, "isString");
|
|
128
133
|
function isObject(info) {
|
|
129
134
|
return Rule((param) => {
|
|
130
135
|
return Object.prototype.toString.call(param) === "[object Object]";
|
|
131
|
-
}, info ||
|
|
136
|
+
}, info || ((k) => `'${k}' should be an object`));
|
|
132
137
|
}
|
|
133
138
|
__name(isObject, "isObject");
|
|
134
139
|
function isMobile(info) {
|
|
135
|
-
return Rule(/^((\+|00)86)?1((3[\d])|(4[5,6,7,9])|(5[0-3,5-9])|(6[5-7])|(7[0-8])|(8[\d])|(9[1,8,9]))\d{8}$/, info ||
|
|
140
|
+
return Rule(/^((\+|00)86)?1((3[\d])|(4[5,6,7,9])|(5[0-3,5-9])|(6[5-7])|(7[0-8])|(8[\d])|(9[1,8,9]))\d{8}$/, info || ((k) => `'${k}' should be a mobile phone number`));
|
|
136
141
|
}
|
|
137
142
|
__name(isMobile, "isMobile");
|
|
138
143
|
function isLandline(info) {
|
|
139
|
-
return Rule(/\d{3}-\d{8}|\d{4}-\d{7}/, info ||
|
|
144
|
+
return Rule(/\d{3}-\d{8}|\d{4}-\d{7}/, info || ((k) => `'${k}' should be a landline`));
|
|
140
145
|
}
|
|
141
146
|
__name(isLandline, "isLandline");
|
|
142
147
|
function isMailBox(info) {
|
|
143
|
-
return Rule(/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/, info ||
|
|
148
|
+
return Rule(/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/, info || ((k) => `'${k}' should be a mailbox`));
|
|
144
149
|
}
|
|
145
150
|
__name(isMailBox, "isMailBox");
|
|
146
151
|
function isIdCard(info) {
|
|
147
|
-
return Rule(/(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/, info ||
|
|
152
|
+
return Rule(/(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/, info || ((k) => `'${k}' should be an identity card number`));
|
|
148
153
|
}
|
|
149
154
|
__name(isIdCard, "isIdCard");
|
|
150
155
|
function isCnName(info) {
|
|
151
|
-
return Rule(/^([\u4E00-\u9FA5·]{2,16})$/, info ||
|
|
156
|
+
return Rule(/^([\u4E00-\u9FA5·]{2,16})$/, info || ((k) => `'${k}' \u9700\u8981\u662F\u4E00\u4E2A\u5408\u7406\u7684\u4E2D\u6587\u540D\u5B57`));
|
|
152
157
|
}
|
|
153
158
|
__name(isCnName, "isCnName");
|
|
154
159
|
function isEnName(info) {
|
|
155
|
-
return Rule(/(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/, info ||
|
|
160
|
+
return Rule(/(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/, info || ((k) => `'${k}' should be a valid en-name`));
|
|
156
161
|
}
|
|
157
162
|
__name(isEnName, "isEnName");
|
|
158
163
|
function isDate(info) {
|
|
159
|
-
return Rule(/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/, info ||
|
|
164
|
+
return Rule(/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/, info || ((k) => `'${k}' should be a valid date`));
|
|
160
165
|
}
|
|
161
166
|
__name(isDate, "isDate");
|
|
162
167
|
function isWechat(info) {
|
|
163
|
-
return Rule(/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/, info ||
|
|
168
|
+
return Rule(/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/, info || ((k) => `'${k}' should be a valid wechat`));
|
|
164
169
|
}
|
|
165
170
|
__name(isWechat, "isWechat");
|
|
166
171
|
function isHexColor(info) {
|
|
167
|
-
return Rule(/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/, info ||
|
|
172
|
+
return Rule(/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/, info || ((k) => `'${k}' should be a valid hex-color`));
|
|
168
173
|
}
|
|
169
174
|
__name(isHexColor, "isHexColor");
|
|
170
175
|
function isPostalCode(info) {
|
|
171
|
-
return Rule(/^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/, info ||
|
|
176
|
+
return Rule(/^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/, info || ((k) => `'${k}' should be a valid postal code`));
|
|
172
177
|
}
|
|
173
178
|
__name(isPostalCode, "isPostalCode");
|
|
174
179
|
|
package/dist/preset/index.js
CHANGED
|
@@ -33,6 +33,7 @@ __export(preset_exports, {
|
|
|
33
33
|
isMobile: () => isMobile,
|
|
34
34
|
isNumber: () => isNumber,
|
|
35
35
|
isObject: () => isObject,
|
|
36
|
+
isOption: () => isOption,
|
|
36
37
|
isPostalCode: () => isPostalCode,
|
|
37
38
|
isString: () => isString,
|
|
38
39
|
isWechat: () => isWechat,
|
|
@@ -106,69 +107,73 @@ function Pipe(v) {
|
|
|
106
107
|
__name(Pipe, "Pipe");
|
|
107
108
|
|
|
108
109
|
// src/preset/rule.ts
|
|
110
|
+
function isOption() {
|
|
111
|
+
return Rule((param) => param === void 0 ? "ok" : true, "");
|
|
112
|
+
}
|
|
113
|
+
__name(isOption, "isOption");
|
|
109
114
|
function isArray(info) {
|
|
110
|
-
return Rule((param) => Array.isArray(param), info ||
|
|
115
|
+
return Rule((param) => Array.isArray(param), info || ((k) => `'${k}' should be an array`));
|
|
111
116
|
}
|
|
112
117
|
__name(isArray, "isArray");
|
|
113
118
|
function isBoolean(info) {
|
|
114
119
|
return Rule((param) => [
|
|
115
120
|
true,
|
|
116
121
|
false
|
|
117
|
-
].includes(param), info ||
|
|
122
|
+
].includes(param), info || ((k) => `'${k}' should be boolean`));
|
|
118
123
|
}
|
|
119
124
|
__name(isBoolean, "isBoolean");
|
|
120
125
|
function isNumber(info) {
|
|
121
|
-
return Rule((param) => typeof param === "number", info ||
|
|
126
|
+
return Rule((param) => typeof param === "number", info || ((k) => `'${k}' should be number`));
|
|
122
127
|
}
|
|
123
128
|
__name(isNumber, "isNumber");
|
|
124
129
|
function isString(info) {
|
|
125
|
-
return Rule((param) => typeof param === "string", info ||
|
|
130
|
+
return Rule((param) => typeof param === "string", info || ((k) => `'${k}' should be a string`));
|
|
126
131
|
}
|
|
127
132
|
__name(isString, "isString");
|
|
128
133
|
function isObject(info) {
|
|
129
134
|
return Rule((param) => {
|
|
130
135
|
return Object.prototype.toString.call(param) === "[object Object]";
|
|
131
|
-
}, info ||
|
|
136
|
+
}, info || ((k) => `'${k}' should be an object`));
|
|
132
137
|
}
|
|
133
138
|
__name(isObject, "isObject");
|
|
134
139
|
function isMobile(info) {
|
|
135
|
-
return Rule(/^((\+|00)86)?1((3[\d])|(4[5,6,7,9])|(5[0-3,5-9])|(6[5-7])|(7[0-8])|(8[\d])|(9[1,8,9]))\d{8}$/, info ||
|
|
140
|
+
return Rule(/^((\+|00)86)?1((3[\d])|(4[5,6,7,9])|(5[0-3,5-9])|(6[5-7])|(7[0-8])|(8[\d])|(9[1,8,9]))\d{8}$/, info || ((k) => `'${k}' should be a mobile phone number`));
|
|
136
141
|
}
|
|
137
142
|
__name(isMobile, "isMobile");
|
|
138
143
|
function isLandline(info) {
|
|
139
|
-
return Rule(/\d{3}-\d{8}|\d{4}-\d{7}/, info ||
|
|
144
|
+
return Rule(/\d{3}-\d{8}|\d{4}-\d{7}/, info || ((k) => `'${k}' should be a landline`));
|
|
140
145
|
}
|
|
141
146
|
__name(isLandline, "isLandline");
|
|
142
147
|
function isMailBox(info) {
|
|
143
|
-
return Rule(/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/, info ||
|
|
148
|
+
return Rule(/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/, info || ((k) => `'${k}' should be a mailbox`));
|
|
144
149
|
}
|
|
145
150
|
__name(isMailBox, "isMailBox");
|
|
146
151
|
function isIdCard(info) {
|
|
147
|
-
return Rule(/(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/, info ||
|
|
152
|
+
return Rule(/(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/, info || ((k) => `'${k}' should be an identity card number`));
|
|
148
153
|
}
|
|
149
154
|
__name(isIdCard, "isIdCard");
|
|
150
155
|
function isCnName(info) {
|
|
151
|
-
return Rule(/^([\u4E00-\u9FA5·]{2,16})$/, info ||
|
|
156
|
+
return Rule(/^([\u4E00-\u9FA5·]{2,16})$/, info || ((k) => `'${k}' \u9700\u8981\u662F\u4E00\u4E2A\u5408\u7406\u7684\u4E2D\u6587\u540D\u5B57`));
|
|
152
157
|
}
|
|
153
158
|
__name(isCnName, "isCnName");
|
|
154
159
|
function isEnName(info) {
|
|
155
|
-
return Rule(/(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/, info ||
|
|
160
|
+
return Rule(/(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/, info || ((k) => `'${k}' should be a valid en-name`));
|
|
156
161
|
}
|
|
157
162
|
__name(isEnName, "isEnName");
|
|
158
163
|
function isDate(info) {
|
|
159
|
-
return Rule(/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/, info ||
|
|
164
|
+
return Rule(/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/, info || ((k) => `'${k}' should be a valid date`));
|
|
160
165
|
}
|
|
161
166
|
__name(isDate, "isDate");
|
|
162
167
|
function isWechat(info) {
|
|
163
|
-
return Rule(/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/, info ||
|
|
168
|
+
return Rule(/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/, info || ((k) => `'${k}' should be a valid wechat`));
|
|
164
169
|
}
|
|
165
170
|
__name(isWechat, "isWechat");
|
|
166
171
|
function isHexColor(info) {
|
|
167
|
-
return Rule(/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/, info ||
|
|
172
|
+
return Rule(/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/, info || ((k) => `'${k}' should be a valid hex-color`));
|
|
168
173
|
}
|
|
169
174
|
__name(isHexColor, "isHexColor");
|
|
170
175
|
function isPostalCode(info) {
|
|
171
|
-
return Rule(/^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/, info ||
|
|
176
|
+
return Rule(/^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/, info || ((k) => `'${k}' should be a valid postal code`));
|
|
172
177
|
}
|
|
173
178
|
__name(isPostalCode, "isPostalCode");
|
|
174
179
|
|
|
@@ -206,6 +211,7 @@ __name(toString, "toString");
|
|
|
206
211
|
isMobile,
|
|
207
212
|
isNumber,
|
|
208
213
|
isObject,
|
|
214
|
+
isOption,
|
|
209
215
|
isPostalCode,
|
|
210
216
|
isString,
|
|
211
217
|
isWechat,
|
package/dist/preset/index.mjs
CHANGED
|
@@ -66,69 +66,73 @@ function Pipe(v) {
|
|
|
66
66
|
__name(Pipe, "Pipe");
|
|
67
67
|
|
|
68
68
|
// src/preset/rule.ts
|
|
69
|
+
function isOption() {
|
|
70
|
+
return Rule((param) => param === void 0 ? "ok" : true, "");
|
|
71
|
+
}
|
|
72
|
+
__name(isOption, "isOption");
|
|
69
73
|
function isArray(info) {
|
|
70
|
-
return Rule((param) => Array.isArray(param), info ||
|
|
74
|
+
return Rule((param) => Array.isArray(param), info || ((k) => `'${k}' should be an array`));
|
|
71
75
|
}
|
|
72
76
|
__name(isArray, "isArray");
|
|
73
77
|
function isBoolean(info) {
|
|
74
78
|
return Rule((param) => [
|
|
75
79
|
true,
|
|
76
80
|
false
|
|
77
|
-
].includes(param), info ||
|
|
81
|
+
].includes(param), info || ((k) => `'${k}' should be boolean`));
|
|
78
82
|
}
|
|
79
83
|
__name(isBoolean, "isBoolean");
|
|
80
84
|
function isNumber(info) {
|
|
81
|
-
return Rule((param) => typeof param === "number", info ||
|
|
85
|
+
return Rule((param) => typeof param === "number", info || ((k) => `'${k}' should be number`));
|
|
82
86
|
}
|
|
83
87
|
__name(isNumber, "isNumber");
|
|
84
88
|
function isString(info) {
|
|
85
|
-
return Rule((param) => typeof param === "string", info ||
|
|
89
|
+
return Rule((param) => typeof param === "string", info || ((k) => `'${k}' should be a string`));
|
|
86
90
|
}
|
|
87
91
|
__name(isString, "isString");
|
|
88
92
|
function isObject(info) {
|
|
89
93
|
return Rule((param) => {
|
|
90
94
|
return Object.prototype.toString.call(param) === "[object Object]";
|
|
91
|
-
}, info ||
|
|
95
|
+
}, info || ((k) => `'${k}' should be an object`));
|
|
92
96
|
}
|
|
93
97
|
__name(isObject, "isObject");
|
|
94
98
|
function isMobile(info) {
|
|
95
|
-
return Rule(/^((\+|00)86)?1((3[\d])|(4[5,6,7,9])|(5[0-3,5-9])|(6[5-7])|(7[0-8])|(8[\d])|(9[1,8,9]))\d{8}$/, info ||
|
|
99
|
+
return Rule(/^((\+|00)86)?1((3[\d])|(4[5,6,7,9])|(5[0-3,5-9])|(6[5-7])|(7[0-8])|(8[\d])|(9[1,8,9]))\d{8}$/, info || ((k) => `'${k}' should be a mobile phone number`));
|
|
96
100
|
}
|
|
97
101
|
__name(isMobile, "isMobile");
|
|
98
102
|
function isLandline(info) {
|
|
99
|
-
return Rule(/\d{3}-\d{8}|\d{4}-\d{7}/, info ||
|
|
103
|
+
return Rule(/\d{3}-\d{8}|\d{4}-\d{7}/, info || ((k) => `'${k}' should be a landline`));
|
|
100
104
|
}
|
|
101
105
|
__name(isLandline, "isLandline");
|
|
102
106
|
function isMailBox(info) {
|
|
103
|
-
return Rule(/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/, info ||
|
|
107
|
+
return Rule(/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/, info || ((k) => `'${k}' should be a mailbox`));
|
|
104
108
|
}
|
|
105
109
|
__name(isMailBox, "isMailBox");
|
|
106
110
|
function isIdCard(info) {
|
|
107
|
-
return Rule(/(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/, info ||
|
|
111
|
+
return Rule(/(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/, info || ((k) => `'${k}' should be an identity card number`));
|
|
108
112
|
}
|
|
109
113
|
__name(isIdCard, "isIdCard");
|
|
110
114
|
function isCnName(info) {
|
|
111
|
-
return Rule(/^([\u4E00-\u9FA5·]{2,16})$/, info ||
|
|
115
|
+
return Rule(/^([\u4E00-\u9FA5·]{2,16})$/, info || ((k) => `'${k}' \u9700\u8981\u662F\u4E00\u4E2A\u5408\u7406\u7684\u4E2D\u6587\u540D\u5B57`));
|
|
112
116
|
}
|
|
113
117
|
__name(isCnName, "isCnName");
|
|
114
118
|
function isEnName(info) {
|
|
115
|
-
return Rule(/(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/, info ||
|
|
119
|
+
return Rule(/(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/, info || ((k) => `'${k}' should be a valid en-name`));
|
|
116
120
|
}
|
|
117
121
|
__name(isEnName, "isEnName");
|
|
118
122
|
function isDate(info) {
|
|
119
|
-
return Rule(/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/, info ||
|
|
123
|
+
return Rule(/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/, info || ((k) => `'${k}' should be a valid date`));
|
|
120
124
|
}
|
|
121
125
|
__name(isDate, "isDate");
|
|
122
126
|
function isWechat(info) {
|
|
123
|
-
return Rule(/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/, info ||
|
|
127
|
+
return Rule(/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/, info || ((k) => `'${k}' should be a valid wechat`));
|
|
124
128
|
}
|
|
125
129
|
__name(isWechat, "isWechat");
|
|
126
130
|
function isHexColor(info) {
|
|
127
|
-
return Rule(/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/, info ||
|
|
131
|
+
return Rule(/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/, info || ((k) => `'${k}' should be a valid hex-color`));
|
|
128
132
|
}
|
|
129
133
|
__name(isHexColor, "isHexColor");
|
|
130
134
|
function isPostalCode(info) {
|
|
131
|
-
return Rule(/^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/, info ||
|
|
135
|
+
return Rule(/^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/, info || ((k) => `'${k}' should be a valid postal code`));
|
|
132
136
|
}
|
|
133
137
|
__name(isPostalCode, "isPostalCode");
|
|
134
138
|
|
|
@@ -165,6 +169,7 @@ export {
|
|
|
165
169
|
isMobile,
|
|
166
170
|
isNumber,
|
|
167
171
|
isObject,
|
|
172
|
+
isOption,
|
|
168
173
|
isPostalCode,
|
|
169
174
|
isString,
|
|
170
175
|
isWechat,
|