Replace checkit-based validation with a simple property check for the time being

master
Sven Slootweg 8 years ago
parent d4c01e8056
commit 89fe5054f0

@ -19,7 +19,6 @@
"author": "Sven Slootweg",
"license": "WTFPL",
"dependencies": {
"checkit": "^0.7.0",
"deep-assign": "^2.0.0",
"default-value": "^1.0.0",
"dotty": "0.0.2"

@ -5,6 +5,7 @@ const defaultValue = require("default-value");
const createObject = require("./create-object");
const createPropertyMapper = require("./property-mapper");
const requireProperties = require("./require-properties");
const max = require("./util/max");
const min = require("./util/min");
@ -16,6 +17,8 @@ function getPosition(object) {
}
module.exports = function createCompositeObject(options) {
requireProperties(options, ["drawOrder", "objects"]);
let mapProperties = createPropertyMapper(options.propertyMap);
let initialPropertySet = mapProperties(options);

@ -1,7 +1,7 @@
'use strict';
module.exports = {
validateSync: require("./validate-sync"),
requireProperties: require("./require-properties"),
createObject: require("./create-object"),
createCompositeObject: require("./create-composite-object")
}

@ -0,0 +1,17 @@
'use strict';
module.exports = function requireProperties(object, properties) {
let missingProperties = [];
properties.forEach((property) => {
if (object[property] == null) {
missingProperties.push(property);
}
});
if (missingProperties.length > 0) {
throw new Error(`Missing required properties: ${missingProperties.join(", ")}`);
} else {
return true;
}
};

@ -1,13 +0,0 @@
'use strict';
const checkit = require("checkit");
module.exports = function(object, rules) {
let [error, validated] = checkit(rules).runSync(object);
if (error != null) {
throw error;
} else {
return validated;
}
};
Loading…
Cancel
Save