_limit.jst 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. {{# def.definitions }}
  2. {{# def.errors }}
  3. {{# def.setupKeyword }}
  4. {{# def.$data }}
  5. {{
  6. var $isMax = $keyword == 'maximum'
  7. , $exclusiveKeyword = $isMax ? 'exclusiveMaximum' : 'exclusiveMinimum'
  8. , $schemaExcl = it.schema[$exclusiveKeyword]
  9. , $isDataExcl = it.opts.$data && $schemaExcl && $schemaExcl.$data
  10. , $op = $isMax ? '<' : '>'
  11. , $notOp = $isMax ? '>' : '<';
  12. }}
  13. {{? $isDataExcl }}
  14. {{
  15. var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr)
  16. , $exclusive = 'exclusive' + $lvl
  17. , $exclType = 'exclType' + $lvl
  18. , $exclIsNumber = 'exclIsNumber' + $lvl
  19. , $opExpr = 'op' + $lvl
  20. , $opStr = '\' + ' + $opExpr + ' + \'';
  21. }}
  22. var schemaExcl{{=$lvl}} = {{=$schemaValueExcl}};
  23. {{ $schemaValueExcl = 'schemaExcl' + $lvl; }}
  24. var {{=$exclusive}};
  25. var {{=$exclType}} = typeof {{=$schemaValueExcl}};
  26. if ({{=$exclType}} != 'boolean' && {{=$exclType}} != 'undefined' && {{=$exclType}} != 'number') {
  27. {{ var $errorKeyword = $exclusiveKeyword; }}
  28. {{# def.error:'_exclusiveLimit' }}
  29. } else if ({{# def.$dataNotType:'number' }}
  30. {{=$exclType}} == 'number'
  31. ? (
  32. ({{=$exclusive}} = {{=$schemaValue}} === undefined || {{=$schemaValueExcl}} {{=$op}}= {{=$schemaValue}})
  33. ? {{=$data}} {{=$notOp}}= {{=$schemaValueExcl}}
  34. : {{=$data}} {{=$notOp}} {{=$schemaValue}}
  35. )
  36. : (
  37. ({{=$exclusive}} = {{=$schemaValueExcl}} === true)
  38. ? {{=$data}} {{=$notOp}}= {{=$schemaValue}}
  39. : {{=$data}} {{=$notOp}} {{=$schemaValue}}
  40. )
  41. || {{=$data}} !== {{=$data}}) {
  42. var op{{=$lvl}} = {{=$exclusive}} ? '{{=$op}}' : '{{=$op}}=';
  43. {{??}}
  44. {{
  45. var $exclIsNumber = typeof $schemaExcl == 'number'
  46. , $opStr = $op; /*used in error*/
  47. }}
  48. {{? $exclIsNumber && $isData }}
  49. {{ var $opExpr = '\'' + $opStr + '\''; /*used in error*/ }}
  50. if ({{# def.$dataNotType:'number' }}
  51. ( {{=$schemaValue}} === undefined
  52. || {{=$schemaExcl}} {{=$op}}= {{=$schemaValue}}
  53. ? {{=$data}} {{=$notOp}}= {{=$schemaExcl}}
  54. : {{=$data}} {{=$notOp}} {{=$schemaValue}} )
  55. || {{=$data}} !== {{=$data}}) {
  56. {{??}}
  57. {{
  58. if ($exclIsNumber && $schema === undefined) {
  59. $schemaValue = $schemaExcl;
  60. $notOp += '=';
  61. } else {
  62. if ($exclIsNumber)
  63. $schemaValue = Math[$isMax ? 'min' : 'max']($schemaExcl, $schema);
  64. if ($schemaExcl === ($exclIsNumber ? $schemaValue : true))
  65. $notOp += '=';
  66. else
  67. $opStr += '=';
  68. }
  69. var $opExpr = '\'' + $opStr + '\''; /*used in error*/
  70. }}
  71. if ({{# def.$dataNotType:'number' }}
  72. {{=$data}} {{=$notOp}} {{=$schemaValue}}
  73. || {{=$data}} !== {{=$data}}) {
  74. {{?}}
  75. {{?}}
  76. {{ var $errorKeyword = $keyword; }}
  77. {{# def.error:'_limit' }}
  78. } {{? $breakOnError }} else { {{?}}