validno 0.1.5 → 0.1.7

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.
@@ -67,7 +67,7 @@ const rulesFunctions = {
67
67
  lengthMinMax: (key, val, minMax) => {
68
68
  const [min, max] = minMax;
69
69
  return {
70
- result: _validations.lengthMin(val, min) && _validations.lengthMin(val, max),
70
+ result: _validations.lengthMin(val, min) && _validations.lengthMax(val, max),
71
71
  details: `Длина должна быть от ${min} до ${max} символов`
72
72
  };
73
73
  },
package/dist/checkType.js CHANGED
@@ -82,10 +82,12 @@ const checkType = (key, value, requirements, keyName = key) => {
82
82
  break;
83
83
  case Date:
84
84
  const isDate = isNotNull && value.constructor === Date;
85
+ const isValid = isDate && !isNaN(value.getTime());
86
+ const errorMsg = isValid ? getErrorDetails(keyName, requirements.type, value) : 'Дата невалидна';
85
87
  result.push({
86
88
  key: keyName,
87
- passed: isDate,
88
- details: isDate ? 'Passed' : getErrorDetails(keyName, requirements.type, value)
89
+ passed: isDate && isValid,
90
+ details: isDate && isValid ? 'Passed' : errorMsg
89
91
  });
90
92
  break;
91
93
  case Boolean:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "validno",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/checkRules.ts CHANGED
@@ -77,7 +77,7 @@ const rulesFunctions: any = {
77
77
  const [min, max] = minMax
78
78
 
79
79
  return {
80
- result: _validations.lengthMin(val, min) && _validations.lengthMin(val, max),
80
+ result: _validations.lengthMin(val, min) && _validations.lengthMax(val, max),
81
81
  details: `Длина должна быть от ${min} до ${max} символов`
82
82
  }
83
83
  },
package/src/checkType.ts CHANGED
@@ -95,11 +95,13 @@ const checkType = (key: string, value: any, requirements: TSchemaItem | TSchemaI
95
95
  break;
96
96
  case Date:
97
97
  const isDate = isNotNull && value.constructor === Date
98
+ const isValid = isDate && !isNaN(value.getTime())
99
+ const errorMsg = isValid ? getErrorDetails(keyName, requirements.type, value) : 'Дата невалидна'
98
100
 
99
101
  result.push({
100
102
  key: keyName,
101
- passed: isDate,
102
- details: isDate ? 'Passed' : getErrorDetails(keyName, requirements.type, value)
103
+ passed: isDate && isValid,
104
+ details: isDate && isValid ? 'Passed' : errorMsg
103
105
  })
104
106
  break;
105
107
  case Boolean: