Initial commit
[yaffs-website] / node_modules / ajv / lib / dot / format.jst
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 === true || $allowUnknown }}
19      ({{=$schemaValue}} && !{{=$format}}
20       {{? $allowUnknown }}
21         && self._opts.unknownFormats.indexOf({{=$schemaValue}}) == -1
22       {{?}}) ||
23    {{?}}
24    ({{=$format}} && !(typeof {{=$format}} == 'function'
25                      ? {{? it.async}}
26                         (async{{=$lvl}} ? {{=it.yieldAwait}} {{=$format}}({{=$data}}) : {{=$format}}({{=$data}}))
27                        {{??}}
28                         {{=$format}}({{=$data}})
29                        {{?}}
30                      : {{=$format}}.test({{=$data}}))))
31 #}}
32
33 {{## def.checkFormat:
34   {{
35     var $formatRef = 'formats' + it.util.getProperty($schema);
36     if ($isObject) $formatRef += '.validate';
37   }}
38   {{? typeof $format == 'function' }}
39     {{=$formatRef}}({{=$data}})
40   {{??}}
41     {{=$formatRef}}.test({{=$data}})
42   {{?}}
43 #}}
44
45
46 {{
47   var $unknownFormats = it.opts.unknownFormats
48     , $allowUnknown = Array.isArray($unknownFormats);
49 }}
50
51 {{? $isData }}
52   {{ var $format = 'format' + $lvl; }}
53   var {{=$format}} = formats[{{=$schemaValue}}];
54   var isObject{{=$lvl}} = typeof {{=$format}} == 'object'
55                           && !({{=$format}} instanceof RegExp)
56                           && {{=$format}}.validate;
57   if (isObject{{=$lvl}}) {
58     {{? it.async}}
59       var async{{=$lvl}} = {{=$format}}.async;
60     {{?}}
61     {{=$format}} = {{=$format}}.validate;
62   }
63   if ({{# def.$dataCheckFormat }}) {
64 {{??}}
65   {{ var $format = it.formats[$schema]; }}
66   {{? !$format }}
67     {{? $unknownFormats === true || ($allowUnknown && $unknownFormats.indexOf($schema) == -1) }}
68       {{ throw new Error('unknown format "' + $schema + '" is used in schema at path "' + it.errSchemaPath + '"'); }}
69     {{??}}
70       {{
71         if (!$allowUnknown) {
72           console.warn('unknown format "' + $schema + '" ignored in schema at path "' + it.errSchemaPath + '"');
73           if ($unknownFormats !== 'ignore')
74             console.warn('In the next major version it will throw exception. See option unknownFormats for more information');
75         }
76       }}
77       {{# def.skipFormat }}
78     {{?}}
79   {{?}}
80   {{
81     var $isObject = typeof $format == 'object'
82                     && !($format instanceof RegExp)
83                     && $format.validate;
84     if ($isObject) {
85       var $async = $format.async === true;
86       $format = $format.validate;
87     }
88   }}
89   {{? $async }}
90     {{
91       if (!it.async) throw new Error('async format in sync schema');
92       var $formatRef = 'formats' + it.util.getProperty($schema) + '.validate';
93     }}
94     if (!({{=it.yieldAwait}} {{=$formatRef}}({{=$data}}))) {
95   {{??}}
96     if (!{{# def.checkFormat }}) {
97   {{?}}
98 {{?}}
99     {{# def.error:'format' }}
100   } {{? $breakOnError }} else { {{?}}