twitst4tz

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

format.jst (3136B)


      1 {{# def.definitions }}
      2 {{# def.errors }}
      3 {{# def.setupKeyword }}
      4 
      5 {{## def.skipFormat:
      6   {{? $breakOnError }} if (true) { {{?}}
      7   {{ return out; }}
      8 #}}
      9 
     10 {{? it.opts.format === false }}{{# def.skipFormat }}{{?}}
     11 
     12 
     13 {{# def.$data }}
     14 
     15 
     16 {{## def.$dataCheckFormat:
     17   {{# def.$dataNotType:'string' }}
     18   ({{? $unknownFormats != 'ignore' }}
     19      ({{=$schemaValue}} && !{{=$format}}
     20       {{? $allowUnknown }}
     21         && self._opts.unknownFormats.indexOf({{=$schemaValue}}) == -1
     22       {{?}}) ||
     23    {{?}}
     24    ({{=$format}} && {{=$formatType}} == '{{=$ruleType}}'
     25                  && !(typeof {{=$format}} == 'function'
     26                      ? {{? it.async}}
     27                         (async{{=$lvl}} ? await {{=$format}}({{=$data}}) : {{=$format}}({{=$data}}))
     28                        {{??}}
     29                         {{=$format}}({{=$data}})
     30                        {{?}}
     31                      : {{=$format}}.test({{=$data}}))))
     32 #}}
     33 
     34 {{## def.checkFormat:
     35   {{
     36     var $formatRef = 'formats' + it.util.getProperty($schema);
     37     if ($isObject) $formatRef += '.validate';
     38   }}
     39   {{? typeof $format == 'function' }}
     40     {{=$formatRef}}({{=$data}})
     41   {{??}}
     42     {{=$formatRef}}.test({{=$data}})
     43   {{?}}
     44 #}}
     45 
     46 
     47 {{
     48   var $unknownFormats = it.opts.unknownFormats
     49     , $allowUnknown = Array.isArray($unknownFormats);
     50 }}
     51 
     52 {{? $isData }}
     53   {{
     54     var $format = 'format' + $lvl
     55       , $isObject = 'isObject' + $lvl
     56       , $formatType = 'formatType' + $lvl;
     57   }}
     58   var {{=$format}} = formats[{{=$schemaValue}}];
     59   var {{=$isObject}} = typeof {{=$format}} == 'object'
     60                         && !({{=$format}} instanceof RegExp)
     61                         && {{=$format}}.validate;
     62   var {{=$formatType}} = {{=$isObject}} && {{=$format}}.type || 'string';
     63   if ({{=$isObject}}) {
     64     {{? it.async}}
     65       var async{{=$lvl}} = {{=$format}}.async;
     66     {{?}}
     67     {{=$format}} = {{=$format}}.validate;
     68   }
     69   if ({{# def.$dataCheckFormat }}) {
     70 {{??}}
     71   {{ var $format = it.formats[$schema]; }}
     72   {{? !$format }}
     73     {{? $unknownFormats == 'ignore' }}
     74       {{ it.logger.warn('unknown format "' + $schema + '" ignored in schema at path "' + it.errSchemaPath + '"'); }}
     75       {{# def.skipFormat }}
     76     {{?? $allowUnknown && $unknownFormats.indexOf($schema) >= 0 }}
     77       {{# def.skipFormat }}
     78     {{??}}
     79       {{ throw new Error('unknown format "' + $schema + '" is used in schema at path "' + it.errSchemaPath + '"'); }}
     80     {{?}}
     81   {{?}}
     82   {{
     83     var $isObject = typeof $format == 'object'
     84                     && !($format instanceof RegExp)
     85                     && $format.validate;
     86     var $formatType = $isObject && $format.type || 'string';
     87     if ($isObject) {
     88       var $async = $format.async === true;
     89       $format = $format.validate;
     90     }
     91   }}
     92   {{? $formatType != $ruleType }}
     93     {{# def.skipFormat }}
     94   {{?}}
     95   {{? $async }}
     96     {{
     97       if (!it.async) throw new Error('async format in sync schema');
     98       var $formatRef = 'formats' + it.util.getProperty($schema) + '.validate';
     99     }}
    100     if (!(await {{=$formatRef}}({{=$data}}))) {
    101   {{??}}
    102     if (!{{# def.checkFormat }}) {
    103   {{?}}
    104 {{?}}
    105     {{# def.error:'format' }}
    106   } {{? $breakOnError }} else { {{?}}