BVB Source Codes

reactide Show format.js Source code

Return Download reactide: download format.js Source code - Download reactide Source code - Type:.js
  1. 'use strict';
  2. module.exports = function generate_format(it, $keyword) {
  3.   var out = ' ';
  4.   var $lvl = it.level;
  5.   var $dataLvl = it.dataLevel;
  6.   var $schema = it.schema[$keyword];
  7.   var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  8.   var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  9.   var $breakOnError = !it.opts.allErrors;
  10.   var $errorKeyword;
  11.   var $data = 'data' + ($dataLvl || '');
  12.   if (it.opts.format === false) {
  13.     if ($breakOnError) {
  14.       out += ' if (true) { ';
  15.     }
  16.     return out;
  17.   }
  18.   var $isData = it.opts.v5 && $schema && $schema.$data,
  19.     $schemaValue;
  20.   if ($isData) {
  21.     out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  22.     $schemaValue = 'schema' + $lvl;
  23.   } else {
  24.     $schemaValue = $schema;
  25.   }
  26.   var $unknownFormats = it.opts.unknownFormats,
  27.     $allowUnknown = Array.isArray($unknownFormats);
  28.   if ($isData) {
  29.     var $format = 'format' + $lvl;
  30.     out += ' var ' + ($format) + ' = formats[' + ($schemaValue) + ']; var isObject' + ($lvl) + ' = typeof ' + ($format) + ' == \'object\' && !(' + ($format) + ' instanceof RegExp) && ' + ($format) + '.validate; if (isObject' + ($lvl) + ') { ';
  31.     if (it.async) {
  32.       out += ' var async' + ($lvl) + ' = ' + ($format) + '.async; ';
  33.     }
  34.     out += ' ' + ($format) + ' = ' + ($format) + '.validate; } if (  ';
  35.     if ($isData) {
  36.       out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || ';
  37.     }
  38.     out += ' (';
  39.     if ($unknownFormats === true || $allowUnknown) {
  40.       out += ' (' + ($schemaValue) + ' && !' + ($format) + ' ';
  41.       if ($allowUnknown) {
  42.         out += ' && self._opts.unknownFormats.indexOf(' + ($schemaValue) + ') == -1 ';
  43.       }
  44.       out += ') || ';
  45.     }
  46.     out += ' (' + ($format) + ' && !(typeof ' + ($format) + ' == \'function\' ? ';
  47.     if (it.async) {
  48.       out += ' (async' + ($lvl) + ' ? ' + (it.yieldAwait) + ' ' + ($format) + '(' + ($data) + ') : ' + ($format) + '(' + ($data) + ')) ';
  49.     } else {
  50.       out += ' ' + ($format) + '(' + ($data) + ') ';
  51.     }
  52.     out += ' : ' + ($format) + '.test(' + ($data) + '))))) {';
  53.   } else {
  54.     var $format = it.formats[$schema];
  55.     if (!$format) {
  56.       if ($unknownFormats === true || ($allowUnknown && $unknownFormats.indexOf($schema) == -1)) {
  57.         throw new Error('unknown format "' + $schema + '" is used in schema at path "' + it.errSchemaPath + '"');
  58.       } else {
  59.         if (!$allowUnknown) {
  60.           console.warn('unknown format "' + $schema + '" ignored in schema at path "' + it.errSchemaPath + '"');
  61.           if ($unknownFormats !== 'ignore') console.warn('In the next major version it will throw exception. See option unknownFormats for more information');
  62.         }
  63.         if ($breakOnError) {
  64.           out += ' if (true) { ';
  65.         }
  66.         return out;
  67.       }
  68.     }
  69.     var $isObject = typeof $format == 'object' && !($format instanceof RegExp) && $format.validate;
  70.     if ($isObject) {
  71.       var $async = $format.async === true;
  72.       $format = $format.validate;
  73.     }
  74.     if ($async) {
  75.       if (!it.async) throw new Error('async format in sync schema');
  76.       var $formatRef = 'formats' + it.util.getProperty($schema) + '.validate';
  77.       out += ' if (!(' + (it.yieldAwait) + ' ' + ($formatRef) + '(' + ($data) + '))) { ';
  78.     } else {
  79.       out += ' if (! ';
  80.       var $formatRef = 'formats' + it.util.getProperty($schema);
  81.       if ($isObject) $formatRef += '.validate';
  82.       if (typeof $format == 'function') {
  83.         out += ' ' + ($formatRef) + '(' + ($data) + ') ';
  84.       } else {
  85.         out += ' ' + ($formatRef) + '.test(' + ($data) + ') ';
  86.       }
  87.       out += ') { ';
  88.     }
  89.   }
  90.   var $$outStack = $$outStack || [];
  91.   $$outStack.push(out);
  92.   out = ''; /* istanbul ignore else */
  93.   if (it.createErrors !== false) {
  94.     out += ' { keyword: \'' + ($errorKeyword || 'format') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { format:  ';
  95.     if ($isData) {
  96.       out += '' + ($schemaValue);
  97.     } else {
  98.       out += '' + (it.util.toQuotedString($schema));
  99.     }
  100.     out += '  } ';
  101.     if (it.opts.messages !== false) {
  102.       out += ' , message: \'should match format "';
  103.       if ($isData) {
  104.         out += '\' + ' + ($schemaValue) + ' + \'';
  105.       } else {
  106.         out += '' + (it.util.escapeQuotes($schema));
  107.       }
  108.       out += '"\' ';
  109.     }
  110.     if (it.opts.verbose) {
  111.       out += ' , schema:  ';
  112.       if ($isData) {
  113.         out += 'validate.schema' + ($schemaPath);
  114.       } else {
  115.         out += '' + (it.util.toQuotedString($schema));
  116.       }
  117.       out += '         , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  118.     }
  119.     out += ' } ';
  120.   } else {
  121.     out += ' {} ';
  122.   }
  123.   var __err = out;
  124.   out = $$outStack.pop();
  125.   if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  126.     if (it.async) {
  127.       out += ' throw new ValidationError([' + (__err) + ']); ';
  128.     } else {
  129.       out += ' validate.errors = [' + (__err) + ']; return false; ';
  130.     }
  131.   } else {
  132.     out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  133.   }
  134.   out += ' } ';
  135.   if ($breakOnError) {
  136.     out += ' else { ';
  137.   }
  138.   return out;
  139. }
  140.  
downloadformat.js Source code - Download reactide Source code
Related Source Codes/Software:
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
postal - 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top