@dvsa/cvs-type-definitions 2.0.29 → 2.1.0
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/package.json +1 -1
- package/schema-validator.d.ts +3 -1
- package/schema-validator.js +7 -2
package/package.json
CHANGED
package/schema-validator.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ErrorObject } from "ajv";
|
|
1
2
|
import { schemas } from "./schemas";
|
|
2
3
|
export declare type Schema = typeof schemas[number];
|
|
3
|
-
export declare
|
|
4
|
+
export declare function isValidObject<B extends boolean | undefined>(schemaName: Schema, objectToValidate: object): boolean;
|
|
5
|
+
export declare function isValidObject<B extends boolean | undefined>(schemaName: Schema, objectToValidate: object, returnErrors: B): B extends false ? boolean : ErrorObject[];
|
package/schema-validator.js
CHANGED
|
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isValidObject = void 0;
|
|
4
4
|
var ajv_1 = require("ajv");
|
|
5
5
|
var fs_1 = require("fs");
|
|
6
|
-
|
|
6
|
+
function isValidObject(schemaName, objectToValidate, returnErrors, logErrors) {
|
|
7
|
+
var _a;
|
|
7
8
|
if (logErrors === void 0) { logErrors = false; }
|
|
8
9
|
var ajv = new ajv_1.default({ removeAdditional: true, allErrors: true });
|
|
9
10
|
var schema = JSON.parse((0, fs_1.readFileSync)("".concat(__dirname, "/json-schemas/").concat(schemaName), "utf8"));
|
|
@@ -12,6 +13,10 @@ var isValidObject = function (schemaName, objectToValidate, logErrors) {
|
|
|
12
13
|
if (logErrors && validateFunction.errors) {
|
|
13
14
|
console.error(validateFunction.errors);
|
|
14
15
|
}
|
|
16
|
+
if (returnErrors) {
|
|
17
|
+
return (_a = validateFunction.errors) !== null && _a !== void 0 ? _a : [];
|
|
18
|
+
}
|
|
15
19
|
return isValid;
|
|
16
|
-
}
|
|
20
|
+
}
|
|
17
21
|
exports.isValidObject = isValidObject;
|
|
22
|
+
;
|