25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

203 satır
3.9 KiB

4 yıl önce
  1. {{## def.setupKeyword:
  2. {{
  3. var $lvl = it.level;
  4. var $dataLvl = it.dataLevel;
  5. var $schema = it.schema[$keyword];
  6. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  7. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  8. var $breakOnError = !it.opts.allErrors;
  9. var $errorKeyword;
  10. var $data = 'data' + ($dataLvl || '');
  11. var $valid = 'valid' + $lvl;
  12. var $errs = 'errs__' + $lvl;
  13. }}
  14. #}}
  15. {{## def.setCompositeRule:
  16. {{
  17. var $wasComposite = it.compositeRule;
  18. it.compositeRule = $it.compositeRule = true;
  19. }}
  20. #}}
  21. {{## def.resetCompositeRule:
  22. {{ it.compositeRule = $it.compositeRule = $wasComposite; }}
  23. #}}
  24. {{## def.setupNextLevel:
  25. {{
  26. var $it = it.util.copy(it);
  27. var $closingBraces = '';
  28. $it.level++;
  29. var $nextValid = 'valid' + $it.level;
  30. }}
  31. #}}
  32. {{## def.ifValid:
  33. {{? $breakOnError }}
  34. if ({{=$valid}}) {
  35. {{ $closingBraces += '}'; }}
  36. {{?}}
  37. #}}
  38. {{## def.ifResultValid:
  39. {{? $breakOnError }}
  40. if ({{=$nextValid}}) {
  41. {{ $closingBraces += '}'; }}
  42. {{?}}
  43. #}}
  44. {{## def.elseIfValid:
  45. {{? $breakOnError }}
  46. {{ $closingBraces += '}'; }}
  47. else {
  48. {{?}}
  49. #}}
  50. {{## def.nonEmptySchema:_schema:
  51. (it.opts.strictKeywords
  52. ? (typeof _schema == 'object' && Object.keys(_schema).length > 0)
  53. || _schema === false
  54. : it.util.schemaHasRules(_schema, it.RULES.all))
  55. #}}
  56. {{## def.strLength:
  57. {{? it.opts.unicode === false }}
  58. {{=$data}}.length
  59. {{??}}
  60. ucs2length({{=$data}})
  61. {{?}}
  62. #}}
  63. {{## def.willOptimize:
  64. it.util.varOccurences($code, $nextData) < 2
  65. #}}
  66. {{## def.generateSubschemaCode:
  67. {{
  68. var $code = it.validate($it);
  69. $it.baseId = $currentBaseId;
  70. }}
  71. #}}
  72. {{## def.insertSubschemaCode:
  73. {{= it.validate($it) }}
  74. {{ $it.baseId = $currentBaseId; }}
  75. #}}
  76. {{## def._optimizeValidate:
  77. it.util.varReplace($code, $nextData, $passData)
  78. #}}
  79. {{## def.optimizeValidate:
  80. {{? {{# def.willOptimize}} }}
  81. {{= {{# def._optimizeValidate }} }}
  82. {{??}}
  83. var {{=$nextData}} = {{=$passData}};
  84. {{= $code }}
  85. {{?}}
  86. #}}
  87. {{## def.$data:
  88. {{
  89. var $isData = it.opts.$data && $schema && $schema.$data
  90. , $schemaValue;
  91. }}
  92. {{? $isData }}
  93. var schema{{=$lvl}} = {{= it.util.getData($schema.$data, $dataLvl, it.dataPathArr) }};
  94. {{ $schemaValue = 'schema' + $lvl; }}
  95. {{??}}
  96. {{ $schemaValue = $schema; }}
  97. {{?}}
  98. #}}
  99. {{## def.$dataNotType:_type:
  100. {{?$isData}} ({{=$schemaValue}} !== undefined && typeof {{=$schemaValue}} != _type) || {{?}}
  101. #}}
  102. {{## def.check$dataIsArray:
  103. if (schema{{=$lvl}} === undefined) {{=$valid}} = true;
  104. else if (!Array.isArray(schema{{=$lvl}})) {{=$valid}} = false;
  105. else {
  106. #}}
  107. {{## def.numberKeyword:
  108. {{? !($isData || typeof $schema == 'number') }}
  109. {{ throw new Error($keyword + ' must be number'); }}
  110. {{?}}
  111. #}}
  112. {{## def.beginDefOut:
  113. {{
  114. var $$outStack = $$outStack || [];
  115. $$outStack.push(out);
  116. out = '';
  117. }}
  118. #}}
  119. {{## def.storeDefOut:_variable:
  120. {{
  121. var _variable = out;
  122. out = $$outStack.pop();
  123. }}
  124. #}}
  125. {{## def.dataPath:(dataPath || ''){{? it.errorPath != '""'}} + {{= it.errorPath }}{{?}}#}}
  126. {{## def.setParentData:
  127. {{
  128. var $parentData = $dataLvl ? 'data' + (($dataLvl-1)||'') : 'parentData'
  129. , $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
  130. }}
  131. #}}
  132. {{## def.passParentData:
  133. {{# def.setParentData }}
  134. , {{= $parentData }}
  135. , {{= $parentDataProperty }}
  136. #}}
  137. {{## def.iterateProperties:
  138. {{? $ownProperties }}
  139. {{=$dataProperties}} = {{=$dataProperties}} || Object.keys({{=$data}});
  140. for (var {{=$idx}}=0; {{=$idx}}<{{=$dataProperties}}.length; {{=$idx}}++) {
  141. var {{=$key}} = {{=$dataProperties}}[{{=$idx}}];
  142. {{??}}
  143. for (var {{=$key}} in {{=$data}}) {
  144. {{?}}
  145. #}}
  146. {{## def.noPropertyInData:
  147. {{=$useData}} === undefined
  148. {{? $ownProperties }}
  149. || !{{# def.isOwnProperty }}
  150. {{?}}
  151. #}}
  152. {{## def.isOwnProperty:
  153. Object.prototype.hasOwnProperty.call({{=$data}}, '{{=it.util.escapeQuotes($propertyKey)}}')
  154. #}}