ascertain 0.7.31 → 0.8.2
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/build/index.d.ts +2 -0
- package/build/index.js +13 -11
- package/package.json +6 -6
package/build/index.d.ts
CHANGED
|
@@ -17,4 +17,6 @@ export interface Ascertain {
|
|
|
17
17
|
(data: any): void;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
export function ascertain<T extends Data = any>(schema: Schema<T>, data: any, rootName?: string): void;
|
|
21
|
+
|
|
20
22
|
export default function <T extends Data = any>(schema: Schema<T>, data: any, rootName?: string): void;
|
package/build/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.or = exports.optional = exports.default = exports.and = exports.$values = exports.$keys = void 0;
|
|
6
|
+
exports.or = exports.optional = exports.default = exports.ascertain = exports.and = exports.$values = exports.$keys = void 0;
|
|
7
7
|
|
|
8
8
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
9
9
|
|
|
@@ -107,13 +107,13 @@ exports.$keys = $keys;
|
|
|
107
107
|
var $values = Symbol.for('@@values');
|
|
108
108
|
exports.$values = $values;
|
|
109
109
|
|
|
110
|
-
function
|
|
110
|
+
function certain(target, schema, path, optional) {
|
|
111
111
|
if (schema === null || typeof schema === 'undefined') {
|
|
112
112
|
return new AssertError(schema, 'any value', path, 'schema value');
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
if (schema instanceof Optional) {
|
|
116
|
-
return
|
|
116
|
+
return certain(target, schema.schema, path, true);
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
var isValue = target !== null && typeof target !== 'undefined';
|
|
@@ -128,7 +128,7 @@ function ascertain(target, schema, path, optional) {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
return findNotError(schema.schema, function (schema) {
|
|
131
|
-
return
|
|
131
|
+
return certain(target, schema, path);
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
134
|
|
|
@@ -138,7 +138,7 @@ function ascertain(target, schema, path, optional) {
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
return findFirstError(schema.schema, function (schema) {
|
|
141
|
-
return
|
|
141
|
+
return certain(target, schema, path);
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
144
|
|
|
@@ -161,7 +161,7 @@ function ascertain(target, schema, path, optional) {
|
|
|
161
161
|
|
|
162
162
|
return findFirstError(target, function (value, idx) {
|
|
163
163
|
return findNotError(schema, function (itemSchemaType) {
|
|
164
|
-
return
|
|
164
|
+
return certain(value, itemSchemaType, "".concat(path, ".").concat(idx));
|
|
165
165
|
});
|
|
166
166
|
});
|
|
167
167
|
} else if (_typeof(schema) === 'object') {
|
|
@@ -181,7 +181,7 @@ function ascertain(target, schema, path, optional) {
|
|
|
181
181
|
if ($keys in schema) {
|
|
182
182
|
var targetKeys = Object.keys(target);
|
|
183
183
|
var assertError = findFirstError(targetKeys, function (targetKey) {
|
|
184
|
-
return
|
|
184
|
+
return certain(targetKey, schema[$keys], "".concat(path, ".").concat(targetKey));
|
|
185
185
|
});
|
|
186
186
|
|
|
187
187
|
if (assertError) {
|
|
@@ -193,7 +193,7 @@ function ascertain(target, schema, path, optional) {
|
|
|
193
193
|
var _targetKeys = Object.keys(target);
|
|
194
194
|
|
|
195
195
|
var _assertError = findFirstError(_targetKeys, function (targetKey) {
|
|
196
|
-
return
|
|
196
|
+
return certain(target[targetKey], schema[$values], "".concat(path, ".").concat(targetKey));
|
|
197
197
|
});
|
|
198
198
|
|
|
199
199
|
if (_assertError) {
|
|
@@ -202,7 +202,7 @@ function ascertain(target, schema, path, optional) {
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
return findFirstError(Object.keys(schema), function (key) {
|
|
205
|
-
return
|
|
205
|
+
return certain(target[key], schema[key], "".concat(path, ".").concat(key));
|
|
206
206
|
});
|
|
207
207
|
}
|
|
208
208
|
} else if (target !== schema) {
|
|
@@ -210,13 +210,15 @@ function ascertain(target, schema, path, optional) {
|
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
var
|
|
213
|
+
var ascertain = function ascertain(schema, data) {
|
|
214
214
|
var rootName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '[root]';
|
|
215
|
-
var result =
|
|
215
|
+
var result = certain(data, schema, rootName);
|
|
216
216
|
|
|
217
217
|
if (result instanceof AssertError) {
|
|
218
218
|
throw new TypeError(result.toString());
|
|
219
219
|
}
|
|
220
220
|
};
|
|
221
221
|
|
|
222
|
+
exports.ascertain = ascertain;
|
|
223
|
+
var _default = ascertain;
|
|
222
224
|
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ascertain",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "0-Deps, simple, fast, for browser and node js object schema validator",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
},
|
|
34
34
|
"homepage": "https://github.com/3axap4eHko/ascertain#readme",
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@babel/cli": "^7.
|
|
37
|
-
"@babel/core": "^7.
|
|
38
|
-
"@babel/preset-env": "^7.
|
|
39
|
-
"babel-jest": "^
|
|
40
|
-
"jest": "^
|
|
36
|
+
"@babel/cli": "^7.17.6",
|
|
37
|
+
"@babel/core": "^7.17.8",
|
|
38
|
+
"@babel/preset-env": "^7.16.11",
|
|
39
|
+
"babel-jest": "^27.5.1",
|
|
40
|
+
"jest": "^27.5.1"
|
|
41
41
|
}
|
|
42
42
|
}
|