uniqueItems.jst 837 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. {{?}}