validno 0.4.5 → 0.4.6

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/dev.js CHANGED
@@ -119,3 +119,17 @@ const test = () => {
119
119
  console.log(validateResult);
120
120
  };
121
121
  test();
122
+ const schema = new Schema({
123
+ select: {
124
+ type: Array,
125
+ eachType: String,
126
+ required: true,
127
+ rules: {
128
+ lengthMin: 1
129
+ }
130
+ }
131
+ });
132
+ const result1 = schema.validate({ select: ['field1', 'field2'] });
133
+ console.log(result1);
134
+ const result2 = schema.validate({ select: [] });
135
+ console.log(result2);
@@ -1 +1 @@
1
- {"version":3,"file":"validateRules.d.ts","sourceRoot":"","sources":["../../../src/engine/methods/validateRules.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAGhD,OAAO,EAAe,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEtE,MAAM,WAAW,kBAAkB;IAC/B,OAAO,EAAE,aAAa,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,GAAG,CAAC;IACX,IAAI,EAAE,gBAAgB,CAAC;IACvB,IAAI,EAAE,GAAG,CAAC;IACV,YAAY,EAAE,OAAO,EAAE,CAAA;CAC1B;AAED,oBAAY,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAItC,eAAO,MAAM,WAAW;;;;CAIvB,CAAA;AAiND,iBAAS,aAAa,CAAC,KAAK,EAAE,kBAAkB,QAe/C;AAED,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"validateRules.d.ts","sourceRoot":"","sources":["../../../src/engine/methods/validateRules.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAGhD,OAAO,EAAe,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEtE,MAAM,WAAW,kBAAkB;IAC/B,OAAO,EAAE,aAAa,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,GAAG,CAAC;IACX,IAAI,EAAE,gBAAgB,CAAC;IACvB,IAAI,EAAE,GAAG,CAAC;IACV,YAAY,EAAE,OAAO,EAAE,CAAA;CAC1B;AAED,oBAAY,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAItC,eAAO,MAAM,WAAW;;;;CAIvB,CAAA;AAmND,iBAAS,aAAa,CAAC,KAAK,EAAE,kBAAkB,QAe/C;AAED,eAAe,aAAa,CAAC"}
@@ -70,33 +70,34 @@ const rulesFunctions = {
70
70
  length: (key, val, length) => {
71
71
  return {
72
72
  result: _validations.lengthIs(val, length),
73
- details: `Value must be equal to ${length}`
73
+ details: `Value length must be equal to ${length} ${Array.isArray(val) ? 'items' : 'characters'}`
74
74
  };
75
75
  },
76
76
  lengthNot: (key, val, lengthNot) => {
77
77
  return {
78
78
  result: _validations.lengthNot(val, lengthNot),
79
- details: `Value must not be equal to ${lengthNot}`
79
+ details: `Value must not be equal to ${lengthNot} ${Array.isArray(val) ? 'items' : 'characters'}`
80
80
  };
81
81
  },
82
82
  lengthMinMax: (key, val, minMax) => {
83
83
  const [min, max] = minMax;
84
84
  return {
85
85
  result: _validations.lengthMin(val, min) && _validations.lengthMax(val, max),
86
- details: `Value must be between ${min} and ${max} characters`
86
+ details: `Value must be between ${min} and ${max} ${Array.isArray(val) ? 'items' : 'characters'}`
87
87
  };
88
88
  },
89
89
  lengthMin: (key, val, min) => {
90
90
  ensureRuleHasCorrectType(val, rulesParams['lengthMin'].allowedTypes);
91
91
  return {
92
92
  result: _validations.lengthMin(val, min),
93
- details: `Value must be at least ${min} characters`
93
+ details: `Value must have at least ${min} ${Array.isArray(val) ? 'items' : 'characters'}`
94
94
  };
95
95
  },
96
96
  lengthMax: (key, val, max) => {
97
+ ensureRuleHasCorrectType(val, rulesParams['lengthMin'].allowedTypes);
97
98
  return {
98
99
  result: _validations.lengthMax(val, max),
99
- details: `Value must not be exceed ${max} characters`
100
+ details: `Value must not exceed ${max} ${Array.isArray(val) ? 'items' : 'characters'}`
100
101
  };
101
102
  },
102
103
  regex: (key, val, regex) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "validno",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "description": "A lightweight TypeScript validation library for runtime data validation. Used as part of Kodzero API framework.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",