[d565449] | 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 |
|
---|
| 11 | var $data = 'data' + ($dataLvl || '');
|
---|
| 12 | var $valid = 'valid' + $lvl;
|
---|
| 13 | var $errs = 'errs__' + $lvl;
|
---|
| 14 | }}
|
---|
| 15 | #}}
|
---|
| 16 |
|
---|
| 17 |
|
---|
| 18 | {{## def.setCompositeRule:
|
---|
| 19 | {{
|
---|
| 20 | var $wasComposite = it.compositeRule;
|
---|
| 21 | it.compositeRule = $it.compositeRule = true;
|
---|
| 22 | }}
|
---|
| 23 | #}}
|
---|
| 24 |
|
---|
| 25 |
|
---|
| 26 | {{## def.resetCompositeRule:
|
---|
| 27 | {{ it.compositeRule = $it.compositeRule = $wasComposite; }}
|
---|
| 28 | #}}
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | {{## def.setupNextLevel:
|
---|
| 32 | {{
|
---|
| 33 | var $it = it.util.copy(it);
|
---|
| 34 | var $closingBraces = '';
|
---|
| 35 | $it.level++;
|
---|
| 36 | var $nextValid = 'valid' + $it.level;
|
---|
| 37 | }}
|
---|
| 38 | #}}
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 | {{## def.ifValid:
|
---|
| 42 | {{? $breakOnError }}
|
---|
| 43 | if ({{=$valid}}) {
|
---|
| 44 | {{ $closingBraces += '}'; }}
|
---|
| 45 | {{?}}
|
---|
| 46 | #}}
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | {{## def.ifResultValid:
|
---|
| 50 | {{? $breakOnError }}
|
---|
| 51 | if ({{=$nextValid}}) {
|
---|
| 52 | {{ $closingBraces += '}'; }}
|
---|
| 53 | {{?}}
|
---|
| 54 | #}}
|
---|
| 55 |
|
---|
| 56 |
|
---|
| 57 | {{## def.elseIfValid:
|
---|
| 58 | {{? $breakOnError }}
|
---|
| 59 | {{ $closingBraces += '}'; }}
|
---|
| 60 | else {
|
---|
| 61 | {{?}}
|
---|
| 62 | #}}
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 | {{## def.nonEmptySchema:_schema:
|
---|
| 66 | (it.opts.strictKeywords
|
---|
| 67 | ? (typeof _schema == 'object' && Object.keys(_schema).length > 0)
|
---|
| 68 | || _schema === false
|
---|
| 69 | : it.util.schemaHasRules(_schema, it.RULES.all))
|
---|
| 70 | #}}
|
---|
| 71 |
|
---|
| 72 |
|
---|
| 73 | {{## def.strLength:
|
---|
| 74 | {{? it.opts.unicode === false }}
|
---|
| 75 | {{=$data}}.length
|
---|
| 76 | {{??}}
|
---|
| 77 | ucs2length({{=$data}})
|
---|
| 78 | {{?}}
|
---|
| 79 | #}}
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 | {{## def.willOptimize:
|
---|
| 83 | it.util.varOccurences($code, $nextData) < 2
|
---|
| 84 | #}}
|
---|
| 85 |
|
---|
| 86 |
|
---|
| 87 | {{## def.generateSubschemaCode:
|
---|
| 88 | {{
|
---|
| 89 | var $code = it.validate($it);
|
---|
| 90 | $it.baseId = $currentBaseId;
|
---|
| 91 | }}
|
---|
| 92 | #}}
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 | {{## def.insertSubschemaCode:
|
---|
| 96 | {{= it.validate($it) }}
|
---|
| 97 | {{ $it.baseId = $currentBaseId; }}
|
---|
| 98 | #}}
|
---|
| 99 |
|
---|
| 100 |
|
---|
| 101 | {{## def._optimizeValidate:
|
---|
| 102 | it.util.varReplace($code, $nextData, $passData)
|
---|
| 103 | #}}
|
---|
| 104 |
|
---|
| 105 |
|
---|
| 106 | {{## def.optimizeValidate:
|
---|
| 107 | {{? {{# def.willOptimize}} }}
|
---|
| 108 | {{= {{# def._optimizeValidate }} }}
|
---|
| 109 | {{??}}
|
---|
| 110 | var {{=$nextData}} = {{=$passData}};
|
---|
| 111 | {{= $code }}
|
---|
| 112 | {{?}}
|
---|
| 113 | #}}
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | {{## def.$data:
|
---|
| 117 | {{
|
---|
| 118 | var $isData = it.opts.$data && $schema && $schema.$data
|
---|
| 119 | , $schemaValue;
|
---|
| 120 | }}
|
---|
| 121 | {{? $isData }}
|
---|
| 122 | var schema{{=$lvl}} = {{= it.util.getData($schema.$data, $dataLvl, it.dataPathArr) }};
|
---|
| 123 | {{ $schemaValue = 'schema' + $lvl; }}
|
---|
| 124 | {{??}}
|
---|
| 125 | {{ $schemaValue = $schema; }}
|
---|
| 126 | {{?}}
|
---|
| 127 | #}}
|
---|
| 128 |
|
---|
| 129 |
|
---|
| 130 | {{## def.$dataNotType:_type:
|
---|
| 131 | {{?$isData}} ({{=$schemaValue}} !== undefined && typeof {{=$schemaValue}} != _type) || {{?}}
|
---|
| 132 | #}}
|
---|
| 133 |
|
---|
| 134 |
|
---|
| 135 | {{## def.check$dataIsArray:
|
---|
| 136 | if (schema{{=$lvl}} === undefined) {{=$valid}} = true;
|
---|
| 137 | else if (!Array.isArray(schema{{=$lvl}})) {{=$valid}} = false;
|
---|
| 138 | else {
|
---|
| 139 | #}}
|
---|
| 140 |
|
---|
| 141 |
|
---|
| 142 | {{## def.numberKeyword:
|
---|
| 143 | {{? !($isData || typeof $schema == 'number') }}
|
---|
| 144 | {{ throw new Error($keyword + ' must be number'); }}
|
---|
| 145 | {{?}}
|
---|
| 146 | #}}
|
---|
| 147 |
|
---|
| 148 |
|
---|
| 149 | {{## def.beginDefOut:
|
---|
| 150 | {{
|
---|
| 151 | var $$outStack = $$outStack || [];
|
---|
| 152 | $$outStack.push(out);
|
---|
| 153 | out = '';
|
---|
| 154 | }}
|
---|
| 155 | #}}
|
---|
| 156 |
|
---|
| 157 |
|
---|
| 158 | {{## def.storeDefOut:_variable:
|
---|
| 159 | {{
|
---|
| 160 | var _variable = out;
|
---|
| 161 | out = $$outStack.pop();
|
---|
| 162 | }}
|
---|
| 163 | #}}
|
---|
| 164 |
|
---|
| 165 |
|
---|
| 166 | {{## def.dataPath:(dataPath || ''){{? it.errorPath != '""'}} + {{= it.errorPath }}{{?}}#}}
|
---|
| 167 |
|
---|
| 168 | {{## def.setParentData:
|
---|
| 169 | {{
|
---|
| 170 | var $parentData = $dataLvl ? 'data' + (($dataLvl-1)||'') : 'parentData'
|
---|
| 171 | , $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
|
---|
| 172 | }}
|
---|
| 173 | #}}
|
---|
| 174 |
|
---|
| 175 | {{## def.passParentData:
|
---|
| 176 | {{# def.setParentData }}
|
---|
| 177 | , {{= $parentData }}
|
---|
| 178 | , {{= $parentDataProperty }}
|
---|
| 179 | #}}
|
---|
| 180 |
|
---|
| 181 |
|
---|
| 182 | {{## def.iterateProperties:
|
---|
| 183 | {{? $ownProperties }}
|
---|
| 184 | {{=$dataProperties}} = {{=$dataProperties}} || Object.keys({{=$data}});
|
---|
| 185 | for (var {{=$idx}}=0; {{=$idx}}<{{=$dataProperties}}.length; {{=$idx}}++) {
|
---|
| 186 | var {{=$key}} = {{=$dataProperties}}[{{=$idx}}];
|
---|
| 187 | {{??}}
|
---|
| 188 | for (var {{=$key}} in {{=$data}}) {
|
---|
| 189 | {{?}}
|
---|
| 190 | #}}
|
---|
| 191 |
|
---|
| 192 |
|
---|
| 193 | {{## def.noPropertyInData:
|
---|
| 194 | {{=$useData}} === undefined
|
---|
| 195 | {{? $ownProperties }}
|
---|
| 196 | || !{{# def.isOwnProperty }}
|
---|
| 197 | {{?}}
|
---|
| 198 | #}}
|
---|
| 199 |
|
---|
| 200 |
|
---|
| 201 | {{## def.isOwnProperty:
|
---|
| 202 | Object.prototype.hasOwnProperty.call({{=$data}}, '{{=it.util.escapeQuotes($propertyKey)}}')
|
---|
| 203 | #}}
|
---|