phecda-core 2.0.0-alpha.2 → 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 CHANGED
@@ -1,4 +1,4 @@
1
- export { i as isArray, a as isBoolean, j as isCnName, l as isDate, k as isEnName, n as isHexColor, h as isIdCard, f as isLandline, g as isMailBox, e as isMobile, b as isNumber, d as isObject, o as isPostalCode, c as isString, m as isWechat, t as toNumber, p as toString } from './pipe-6da589ab.js';
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
2
 
3
3
  interface NameSpace {
4
4
  [name: string]: Phecda;
@@ -79,7 +79,7 @@ declare function addDecoToClass<M extends new (...args: any) => any>(c: M, key:
79
79
 
80
80
  declare function Init(target: any, key: PropertyKey): void;
81
81
  declare function Bind(value: any): (target: any, k: PropertyKey) => void;
82
- declare function Rule(rule: RegExp | string | Function | number, info: string | ((k: string) => string), meta?: any): (obj: any, key: PropertyKey) => void;
82
+ declare function Rule(rule: RegExp | string | ((arg: any) => boolean | 'ok') | number, info: string | ((k: string) => string), meta?: any): (obj: any, key: PropertyKey) => void;
83
83
  declare function Ignore(target: any, key: PropertyKey): void;
84
84
  declare function Clear(target: any, key: PropertyKey): void;
85
85
  declare function Err<Fn extends (...args: any) => any>(cb: Fn): (target: any, key: PropertyKey) => void;
@@ -71,6 +71,7 @@ var Phecda = (() => {
71
71
  isMobile: () => isMobile,
72
72
  isNumber: () => isNumber,
73
73
  isObject: () => isObject,
74
+ isOption: () => isOption,
74
75
  isPhecda: () => isPhecda,
75
76
  isPostalCode: () => isPostalCode,
76
77
  isString: () => isString,
@@ -428,7 +429,10 @@ var Phecda = (() => {
428
429
  if (options.collectError !== false) {
429
430
  for (const handler of handlers) {
430
431
  const rule = handler.rule;
431
- if (rule && !await validate(rule, data[item])) {
432
+ const ret = await validate(rule, data[item]);
433
+ if (ret === "ok")
434
+ break;
435
+ if (rule && !ret) {
432
436
  err.push(typeof handler.info === "function" ? handler.info(item) : handler.info);
433
437
  if (!options.collectError)
434
438
  break;
@@ -583,6 +587,10 @@ var Phecda = (() => {
583
587
  __name(Storage, "Storage");
584
588
 
585
589
  // src/preset/rule.ts
590
+ function isOption() {
591
+ return Rule((param) => param === void 0 ? "ok" : true, "");
592
+ }
593
+ __name(isOption, "isOption");
586
594
  function isArray(info) {
587
595
  return Rule((param) => Array.isArray(param), info || ((k) => `'${k}' should be an array`));
588
596
  }
package/dist/index.js CHANGED
@@ -70,6 +70,7 @@ __export(src_exports, {
70
70
  isMobile: () => isMobile,
71
71
  isNumber: () => isNumber,
72
72
  isObject: () => isObject,
73
+ isOption: () => isOption,
73
74
  isPhecda: () => isPhecda,
74
75
  isPostalCode: () => isPostalCode,
75
76
  isString: () => isString,
@@ -428,7 +429,10 @@ async function plainToClass(Model, input, options = {}) {
428
429
  if (options.collectError !== false) {
429
430
  for (const handler of handlers) {
430
431
  const rule = handler.rule;
431
- if (rule && !await validate(rule, data[item])) {
432
+ const ret = await validate(rule, data[item]);
433
+ if (ret === "ok")
434
+ break;
435
+ if (rule && !ret) {
432
436
  err.push(typeof handler.info === "function" ? handler.info(item) : handler.info);
433
437
  if (!options.collectError)
434
438
  break;
@@ -583,6 +587,10 @@ function Storage(storeKey) {
583
587
  __name(Storage, "Storage");
584
588
 
585
589
  // src/preset/rule.ts
590
+ function isOption() {
591
+ return Rule((param) => param === void 0 ? "ok" : true, "");
592
+ }
593
+ __name(isOption, "isOption");
586
594
  function isArray(info) {
587
595
  return Rule((param) => Array.isArray(param), info || ((k) => `'${k}' should be an array`));
588
596
  }
@@ -709,6 +717,7 @@ __name(toString, "toString");
709
717
  isMobile,
710
718
  isNumber,
711
719
  isObject,
720
+ isOption,
712
721
  isPhecda,
713
722
  isPostalCode,
714
723
  isString,
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
- if (rule && !await validate(rule, data[item])) {
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;
@@ -493,6 +496,10 @@ function Storage(storeKey) {
493
496
  __name(Storage, "Storage");
494
497
 
495
498
  // src/preset/rule.ts
499
+ function isOption() {
500
+ return Rule((param) => param === void 0 ? "ok" : true, "");
501
+ }
502
+ __name(isOption, "isOption");
496
503
  function isArray(info) {
497
504
  return Rule((param) => Array.isArray(param), info || ((k) => `'${k}' should be an array`));
498
505
  }
@@ -618,6 +625,7 @@ export {
618
625
  isMobile,
619
626
  isNumber,
620
627
  isObject,
628
+ isOption,
621
629
  isPhecda,
622
630
  isPostalCode,
623
631
  isString,
@@ -1,3 +1,4 @@
1
+ declare function isOption(): (obj: any, key: PropertyKey) => void;
1
2
  declare function isArray(info?: string): (obj: any, key: PropertyKey) => void;
2
3
  declare function isBoolean(info?: string): (obj: any, key: PropertyKey) => void;
3
4
  declare function isNumber(info?: string): (obj: any, key: PropertyKey) => void;
@@ -17,4 +18,4 @@ declare function isPostalCode(info?: string): (obj: any, key: PropertyKey) => vo
17
18
  declare function toNumber(): (obj: any, key: PropertyKey) => void;
18
19
  declare function toString(): (obj: any, key: PropertyKey) => void;
19
20
 
20
- export { isBoolean as a, isNumber as b, isString as c, isObject as d, isMobile as e, isLandline as f, isMailBox as g, isIdCard as h, isArray as i, isCnName as j, isEnName as k, isDate as l, isWechat as m, isHexColor as n, isPostalCode as o, toString as p, toNumber as t };
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 };
@@ -1 +1 @@
1
- export { i as isArray, a as isBoolean, j as isCnName, l as isDate, k as isEnName, n as isHexColor, h as isIdCard, f as isLandline, g as isMailBox, e as isMobile, b as isNumber, d as isObject, o as isPostalCode, c as isString, m as isWechat, t as toNumber, p as toString } from '../pipe-6da589ab.js';
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,6 +107,10 @@ 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
115
  return Rule((param) => Array.isArray(param), info || ((k) => `'${k}' should be an array`));
111
116
  }
@@ -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,6 +107,10 @@ 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
115
  return Rule((param) => Array.isArray(param), info || ((k) => `'${k}' should be an array`));
111
116
  }
@@ -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,
@@ -66,6 +66,10 @@ 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
74
  return Rule((param) => Array.isArray(param), info || ((k) => `'${k}' should be an array`));
71
75
  }
@@ -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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-core",
3
- "version": "2.0.0-alpha.2",
3
+ "version": "2.0.0-alpha.3",
4
4
  "description": "provide base function and abstract limit to other phecda module ",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",