@lucania/schema 1.0.7 → 1.0.9
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.js +23 -12
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -194,17 +194,30 @@
|
|
|
194
194
|
return validated;
|
|
195
195
|
}
|
|
196
196
|
else if (isSchemaArray(schema)) {
|
|
197
|
-
if (
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
197
|
+
if (typeof source === "object") {
|
|
198
|
+
if (source.constructor.name === "Object") {
|
|
199
|
+
const keys = Object.keys(source);
|
|
200
|
+
if (keys.some((key) => isNaN(parseInt(key)))) {
|
|
201
|
+
return new ValidationError("incorrectType", schema, source, path, originalSchema, originalSource);
|
|
202
|
+
}
|
|
203
|
+
const newSource = [];
|
|
204
|
+
for (const key of keys) {
|
|
205
|
+
newSource[key] = source[key];
|
|
204
206
|
}
|
|
205
|
-
|
|
207
|
+
source = newSource;
|
|
208
|
+
}
|
|
209
|
+
if (Array.isArray(source)) {
|
|
210
|
+
[schema] = schema;
|
|
211
|
+
const validated = [];
|
|
212
|
+
for (let i = 0; i < source.length; i++) {
|
|
213
|
+
const result = _validate(schema, source[i], path, originalSchema, originalSource);
|
|
214
|
+
if (result instanceof ValidationError) {
|
|
215
|
+
return result;
|
|
216
|
+
}
|
|
217
|
+
validated[i] = result;
|
|
218
|
+
}
|
|
219
|
+
return validated;
|
|
206
220
|
}
|
|
207
|
-
return validated;
|
|
208
221
|
}
|
|
209
222
|
const errorType = source === undefined || source === null ? "missing" : "incorrectType";
|
|
210
223
|
return new ValidationError(errorType, schema, source, path, originalSchema, originalSource);
|
|
@@ -325,7 +338,7 @@
|
|
|
325
338
|
}
|
|
326
339
|
static getMessage(type, source, schema, path) {
|
|
327
340
|
let sourceRepresentation = JSON.stringify(source);
|
|
328
|
-
if (isNaN(source)) {
|
|
341
|
+
if (typeof source === "number" && isNaN(source)) {
|
|
329
342
|
sourceRepresentation = "NaN";
|
|
330
343
|
}
|
|
331
344
|
switch (type) {
|
|
@@ -348,7 +361,5 @@
|
|
|
348
361
|
}
|
|
349
362
|
Schema.ValidationError = ValidationError;
|
|
350
363
|
})(Schema || (exports.Schema = Schema = {}));
|
|
351
|
-
const cow = Schema.validate({ cow: { type: "number", required: true } }, { cow: NaN });
|
|
352
|
-
console.log(cow);
|
|
353
364
|
|
|
354
365
|
}));
|