twitst4tz

twitter statistics web application
Log | Files | Refs | README | LICENSE

definitions.def (3990B)


      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     : it.util.schemaHasRules(_schema, it.RULES.all))
     69 #}}
     70 
     71 
     72 {{## def.strLength:
     73   {{? it.opts.unicode === false }}
     74     {{=$data}}.length
     75   {{??}}
     76     ucs2length({{=$data}})
     77   {{?}}
     78 #}}
     79 
     80 
     81 {{## def.willOptimize:
     82   it.util.varOccurences($code, $nextData) < 2
     83 #}}
     84 
     85 
     86 {{## def.generateSubschemaCode:
     87   {{
     88     var $code = it.validate($it);
     89     $it.baseId = $currentBaseId;
     90   }}
     91 #}}
     92 
     93 
     94 {{## def.insertSubschemaCode:
     95   {{= it.validate($it) }}
     96   {{ $it.baseId = $currentBaseId; }}
     97 #}}
     98 
     99 
    100 {{## def._optimizeValidate:
    101   it.util.varReplace($code, $nextData, $passData)
    102 #}}
    103 
    104 
    105 {{## def.optimizeValidate:
    106   {{? {{# def.willOptimize}} }}
    107     {{= {{# def._optimizeValidate }} }}
    108   {{??}}
    109     var {{=$nextData}} = {{=$passData}};
    110     {{= $code }}
    111   {{?}}
    112 #}}
    113 
    114 
    115 {{## def.cleanUp: {{ out = it.util.cleanUpCode(out); }} #}}
    116 
    117 
    118 {{## def.finalCleanUp: {{ out = it.util.finalCleanUpCode(out, $async); }} #}}
    119 
    120 
    121 {{## def.$data:
    122   {{
    123     var $isData = it.opts.$data && $schema && $schema.$data
    124       , $schemaValue;
    125   }}
    126   {{? $isData }}
    127     var schema{{=$lvl}} = {{= it.util.getData($schema.$data, $dataLvl, it.dataPathArr) }};
    128     {{ $schemaValue = 'schema' + $lvl; }}
    129   {{??}}
    130     {{ $schemaValue = $schema; }}
    131   {{?}}
    132 #}}
    133 
    134 
    135 {{## def.$dataNotType:_type:
    136   {{?$isData}} ({{=$schemaValue}} !== undefined && typeof {{=$schemaValue}} != _type) || {{?}}
    137 #}}
    138 
    139 
    140 {{## def.check$dataIsArray:
    141   if (schema{{=$lvl}} === undefined) {{=$valid}} = true;
    142   else if (!Array.isArray(schema{{=$lvl}})) {{=$valid}} = false;
    143   else {
    144 #}}
    145 
    146 
    147 {{## def.beginDefOut:
    148   {{
    149     var $$outStack = $$outStack || [];
    150     $$outStack.push(out);
    151     out = '';
    152   }}
    153 #}}
    154 
    155 
    156 {{## def.storeDefOut:_variable:
    157   {{
    158     var _variable = out;
    159     out = $$outStack.pop();
    160   }}
    161 #}}
    162 
    163 
    164 {{## def.dataPath:(dataPath || ''){{? it.errorPath != '""'}} + {{= it.errorPath }}{{?}}#}}
    165 
    166 {{## def.setParentData:
    167   {{
    168     var $parentData = $dataLvl ? 'data' + (($dataLvl-1)||'') : 'parentData'
    169       , $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
    170   }}
    171 #}}
    172 
    173 {{## def.passParentData:
    174   {{# def.setParentData }}
    175   , {{= $parentData }}
    176   , {{= $parentDataProperty }}
    177 #}}
    178 
    179 
    180 {{## def.iterateProperties:
    181   {{? $ownProperties }}
    182     {{=$dataProperties}} = {{=$dataProperties}} || Object.keys({{=$data}});
    183     for (var {{=$idx}}=0; {{=$idx}}<{{=$dataProperties}}.length; {{=$idx}}++) {
    184       var {{=$key}} = {{=$dataProperties}}[{{=$idx}}];
    185   {{??}}
    186     for (var {{=$key}} in {{=$data}}) {
    187   {{?}}
    188 #}}
    189 
    190 
    191 {{## def.noPropertyInData:
    192   {{=$useData}} === undefined
    193   {{? $ownProperties }}
    194     || !{{# def.isOwnProperty }}
    195   {{?}}
    196 #}}
    197 
    198 
    199 {{## def.isOwnProperty:
    200   Object.prototype.hasOwnProperty.call({{=$data}}, '{{=it.util.escapeQuotes($propertyKey)}}')
    201 #}}