_formatLimit.jst 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. {{# def.definitions }}
  2. {{# def.errors }}
  3. {{# def.setupKeyword }}
  4. var {{=$valid}} = undefined;
  5. {{## def.skipFormatLimit:
  6. {{=$valid}} = true;
  7. {{ return out; }}
  8. #}}
  9. {{## def.compareFormat:
  10. {{? $isData }}
  11. if ({{=$schemaValue}} === undefined) {{=$valid}} = true;
  12. else if (typeof {{=$schemaValue}} != 'string') {{=$valid}} = false;
  13. else {
  14. {{ $closingBraces += '}'; }}
  15. {{?}}
  16. {{? $isDataFormat }}
  17. if (!{{=$compare}}) {{=$valid}} = true;
  18. else {
  19. {{ $closingBraces += '}'; }}
  20. {{?}}
  21. var {{=$result}} = {{=$compare}}({{=$data}}, {{# def.schemaValueQS }});
  22. if ({{=$result}} === undefined) {{=$valid}} = false;
  23. #}}
  24. {{? it.opts.format === false }}{{# def.skipFormatLimit }}{{?}}
  25. {{
  26. var $schemaFormat = it.schema.format
  27. , $isDataFormat = it.opts.$data && $schemaFormat.$data
  28. , $closingBraces = '';
  29. }}
  30. {{? $isDataFormat }}
  31. {{
  32. var $schemaValueFormat = it.util.getData($schemaFormat.$data, $dataLvl, it.dataPathArr)
  33. , $format = 'format' + $lvl
  34. , $compare = 'compare' + $lvl;
  35. }}
  36. var {{=$format}} = formats[{{=$schemaValueFormat}}]
  37. , {{=$compare}} = {{=$format}} && {{=$format}}.compare;
  38. {{??}}
  39. {{ var $format = it.formats[$schemaFormat]; }}
  40. {{? !($format && $format.compare) }}
  41. {{# def.skipFormatLimit }}
  42. {{?}}
  43. {{ var $compare = 'formats' + it.util.getProperty($schemaFormat) + '.compare'; }}
  44. {{?}}
  45. {{
  46. var $isMax = $keyword == 'formatMaximum'
  47. , $exclusiveKeyword = 'formatExclusive' + ($isMax ? 'Maximum' : 'Minimum')
  48. , $schemaExcl = it.schema[$exclusiveKeyword]
  49. , $isDataExcl = it.opts.$data && $schemaExcl && $schemaExcl.$data
  50. , $op = $isMax ? '<' : '>'
  51. , $result = 'result' + $lvl;
  52. }}
  53. {{# def.$data }}
  54. {{? $isDataExcl }}
  55. {{
  56. var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr)
  57. , $exclusive = 'exclusive' + $lvl
  58. , $opExpr = 'op' + $lvl
  59. , $opStr = '\' + ' + $opExpr + ' + \'';
  60. }}
  61. var schemaExcl{{=$lvl}} = {{=$schemaValueExcl}};
  62. {{ $schemaValueExcl = 'schemaExcl' + $lvl; }}
  63. if (typeof {{=$schemaValueExcl}} != 'boolean' && {{=$schemaValueExcl}} !== undefined) {
  64. {{=$valid}} = false;
  65. {{ var $errorKeyword = $exclusiveKeyword; }}
  66. {{# def.error:'_formatExclusiveLimit' }}
  67. }
  68. {{# def.elseIfValid }}
  69. {{# def.compareFormat }}
  70. var {{=$exclusive}} = {{=$schemaValueExcl}} === true;
  71. if ({{=$valid}} === undefined) {
  72. {{=$valid}} = {{=$exclusive}}
  73. ? {{=$result}} {{=$op}} 0
  74. : {{=$result}} {{=$op}}= 0;
  75. }
  76. if (!{{=$valid}}) var op{{=$lvl}} = {{=$exclusive}} ? '{{=$op}}' : '{{=$op}}=';
  77. {{??}}
  78. {{
  79. var $exclusive = $schemaExcl === true
  80. , $opStr = $op; /*used in error*/
  81. if (!$exclusive) $opStr += '=';
  82. var $opExpr = '\'' + $opStr + '\''; /*used in error*/
  83. }}
  84. {{# def.compareFormat }}
  85. if ({{=$valid}} === undefined)
  86. {{=$valid}} = {{=$result}} {{=$op}}{{?!$exclusive}}={{?}} 0;
  87. {{?}}
  88. {{= $closingBraces }}
  89. if (!{{=$valid}}) {
  90. {{ var $errorKeyword = $keyword; }}
  91. {{# def.error:'_formatLimit' }}
  92. }