validno 0.2.5 → 0.2.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/ValidnoResult.js +8 -1
- package/dist/constants/details.js +11 -6
- package/dist/dev.js +23 -44
- package/dist/utils/validateType.js +11 -0
- package/dist/utils/validations.js +1 -1
- package/dist/validate.js +11 -5
- package/dist/{checkRules.js → validateRules.js} +2 -2
- package/dist/validateType.js +124 -0
- package/package.json +1 -1
- package/dev.js +0 -0
- package/dist/checkType.js +0 -167
- package/dist/utils/nested.js +0 -1
package/dist/ValidnoResult.js
CHANGED
|
@@ -9,6 +9,10 @@ class ValidnoResult {
|
|
|
9
9
|
this.byKeys = (results === null || results === void 0 ? void 0 : results.byKeys) || {};
|
|
10
10
|
this.errorsByKeys = (results === null || results === void 0 ? void 0 : results.errorsByKeys) || {};
|
|
11
11
|
}
|
|
12
|
+
setNoData() {
|
|
13
|
+
this.ok = false;
|
|
14
|
+
this.errors = ['Отсутствует объект для проверки'];
|
|
15
|
+
}
|
|
12
16
|
setKeyStatus(key, result) {
|
|
13
17
|
this.byKeys[key] = result;
|
|
14
18
|
}
|
|
@@ -68,7 +72,7 @@ class ValidnoResult {
|
|
|
68
72
|
}
|
|
69
73
|
}
|
|
70
74
|
finish() {
|
|
71
|
-
if (this.failed.length)
|
|
75
|
+
if (this.failed.length || this.errors.length)
|
|
72
76
|
this.ok = false;
|
|
73
77
|
else
|
|
74
78
|
this.ok = true;
|
|
@@ -86,5 +90,8 @@ class ValidnoResult {
|
|
|
86
90
|
errorsByKeys: this.errorsByKeys,
|
|
87
91
|
};
|
|
88
92
|
}
|
|
93
|
+
isValid() {
|
|
94
|
+
return this.ok === true;
|
|
95
|
+
}
|
|
89
96
|
}
|
|
90
97
|
export default ValidnoResult;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
export var
|
|
2
|
-
(function (
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
})(
|
|
1
|
+
export var EValidationId;
|
|
2
|
+
(function (EValidationId) {
|
|
3
|
+
EValidationId["Missing"] = "missing";
|
|
4
|
+
EValidationId["Type"] = "type";
|
|
5
|
+
EValidationId["Rule"] = "rule";
|
|
6
|
+
})(EValidationId || (EValidationId = {}));
|
|
7
|
+
export var EValidationDetails;
|
|
8
|
+
(function (EValidationDetails) {
|
|
9
|
+
EValidationDetails["OK"] = "ok";
|
|
10
|
+
EValidationDetails["INVALID_DATE"] = "\u0414\u0430\u0442\u0430 \u043D\u0435\u0432\u0430\u043B\u0438\u0434\u043D\u0430";
|
|
11
|
+
})(EValidationDetails || (EValidationDetails = {}));
|
package/dist/dev.js
CHANGED
|
@@ -1,51 +1,30 @@
|
|
|
1
1
|
import { Schema } from "./Schema.js";
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type: String,
|
|
2
|
+
const testSchema = new Schema({
|
|
3
|
+
parent: {
|
|
4
|
+
collection: {
|
|
5
|
+
type: [String, Array],
|
|
6
6
|
required: true
|
|
7
|
-
},
|
|
8
|
-
str2: {
|
|
9
|
-
deep1: {
|
|
10
|
-
type: String,
|
|
11
|
-
required: true,
|
|
12
|
-
}
|
|
13
7
|
}
|
|
14
|
-
});
|
|
15
|
-
const res = cfgSchema.validate(cfg);
|
|
16
|
-
console.log(res);
|
|
17
|
-
};
|
|
18
|
-
const uniTestService = {
|
|
19
|
-
str1: 'xxxx'
|
|
20
|
-
};
|
|
21
|
-
validateConfig(uniTestService);
|
|
22
|
-
console.log(uniTestService);
|
|
23
|
-
console.log(uniTestService);
|
|
24
|
-
const obj = {
|
|
25
|
-
top: {
|
|
26
|
-
mid1: {
|
|
27
|
-
low1a: false,
|
|
28
|
-
low1b: false
|
|
29
|
-
},
|
|
30
|
-
mid2: {
|
|
31
|
-
low2a: false
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
top2: false
|
|
35
|
-
};
|
|
36
|
-
const setNestedValue = (linkedObj, keysLevels, curLevel, valueToSet) => {
|
|
37
|
-
const lvKey = keysLevels[curLevel];
|
|
38
|
-
if (curLevel < keysLevels.length - 1) {
|
|
39
|
-
if (!linkedObj[lvKey] || typeof linkedObj[lvKey] !== 'object') {
|
|
40
|
-
linkedObj[lvKey] = {};
|
|
41
|
-
}
|
|
42
|
-
return setNestedValue(linkedObj[lvKey], keysLevels, curLevel + 1, valueToSet);
|
|
43
8
|
}
|
|
44
|
-
|
|
45
|
-
|
|
9
|
+
});
|
|
10
|
+
const testObj = {
|
|
11
|
+
parent: {
|
|
12
|
+
collection: ['xxxx']
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const testObj2 = {
|
|
16
|
+
parent: {
|
|
17
|
+
collection: false
|
|
46
18
|
}
|
|
47
19
|
};
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
20
|
+
const testObj3 = {
|
|
21
|
+
parent: {
|
|
22
|
+
collection: 'str'
|
|
23
|
+
}
|
|
51
24
|
};
|
|
25
|
+
const res = testSchema.validate(testObj);
|
|
26
|
+
console.log(res.ok === true ? '#1 ✅' : '#1 ❌');
|
|
27
|
+
const res2 = testSchema.validate(testObj2);
|
|
28
|
+
console.log(res2.ok === false ? '#2 ✅' : '#2 ❌');
|
|
29
|
+
const res3 = testSchema.validate(testObj3);
|
|
30
|
+
console.log(res3.ok === true ? '#3 ✅' : '#3 ❌');
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EValidationDetails } from "../constants/details.js";
|
|
2
|
+
const _validateType = {
|
|
3
|
+
getResult: (key, passed, details = EValidationDetails.OK) => {
|
|
4
|
+
return {
|
|
5
|
+
key: key,
|
|
6
|
+
passed: passed,
|
|
7
|
+
details: details,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
export default _validateType;
|
|
@@ -32,7 +32,7 @@ _validations.isNullOrUndefined = (value) => {
|
|
|
32
32
|
return value === undefined || value === null;
|
|
33
33
|
};
|
|
34
34
|
_validations.isEmail = (value) => {
|
|
35
|
-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
35
|
+
const emailRegex = /^(?!.*\.\.)[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
36
36
|
return emailRegex.test(value);
|
|
37
37
|
};
|
|
38
38
|
_validations.isDateYYYYMMDD = (value) => {
|
package/dist/validate.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import checkType from "./
|
|
1
|
+
import checkType from "./validateType.js";
|
|
2
2
|
import _errors from "./utils/errors.js";
|
|
3
|
-
import checkRules from "./
|
|
3
|
+
import checkRules from "./validateRules.js";
|
|
4
4
|
import _helpers from "./utils/helpers.js";
|
|
5
|
-
import {
|
|
5
|
+
import { EValidationId } from "./constants/details.js";
|
|
6
6
|
import ValidnoResult from "./ValidnoResult.js";
|
|
7
7
|
function handleMissingKey(schema, input) {
|
|
8
8
|
const { key, nestedKey, data, reqs } = input;
|
|
@@ -12,7 +12,7 @@ function handleMissingKey(schema, input) {
|
|
|
12
12
|
return _errors.getMissingError(messageKey);
|
|
13
13
|
}
|
|
14
14
|
const errorMessage = reqs.customMessage({
|
|
15
|
-
keyword:
|
|
15
|
+
keyword: EValidationId.Missing,
|
|
16
16
|
value: data[key],
|
|
17
17
|
key: messageKey,
|
|
18
18
|
title: messageTitle,
|
|
@@ -41,6 +41,12 @@ function validateNestedKey(input) {
|
|
|
41
41
|
}
|
|
42
42
|
function validateKey(input) {
|
|
43
43
|
let { results, key, nestedKey, data, reqs } = input;
|
|
44
|
+
if (data === undefined) {
|
|
45
|
+
const noDataResult = new ValidnoResult();
|
|
46
|
+
noDataResult.setNoData();
|
|
47
|
+
noDataResult.finish();
|
|
48
|
+
return noDataResult;
|
|
49
|
+
}
|
|
44
50
|
if (!results)
|
|
45
51
|
results = new ValidnoResult();
|
|
46
52
|
if (!nestedKey)
|
|
@@ -89,7 +95,7 @@ function checkValueType(results, key, value, reqs, nestedKey, typeChecked) {
|
|
|
89
95
|
typeCheck.forEach((res) => {
|
|
90
96
|
if (!res.passed) {
|
|
91
97
|
typeChecked.push(false);
|
|
92
|
-
results.errors.push(res.details);
|
|
98
|
+
results.errors.push(res.details || '');
|
|
93
99
|
}
|
|
94
100
|
});
|
|
95
101
|
}
|
|
@@ -110,7 +110,7 @@ const rulesFunctions = {
|
|
|
110
110
|
return output;
|
|
111
111
|
}
|
|
112
112
|
};
|
|
113
|
-
function
|
|
113
|
+
function validateRules(key, value, requirements, inputObj) {
|
|
114
114
|
const result = {
|
|
115
115
|
ok: true,
|
|
116
116
|
details: []
|
|
@@ -156,4 +156,4 @@ function checkRules(key, value, requirements, inputObj) {
|
|
|
156
156
|
return result;
|
|
157
157
|
}
|
|
158
158
|
;
|
|
159
|
-
export default
|
|
159
|
+
export default validateRules;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { EValidationDetails, EValidationId } from "./constants/details.js";
|
|
2
|
+
import _validations from "./utils/validations.js";
|
|
3
|
+
import _errors from "./utils/errors.js";
|
|
4
|
+
import _validateType from "./utils/validateType.js";
|
|
5
|
+
const validateUnionType = (key, value, requirements, keyName = key) => {
|
|
6
|
+
const typeList = Array.isArray(requirements.type)
|
|
7
|
+
? requirements.type.map((el) => String((el === null || el === void 0 ? void 0 : el.name) || el))
|
|
8
|
+
: [];
|
|
9
|
+
const results = [];
|
|
10
|
+
for (let i = 0; i < typeList.length; i++) {
|
|
11
|
+
const requirementsRe = Object.assign(Object.assign({}, requirements), { type: requirements.type[i] });
|
|
12
|
+
const result = validateType(key, value, requirementsRe);
|
|
13
|
+
results.push(result[0].passed);
|
|
14
|
+
if (results[i] === true)
|
|
15
|
+
return _validateType.getResult(keyName, true);
|
|
16
|
+
}
|
|
17
|
+
const isPassed = results.some((r) => r === true);
|
|
18
|
+
const result = _validateType.getResult(keyName, isPassed, isPassed ? null : _errors.getErrorDetails(keyName, typeList.join('/'), value));
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
const validateType = (key, value, requirements, keyName = key) => {
|
|
22
|
+
var _a;
|
|
23
|
+
const isNotNull = value !== null;
|
|
24
|
+
const keyTitle = 'title' in requirements ? requirements.title : keyName;
|
|
25
|
+
const hasCustomMessage = requirements.customMessage && typeof requirements.customMessage === 'function';
|
|
26
|
+
if (value === undefined && requirements.required) {
|
|
27
|
+
return [_validateType.getResult(keyName, false, _errors.getMissingError(keyName))];
|
|
28
|
+
}
|
|
29
|
+
if (Array.isArray(requirements.type)) {
|
|
30
|
+
return [validateUnionType(key, value, requirements)];
|
|
31
|
+
}
|
|
32
|
+
if (value === undefined && requirements.required !== true) {
|
|
33
|
+
return [_validateType.getResult(keyName, true)];
|
|
34
|
+
}
|
|
35
|
+
const customErrDetails = hasCustomMessage ?
|
|
36
|
+
requirements.customMessage({
|
|
37
|
+
keyword: EValidationId.Type,
|
|
38
|
+
value: value,
|
|
39
|
+
key: keyName,
|
|
40
|
+
title: keyTitle,
|
|
41
|
+
reqs: requirements,
|
|
42
|
+
schema: null
|
|
43
|
+
}) :
|
|
44
|
+
null;
|
|
45
|
+
const baseErrDetails = _errors.getErrorDetails(keyName, requirements.type, value);
|
|
46
|
+
const getDetails = (isOK, errorText) => isOK ?
|
|
47
|
+
EValidationDetails.OK :
|
|
48
|
+
errorText || customErrDetails || baseErrDetails;
|
|
49
|
+
const typeBySchema = requirements.type;
|
|
50
|
+
const result = [];
|
|
51
|
+
switch (typeBySchema) {
|
|
52
|
+
case 'any': {
|
|
53
|
+
result.push(_validateType.getResult(keyName, true, getDetails(true)));
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
case Number: {
|
|
57
|
+
const isNumber = isNotNull && value.constructor === Number;
|
|
58
|
+
result.push(_validateType.getResult(keyName, isNumber, getDetails(isNumber)));
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
case String: {
|
|
62
|
+
const isString = isNotNull && value.constructor === String;
|
|
63
|
+
result.push(_validateType.getResult(keyName, isString, getDetails(isString)));
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
case Date: {
|
|
67
|
+
const isDate = isNotNull && value.constructor === Date;
|
|
68
|
+
const isValid = isDate && !isNaN(value.getTime());
|
|
69
|
+
const isValidDate = isDate && isValid;
|
|
70
|
+
result.push(_validateType.getResult(keyName, isValidDate, getDetails(isValidDate, EValidationDetails.INVALID_DATE)));
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
case Boolean: {
|
|
74
|
+
const isBoolean = isNotNull && value.constructor === Boolean;
|
|
75
|
+
result.push(_validateType.getResult(keyName, isBoolean, getDetails(isBoolean)));
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
case Array: {
|
|
79
|
+
const isArray = isNotNull && value.constructor === Array;
|
|
80
|
+
if (!isArray) {
|
|
81
|
+
result.push(_validateType.getResult(keyName, false, getDetails(isArray)));
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
let isEachChecked = { passed: true, details: "" };
|
|
85
|
+
if ('eachType' in requirements) {
|
|
86
|
+
for (const el of value) {
|
|
87
|
+
const result = validateType('each of ' + key, el, { type: requirements.eachType, required: true });
|
|
88
|
+
if (!result[0].passed) {
|
|
89
|
+
isEachChecked.passed = false;
|
|
90
|
+
isEachChecked.details = result[0].details || '';
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const isOk = isArray && isEachChecked.passed;
|
|
96
|
+
const details = !isEachChecked.passed ? isEachChecked.details : getDetails(isOk);
|
|
97
|
+
result.push(_validateType.getResult(keyName, isOk, details));
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
case Object: {
|
|
101
|
+
const isObject = _validations.isObject(value) && value.constructor === Object;
|
|
102
|
+
result.push(_validateType.getResult(keyName, isObject, getDetails(isObject)));
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case RegExp: {
|
|
106
|
+
const isRegex = _validations.isRegex(value);
|
|
107
|
+
result.push(_validateType.getResult(keyName, isRegex, getDetails(isRegex)));
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
case null: {
|
|
111
|
+
const isNull = value === null;
|
|
112
|
+
result.push(_validateType.getResult(keyName, isNull, getDetails(isNull)));
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
default: {
|
|
116
|
+
const isInstanceOf = typeof typeBySchema === 'function' && value instanceof typeBySchema;
|
|
117
|
+
const isConstructorSame = typeof typeBySchema === 'function' && ((_a = value.constructor) === null || _a === void 0 ? void 0 : _a.name) === (typeBySchema === null || typeBySchema === void 0 ? void 0 : typeBySchema.name);
|
|
118
|
+
const isOK = isInstanceOf && isConstructorSame;
|
|
119
|
+
result.push(_validateType.getResult(keyName, isOK, getDetails(isOK)));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
};
|
|
124
|
+
export default validateType;
|
package/package.json
CHANGED
package/dev.js
DELETED
|
File without changes
|
package/dist/checkType.js
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { ErrorKeywords } from "./constants/details.js";
|
|
2
|
-
import _validations from "./utils/validations.js";
|
|
3
|
-
import _errors from "./utils/errors.js";
|
|
4
|
-
const checkTypeMultiple = (key, value, requirements, keyName = key) => {
|
|
5
|
-
const constructorNames = Array.isArray(requirements.type)
|
|
6
|
-
? requirements.type.map((el) => String((el === null || el === void 0 ? void 0 : el.name) || el))
|
|
7
|
-
: [];
|
|
8
|
-
const result = {
|
|
9
|
-
key: keyName,
|
|
10
|
-
passed: false,
|
|
11
|
-
details: _errors.getErrorDetails(keyName, constructorNames.join('/'), value)
|
|
12
|
-
};
|
|
13
|
-
let i = 0;
|
|
14
|
-
if (Array.isArray(requirements.type)) {
|
|
15
|
-
while (i < requirements.type.length) {
|
|
16
|
-
const requirementsRe = Object.assign(Object.assign({}, requirements), { type: requirements.type[i] });
|
|
17
|
-
const check = checkType(key, value, requirementsRe);
|
|
18
|
-
if (check[0].passed === true) {
|
|
19
|
-
result.passed = true;
|
|
20
|
-
result.details = 'OK';
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
i++;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
27
|
-
};
|
|
28
|
-
const checkType = (key, value, requirements, keyName = key) => {
|
|
29
|
-
var _a;
|
|
30
|
-
const isNotNull = value !== null;
|
|
31
|
-
const keyTitle = 'title' in requirements ? requirements.title : keyName;
|
|
32
|
-
const hasCustomMessage = requirements.customMessage && typeof requirements.customMessage === 'function';
|
|
33
|
-
if (value === undefined && requirements.required) {
|
|
34
|
-
return [{ key: keyName, passed: false, details: `Значение "${keyName}" отсутствует` }];
|
|
35
|
-
}
|
|
36
|
-
let result = [];
|
|
37
|
-
if (Array.isArray(requirements.type)) {
|
|
38
|
-
return [checkTypeMultiple(key, value, requirements)];
|
|
39
|
-
}
|
|
40
|
-
if (value === undefined && requirements.required !== true) {
|
|
41
|
-
result.push({
|
|
42
|
-
key: keyName,
|
|
43
|
-
passed: true,
|
|
44
|
-
details: 'OK'
|
|
45
|
-
});
|
|
46
|
-
return result;
|
|
47
|
-
}
|
|
48
|
-
const customErrDetails = hasCustomMessage ?
|
|
49
|
-
requirements.customMessage({
|
|
50
|
-
keyword: ErrorKeywords.Type,
|
|
51
|
-
value: value,
|
|
52
|
-
key: keyName,
|
|
53
|
-
title: keyTitle,
|
|
54
|
-
reqs: requirements,
|
|
55
|
-
schema: null
|
|
56
|
-
}) :
|
|
57
|
-
null;
|
|
58
|
-
const baseErrDetails = _errors.getErrorDetails(keyName, requirements.type, value);
|
|
59
|
-
const getDetails = (isOK) => isOK ? 'OK' : customErrDetails || baseErrDetails;
|
|
60
|
-
const typeBySchema = requirements.type;
|
|
61
|
-
switch (typeBySchema) {
|
|
62
|
-
case 'any':
|
|
63
|
-
result.push({
|
|
64
|
-
key: keyName,
|
|
65
|
-
passed: true,
|
|
66
|
-
details: 'OK'
|
|
67
|
-
});
|
|
68
|
-
break;
|
|
69
|
-
case Number:
|
|
70
|
-
const isNumber = isNotNull && value.constructor === Number;
|
|
71
|
-
result.push({
|
|
72
|
-
key: keyName,
|
|
73
|
-
passed: isNumber,
|
|
74
|
-
details: getDetails(isNumber)
|
|
75
|
-
});
|
|
76
|
-
break;
|
|
77
|
-
case String:
|
|
78
|
-
const isString = isNotNull && value.constructor === String;
|
|
79
|
-
result.push({
|
|
80
|
-
key: keyName,
|
|
81
|
-
passed: isString,
|
|
82
|
-
details: getDetails(isString)
|
|
83
|
-
});
|
|
84
|
-
break;
|
|
85
|
-
case Date:
|
|
86
|
-
const isDate = isNotNull && value.constructor === Date;
|
|
87
|
-
const isValid = isDate && !isNaN(value.getTime());
|
|
88
|
-
const errorMsg = isValid ? getDetails(isDate) : 'Дата невалидна';
|
|
89
|
-
result.push({
|
|
90
|
-
key: keyName,
|
|
91
|
-
passed: isDate && isValid,
|
|
92
|
-
details: isDate && isValid ? 'OK' : errorMsg
|
|
93
|
-
});
|
|
94
|
-
break;
|
|
95
|
-
case Boolean:
|
|
96
|
-
const isBoolean = isNotNull && value.constructor === Boolean;
|
|
97
|
-
result.push({
|
|
98
|
-
key: keyName,
|
|
99
|
-
passed: isBoolean,
|
|
100
|
-
details: isBoolean ? 'OK' : getDetails(isBoolean)
|
|
101
|
-
});
|
|
102
|
-
break;
|
|
103
|
-
case Array:
|
|
104
|
-
const isArray = isNotNull && value.constructor === Array;
|
|
105
|
-
if (!isArray) {
|
|
106
|
-
result.push({
|
|
107
|
-
key: keyName,
|
|
108
|
-
passed: false,
|
|
109
|
-
details: getDetails(isArray)
|
|
110
|
-
});
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
let isEachChecked = { passed: true, details: "" };
|
|
114
|
-
if ('eachType' in requirements) {
|
|
115
|
-
isEachChecked.passed = value.every((el) => {
|
|
116
|
-
const checkResult = checkType('each of ' + key, el, { type: requirements.eachType, required: true });
|
|
117
|
-
if (!checkResult[0].passed) {
|
|
118
|
-
isEachChecked.details = checkResult[0].details;
|
|
119
|
-
isEachChecked.passed = false;
|
|
120
|
-
}
|
|
121
|
-
return true;
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
const isOk = isArray && isEachChecked.passed;
|
|
125
|
-
result.push({
|
|
126
|
-
key: keyName,
|
|
127
|
-
passed: isOk,
|
|
128
|
-
details: isOk ? 'OK' : !isEachChecked.passed ? isEachChecked.details : getDetails(isOk)
|
|
129
|
-
});
|
|
130
|
-
break;
|
|
131
|
-
case Object:
|
|
132
|
-
const isObject = _validations.isObject(value) && value.constructor === Object;
|
|
133
|
-
result.push({
|
|
134
|
-
key: keyName,
|
|
135
|
-
passed: isObject,
|
|
136
|
-
details: isObject ? 'OK' : getDetails(isObject)
|
|
137
|
-
});
|
|
138
|
-
break;
|
|
139
|
-
case RegExp:
|
|
140
|
-
const isRegex = _validations.isRegex(value);
|
|
141
|
-
result.push({
|
|
142
|
-
key: keyName,
|
|
143
|
-
passed: isRegex,
|
|
144
|
-
details: isRegex ? 'OK' : getDetails(isRegex)
|
|
145
|
-
});
|
|
146
|
-
break;
|
|
147
|
-
case null:
|
|
148
|
-
const isNull = value === null;
|
|
149
|
-
result.push({
|
|
150
|
-
key: keyName,
|
|
151
|
-
passed: isNull,
|
|
152
|
-
details: isNull ? 'OK' : getDetails(isNull)
|
|
153
|
-
});
|
|
154
|
-
break;
|
|
155
|
-
default:
|
|
156
|
-
const isInstanceOf = typeof typeBySchema === 'function' && value instanceof typeBySchema;
|
|
157
|
-
const isConstructorSame = typeof typeBySchema === 'function' && ((_a = value.constructor) === null || _a === void 0 ? void 0 : _a.name) === (typeBySchema === null || typeBySchema === void 0 ? void 0 : typeBySchema.name);
|
|
158
|
-
const checked = isInstanceOf && isConstructorSame;
|
|
159
|
-
result.push({
|
|
160
|
-
key: keyName,
|
|
161
|
-
passed: checked,
|
|
162
|
-
details: getDetails(checked)
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
return result;
|
|
166
|
-
};
|
|
167
|
-
export default checkType;
|
package/dist/utils/nested.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|