Front end of the Slack clone application.

uniqueItemProperties.js 827B

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. module.exports = function defFunc(ajv) {
  3. defFunc.definition = {
  4. type: 'array',
  5. compile: function(keys, parentSchema, it) {
  6. var equal = it.util.equal;
  7. return function(data) {
  8. if (data.length > 1) {
  9. for (var k=0; k < keys.length; k++) {
  10. var key = keys[k];
  11. for (var i = data.length; i--;) {
  12. if (typeof data[i] != 'object') continue;
  13. for (var j = i; j--;) {
  14. if (typeof data[j] == 'object' && equal(data[i][key], data[j][key]))
  15. return false;
  16. }
  17. }
  18. }
  19. }
  20. return true;
  21. };
  22. },
  23. metaSchema: {
  24. type: 'array',
  25. items: {type: 'string'}
  26. }
  27. };
  28. ajv.addKeyword('uniqueItemProperties', defFunc.definition);
  29. return ajv;
  30. };