Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Minor improvements to the ‘getProperty’ method

  • Loading branch information...
commit a7315e7882fd8befdb08e3ff498b209c4d44c1d3 1 parent cf2eb97
František Hába authored
9 src/engines/json/getProperty.js
View
@@ -1,9 +1,12 @@
/**
* GetProperty
*
+ * @param {string} property
* @param {object} source
- * @param {string} property
*/
-Validation.prototype.getProperty = function(source, property) {
- return (!source) ? undefined : source[property];
+Validation.prototype.getProperty = function(property, source) {
+ var tree = property.match(/([a-zA-Z0-9\s]+)/g);
+ return tree.reduce(function(previousValue, currentValue, index) {
+ return (previousValue && previousValue[currentValue]) ? previousValue[currentValue] : undefined;
+ }, source);
};
2  src/engines/json/validateProperties.js
View
@@ -18,7 +18,7 @@ Validation.prototype.validateProperties = function(instance, schema, path, callb
isArray = propertyAttributes.type === 'array';
// Get the value of property (instance[property])
- var propertyValue = self.getProperty(instance, property);
+ var propertyValue = self.getProperty(property, instance);
// Compose the property path
var propertyName = property.indexOf(' ') !== -1 ? '[\'' + property + '\']' : '.' + property,
Please sign in to comment.
Something went wrong with that request. Please try again.