Commit 9e02ff51 authored by Tristan Cavelier's avatar Tristan Cavelier

Metadata.js check method added

parent d073d692
...@@ -23,6 +23,20 @@ Metadata.prototype.format = function () { ...@@ -23,6 +23,20 @@ Metadata.prototype.format = function () {
return this.update(this._dict); return this.update(this._dict);
}; };
Metadata.prototype.check = function () {
var k;
for (k in this._dict) {
if (this._dict.hasOwnProperty(k)) {
if (k[0] !== '_') {
if (!Metadata.checkValue(this._dict[k])) {
return false;
}
}
}
}
return true;
};
Metadata.prototype.update = function (metadata) { Metadata.prototype.update = function (metadata) {
var k; var k;
for (k in metadata) { for (k in metadata) {
...@@ -251,4 +265,50 @@ Metadata.normalizeValue = function (value) { ...@@ -251,4 +265,50 @@ Metadata.normalizeValue = function (value) {
} }
}; };
Metadata.checkArray = function (value) {
var i;
for (i = 0; i < value.length; i += 1) {
if (Metadata.isDict(value[i])) {
if (!Metadata.checkObject(value[i])) {
return false;
}
} else if (!Metadata.isContent(value[i])) {
return false;
}
}
return true;
};
Metadata.checkObject = function (value) {
var i, ok = false;
for (i in value) {
if (value.hasOwnProperty(i)) {
if (Metadata.isContent(value[i])) {
if (i === 'content') {
ok = true;
}
} else {
return false;
}
}
}
if (ok === false) {
return false;
}
return true;
};
Metadata.checkValue = function (value) {
if (Metadata.isContent(value)) {
return true;
}
if (Array.isArray(value)) {
return Metadata.checkArray(value);
}
if (Metadata.isDict(value)) {
return Metadata.checkObject(value);
}
return false;
};
exports.Metadata = Metadata; exports.Metadata = Metadata;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment