Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const tv4 = require('tv4');
tv4.defineError('UNIQUE_KEYS', 10001, '{uniqueKeys} are must be unique value.');
tv4.defineKeyword('uniqueKeys', function(data, value, schema) {
if (!Array.isArray(value)) {
return null;
}
let targets = [];
for (let key of value) {
if (data[key] !== null && data[key] !== undefined) {
targets.push(data[key]);
}
}
let duplicated = targets.filter(function(x, i, self) {
return self.indexOf(x) !== self.lastIndexOf(x);
});
if (duplicated.length > 0) {
return {