ph-utils 0.2.16 → 0.2.17

Sign up to get free protection for your applications and to get access to all the features.
package/lib/validator.js CHANGED
@@ -56,9 +56,6 @@ class Validator {
56
56
  for (let schema of schemas) {
57
57
  // 解析规则
58
58
  let rules = [];
59
- if (schema.required === true) {
60
- rules.push(this._parseStringRule('required'));
61
- }
62
59
  let rule = schema.rules;
63
60
  if (typeof rule === 'string') {
64
61
  rules = rules.concat(this._parseStringRule(rule));
@@ -66,7 +63,7 @@ class Validator {
66
63
  else if (rule instanceof Array) {
67
64
  for (let ruleItem of rule) {
68
65
  if (typeof ruleItem === 'string') {
69
- rules = rules.concat(this._parseStringRule(ruleItem));
66
+ rules.push(...this._parseStringRule(ruleItem));
70
67
  }
71
68
  else if (ruleItem instanceof RegExp ||
72
69
  typeof ruleItem === 'function') {
@@ -74,7 +71,7 @@ class Validator {
74
71
  }
75
72
  else {
76
73
  if (typeof ruleItem.rule === 'string') {
77
- rules = rules.concat(this._parseStringRule(ruleItem.rule, ruleItem.message));
74
+ rules.push(...this._parseStringRule(ruleItem.rule, ruleItem.message));
78
75
  }
79
76
  else {
80
77
  rules.push({
@@ -88,6 +85,10 @@ class Validator {
88
85
  else {
89
86
  rules.push({ rule, message: defaultMsg });
90
87
  }
88
+ if (schema.required === true &&
89
+ rules.findIndex((r) => r.rule === 'required') === -1) {
90
+ rules.push(this._parseStringRule('required'));
91
+ }
91
92
  parsedRules[schema.key] = rules;
92
93
  }
93
94
  this.rules = parsedRules;
@@ -193,7 +194,7 @@ class Validator {
193
194
  }
194
195
  else if (rule === 'required') {
195
196
  rrule = 'required';
196
- message = defaultMsgs.required;
197
+ message = ruleErrMsg || defaultMsgs.required;
197
198
  }
198
199
  else if (Object.prototype.hasOwnProperty.call(ruleRegexs, r)) {
199
200
  rrule = ruleRegexs[r];
@@ -52,9 +52,6 @@ class Validator {
52
52
  for (let schema of schemas) {
53
53
  // 解析规则
54
54
  let rules = [];
55
- if (schema.required === true) {
56
- rules.push(this._parseStringRule('required'));
57
- }
58
55
  let rule = schema.rules;
59
56
  if (typeof rule === 'string') {
60
57
  rules = rules.concat(this._parseStringRule(rule));
@@ -62,7 +59,7 @@ class Validator {
62
59
  else if (rule instanceof Array) {
63
60
  for (let ruleItem of rule) {
64
61
  if (typeof ruleItem === 'string') {
65
- rules = rules.concat(this._parseStringRule(ruleItem));
62
+ rules.push(...this._parseStringRule(ruleItem));
66
63
  }
67
64
  else if (ruleItem instanceof RegExp ||
68
65
  typeof ruleItem === 'function') {
@@ -70,7 +67,7 @@ class Validator {
70
67
  }
71
68
  else {
72
69
  if (typeof ruleItem.rule === 'string') {
73
- rules = rules.concat(this._parseStringRule(ruleItem.rule, ruleItem.message));
70
+ rules.push(...this._parseStringRule(ruleItem.rule, ruleItem.message));
74
71
  }
75
72
  else {
76
73
  rules.push({
@@ -84,6 +81,10 @@ class Validator {
84
81
  else {
85
82
  rules.push({ rule, message: defaultMsg });
86
83
  }
84
+ if (schema.required === true &&
85
+ rules.findIndex((r) => r.rule === 'required') === -1) {
86
+ rules.push(this._parseStringRule('required'));
87
+ }
87
88
  parsedRules[schema.key] = rules;
88
89
  }
89
90
  this.rules = parsedRules;
@@ -189,7 +190,7 @@ class Validator {
189
190
  }
190
191
  else if (rule === 'required') {
191
192
  rrule = 'required';
192
- message = defaultMsgs.required;
193
+ message = ruleErrMsg || defaultMsgs.required;
193
194
  }
194
195
  else if (Object.prototype.hasOwnProperty.call(ruleRegexs, r)) {
195
196
  rrule = ruleRegexs[r];
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "module": "lib/index_m.js",
6
6
  "types": "lib/index.d.ts",
7
7
  "browser": "lib/index_m.js",
8
- "version": "0.2.16",
8
+ "version": "0.2.17",
9
9
  "repository": {
10
10
  "type": "git",
11
11
  "url": "git+https//gitee.com/towardly/ph.git",