_limit.jst 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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.v5 && $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. , $opExpr = 'op' + $lvl
  18. , $opStr = '\' + ' + $opExpr + ' + \'';
  19. }}
  20. var schemaExcl{{=$lvl}} = {{=$schemaValueExcl}};
  21. {{ $schemaValueExcl = 'schemaExcl' + $lvl; }}
  22. var exclusive{{=$lvl}};
  23. if (typeof {{=$schemaValueExcl}} != 'boolean' && typeof {{=$schemaValueExcl}} != 'undefined') {
  24. {{ var $errorKeyword = $exclusiveKeyword; }}
  25. {{# def.error:'_exclusiveLimit' }}
  26. } else if({{# def.$dataNotType:'number' }}
  27. ((exclusive{{=$lvl}} = {{=$schemaValueExcl}} === true)
  28. ? {{=$data}} {{=$notOp}}= {{=$schemaValue}}
  29. : {{=$data}} {{=$notOp}} {{=$schemaValue}})
  30. || {{=$data}} !== {{=$data}}) {
  31. var op{{=$lvl}} = exclusive{{=$lvl}} ? '{{=$op}}' : '{{=$op}}=';
  32. {{??}}
  33. {{
  34. var $exclusive = $schemaExcl === true
  35. , $opStr = $op; /*used in error*/
  36. if (!$exclusive) $opStr += '=';
  37. var $opExpr = '\'' + $opStr + '\''; /*used in error*/
  38. }}
  39. if ({{# def.$dataNotType:'number' }}
  40. {{=$data}} {{=$notOp}}{{?$exclusive}}={{?}} {{=$schemaValue}}
  41. || {{=$data}} !== {{=$data}}) {
  42. {{?}}
  43. {{ var $errorKeyword = $keyword; }}
  44. {{# def.error:'_limit' }}
  45. } {{? $breakOnError }} else { {{?}}