In:
[{error: ““, …}, {error: ““, …}]
Out:
[““, ““]
flattenErrorsToArray: function(errors) {
return errors
.map(function(error) { return error.error; })
.filter(function(value, index, self) {
return self.indexOf(value) === index;
});
},
cleanAttributes: function(attributes, whitelist) {
function whitelistCreator(obj, key, last) {
if (v.isObject(obj[key])) {
return obj[key];
}
return (obj[key] = last ? true : {});
}
function buildObjectWhitelist(whitelist) {
var ow = {}
, lastObject
, attr;
for (attr in whitelist) {
if (!whitelist[attr]) {
continue;
}
v.forEachKeyInKeypath(ow, attr, whitelistCreator);
}
return ow;
}
function cleanRecursive(attributes, whitelist) {
if (!v.isObject(attributes)) {
return attributes;
}
var ret = v.extend({}, attributes)
, w
, attribute;
for (attribute in attributes) {
w = whitelist[attribute];
if (v.isObject(w)) {
ret[attribute] = cleanRecursive(ret[attribute], w);
} else if (!w) {
delete ret[attribute];
}
}
return ret;
}
if (!v.isObject(whitelist) || !v.isObject(attributes)) {
return {};
}
whitelist = buildObjectWhitelist(whitelist);
return cleanRecursive(attributes, whitelist);
},
exposeModule: function(validate, root, exports, module, define) {
if (exports) {
if (module && module.exports) {
exports = module.exports = validate;
}
exports.validate = validate;
} else {
root.validate = validate;
if (validate.isFunction(define) && define.amd) {
define([], function () { return validate; });
}
}
},
warn: function(msg) {
if (typeof console !== "undefined" && console.warn) {
console.warn("[validate.js] " + msg);
}
},
error: function(msg) {
if (typeof console !== "undefined" && console.error) {
console.error("[validate.js] " + msg);
}
}
});
validate.validators = {