Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added a new attribute called ‘patternProperties’

  • Loading branch information...
commit 598afd2e71b76eac8491cab82f57fd5c6432de83 1 parent 9d573be
@Baggz authored
Showing with 47 additions and 0 deletions.
  1. +47 −0 src/engines/json/attributes/patternProperties.js
View
47 src/engines/json/attributes/patternProperties.js
@@ -0,0 +1,47 @@
+(function() {
+
+ /**
+ * PatternProperties
+ */
+ var attribute = function patternProperties(property, propertyValue, attributeValue, propertyAttributes, callback) {
+
+ // Saves a reference to ‘this’
+ var self = this;
+
+ // Skip
+ if (isEmpty(attributeValue)) {
+ return callback();
+ }
+
+ var matches = {};
+ var patterns = keys(attributeValue);
+
+ each(propertyValue, function(key, value) {
+
+ each(patterns, function(index, pattern) {
+ if (key.match(new RegExp(pattern))) {
+ matches[key] = attributeValue[pattern];
+ }
+ });
+
+ });
+
+ if (isEmpty(matches)) {
+ return callback();
+ }
+
+ each(matches, function(propertyName, propertySchema, callback) {
+ return self.validateSchema(
+ propertyValue[propertyName],
+ propertySchema,
+ property + '.' + propertyName, // Fix Me!
+ callback
+ );
+ }, callback);
+
+ };
+
+ // Export
+ Validation.prototype.addAttribute('patternProperties', attribute);
+
+}());
Please sign in to comment.
Something went wrong with that request. Please try again.