Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

uniqueItems.jst 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 i = {{=$data}}.length
  15. , {{=$valid}} = true
  16. , j;
  17. if (i > 1) {
  18. {{
  19. var $itemType = it.schema.items && it.schema.items.type
  20. , $typeIsArray = Array.isArray($itemType);
  21. }}
  22. {{? !$itemType || $itemType == 'object' || $itemType == 'array' ||
  23. ($typeIsArray && ($itemType.indexOf('object') >= 0 || $itemType.indexOf('array') >= 0)) }}
  24. outer:
  25. for (;i--;) {
  26. for (j = i; j--;) {
  27. if (equal({{=$data}}[i], {{=$data}}[j])) {
  28. {{=$valid}} = false;
  29. break outer;
  30. }
  31. }
  32. }
  33. {{??}}
  34. var itemIndices = {}, item;
  35. for (;i--;) {
  36. var item = {{=$data}}[i];
  37. {{ var $method = 'checkDataType' + ($typeIsArray ? 's' : ''); }}
  38. if ({{= it.util[$method]($itemType, 'item', it.opts.strictNumbers, true) }}) continue;
  39. {{? $typeIsArray}}
  40. if (typeof item == 'string') item = '"' + item;
  41. {{?}}
  42. if (typeof itemIndices[item] == 'number') {
  43. {{=$valid}} = false;
  44. j = itemIndices[item];
  45. break;
  46. }
  47. itemIndices[item] = i;
  48. }
  49. {{?}}
  50. }
  51. {{? $isData }} } {{?}}
  52. if (!{{=$valid}}) {
  53. {{# def.error:'uniqueItems' }}
  54. } {{? $breakOnError }} else { {{?}}
  55. {{??}}
  56. {{? $breakOnError }} if (true) { {{?}}
  57. {{?}}