uniqueItems.jst 837 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. {{# def.definitions }}
  2. {{# def.errors }}
  3. {{# def.setupKeyword }}
  4. {{# def.$data }}
  5. {{? ($schema || $isData) && it.opts.uniqueItems !== false }}
  6. {{? $isData }}
  7. var {{=$valid}};
  8. if ({{=$schemaValue}} === false || {{=$schemaValue}} === undefined)
  9. {{=$valid}} = true;
  10. else if (typeof {{=$schemaValue}} != 'boolean')
  11. {{=$valid}} = false;
  12. else {
  13. {{?}}
  14. var {{=$valid}} = true;
  15. if ({{=$data}}.length > 1) {
  16. var i = {{=$data}}.length, j;
  17. outer:
  18. for (;i--;) {
  19. for (j = i; j--;) {
  20. if (equal({{=$data}}[i], {{=$data}}[j])) {
  21. {{=$valid}} = false;
  22. break outer;
  23. }
  24. }
  25. }
  26. }
  27. {{? $isData }} } {{?}}
  28. if (!{{=$valid}}) {
  29. {{# def.error:'uniqueItems' }}
  30. } {{? $breakOnError }} else { {{?}}
  31. {{??}}
  32. {{? $breakOnError }} if (true) { {{?}}
  33. {{?}}