選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

definitions.def 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. : it.util.schemaHasRules(_schema, it.RULES.all))
  54. #}}
  55. {{## def.strLength:
  56. {{? it.opts.unicode === false }}
  57. {{=$data}}.length
  58. {{??}}
  59. ucs2length({{=$data}})
  60. {{?}}
  61. #}}
  62. {{## def.willOptimize:
  63. it.util.varOccurences($code, $nextData) < 2
  64. #}}
  65. {{## def.generateSubschemaCode:
  66. {{
  67. var $code = it.validate($it);
  68. $it.baseId = $currentBaseId;
  69. }}
  70. #}}
  71. {{## def.insertSubschemaCode:
  72. {{= it.validate($it) }}
  73. {{ $it.baseId = $currentBaseId; }}
  74. #}}
  75. {{## def._optimizeValidate:
  76. it.util.varReplace($code, $nextData, $passData)
  77. #}}
  78. {{## def.optimizeValidate:
  79. {{? {{# def.willOptimize}} }}
  80. {{= {{# def._optimizeValidate }} }}
  81. {{??}}
  82. var {{=$nextData}} = {{=$passData}};
  83. {{= $code }}
  84. {{?}}
  85. #}}
  86. {{## def.cleanUp: {{ out = it.util.cleanUpCode(out); }} #}}
  87. {{## def.finalCleanUp: {{ out = it.util.finalCleanUpCode(out, $async); }} #}}
  88. {{## def.$data:
  89. {{
  90. var $isData = it.opts.$data && $schema && $schema.$data
  91. , $schemaValue;
  92. }}
  93. {{? $isData }}
  94. var schema{{=$lvl}} = {{= it.util.getData($schema.$data, $dataLvl, it.dataPathArr) }};
  95. {{ $schemaValue = 'schema' + $lvl; }}
  96. {{??}}
  97. {{ $schemaValue = $schema; }}
  98. {{?}}
  99. #}}
  100. {{## def.$dataNotType:_type:
  101. {{?$isData}} ({{=$schemaValue}} !== undefined && typeof {{=$schemaValue}} != _type) || {{?}}
  102. #}}
  103. {{## def.check$dataIsArray:
  104. if (schema{{=$lvl}} === undefined) {{=$valid}} = true;
  105. else if (!Array.isArray(schema{{=$lvl}})) {{=$valid}} = false;
  106. else {
  107. #}}
  108. {{## def.beginDefOut:
  109. {{
  110. var $$outStack = $$outStack || [];
  111. $$outStack.push(out);
  112. out = '';
  113. }}
  114. #}}
  115. {{## def.storeDefOut:_variable:
  116. {{
  117. var _variable = out;
  118. out = $$outStack.pop();
  119. }}
  120. #}}
  121. {{## def.dataPath:(dataPath || ''){{? it.errorPath != '""'}} + {{= it.errorPath }}{{?}}#}}
  122. {{## def.setParentData:
  123. {{
  124. var $parentData = $dataLvl ? 'data' + (($dataLvl-1)||'') : 'parentData'
  125. , $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
  126. }}
  127. #}}
  128. {{## def.passParentData:
  129. {{# def.setParentData }}
  130. , {{= $parentData }}
  131. , {{= $parentDataProperty }}
  132. #}}
  133. {{## def.iterateProperties:
  134. {{? $ownProperties }}
  135. {{=$dataProperties}} = {{=$dataProperties}} || Object.keys({{=$data}});
  136. for (var {{=$idx}}=0; {{=$idx}}<{{=$dataProperties}}.length; {{=$idx}}++) {
  137. var {{=$key}} = {{=$dataProperties}}[{{=$idx}}];
  138. {{??}}
  139. for (var {{=$key}} in {{=$data}}) {
  140. {{?}}
  141. #}}
  142. {{## def.noPropertyInData:
  143. {{=$useData}} === undefined
  144. {{? $ownProperties }}
  145. || !{{# def.isOwnProperty }}
  146. {{?}}
  147. #}}
  148. {{## def.isOwnProperty:
  149. Object.prototype.hasOwnProperty.call({{=$data}}, '{{=it.util.escapeQuotes($propertyKey)}}')
  150. #}}