3 {{# def.setupKeyword }}
6 {{? $breakOnError }} if (true) { {{?}}
10 {{? it.opts.format === false }}{{# def.skipFormat }}{{?}}
16 {{## def.$dataCheckFormat:
17 {{# def.$dataNotType:'string' }}
18 ({{? $unknownFormats != 'ignore' }}
19 ({{=$schemaValue}} && !{{=$format}}
21 && self._opts.unknownFormats.indexOf({{=$schemaValue}}) == -1
24 ({{=$format}} && {{=$formatType}} == '{{=$ruleType}}'
25 && !(typeof {{=$format}} == 'function'
27 (async{{=$lvl}} ? await {{=$format}}({{=$data}}) : {{=$format}}({{=$data}}))
29 {{=$format}}({{=$data}})
31 : {{=$format}}.test({{=$data}}))))
36 var $formatRef = 'formats' + it.util.getProperty($schema);
37 if ($isObject) $formatRef += '.validate';
39 {{? typeof $format == 'function' }}
40 {{=$formatRef}}({{=$data}})
42 {{=$formatRef}}.test({{=$data}})
48 var $unknownFormats = it.opts.unknownFormats
49 , $allowUnknown = Array.isArray($unknownFormats);
54 var $format = 'format' + $lvl
55 , $isObject = 'isObject' + $lvl
56 , $formatType = 'formatType' + $lvl;
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';
65 var async{{=$lvl}} = {{=$format}}.async;
67 {{=$format}} = {{=$format}}.validate;
69 if ({{# def.$dataCheckFormat }}) {
71 {{ var $format = it.formats[$schema]; }}
73 {{? $unknownFormats == 'ignore' }}
74 {{ it.logger.warn('unknown format "' + $schema + '" ignored in schema at path "' + it.errSchemaPath + '"'); }}
76 {{?? $allowUnknown && $unknownFormats.indexOf($schema) >= 0 }}
79 {{ throw new Error('unknown format "' + $schema + '" is used in schema at path "' + it.errSchemaPath + '"'); }}
83 var $isObject = typeof $format == 'object'
84 && !($format instanceof RegExp)
86 var $formatType = $isObject && $format.type || 'string';
88 var $async = $format.async === true;
89 $format = $format.validate;
92 {{? $formatType != $ruleType }}
97 if (!it.async) throw new Error('async format in sync schema');
98 var $formatRef = 'formats' + it.util.getProperty($schema) + '.validate';
100 if (!(await {{=$formatRef}}({{=$data}}))) {
102 if (!{{# def.checkFormat }}) {
105 {{# def.error:'format' }}
106 } {{? $breakOnError }} else { {{?}}