2 module.exports = function generate__limit(it, $keyword) {
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;
11 var $data = 'data' + ($dataLvl || '');
12 var $isData = it.opts.v5 && $schema && $schema.$data,
15 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
16 $schemaValue = 'schema' + $lvl;
18 $schemaValue = $schema;
20 var $isMax = $keyword == 'maximum',
21 $exclusiveKeyword = $isMax ? 'exclusiveMaximum' : 'exclusiveMinimum',
22 $schemaExcl = it.schema[$exclusiveKeyword],
23 $isDataExcl = it.opts.v5 && $schemaExcl && $schemaExcl.$data,
24 $op = $isMax ? '<' : '>',
25 $notOp = $isMax ? '>' : '<';
27 var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr),
28 $exclusive = 'exclusive' + $lvl,
29 $opExpr = 'op' + $lvl,
30 $opStr = '\' + ' + $opExpr + ' + \'';
31 out += ' var schemaExcl' + ($lvl) + ' = ' + ($schemaValueExcl) + '; ';
32 $schemaValueExcl = 'schemaExcl' + $lvl;
33 out += ' var exclusive' + ($lvl) + '; if (typeof ' + ($schemaValueExcl) + ' != \'boolean\' && typeof ' + ($schemaValueExcl) + ' != \'undefined\') { ';
34 var $errorKeyword = $exclusiveKeyword;
35 var $$outStack = $$outStack || [];
37 out = ''; /* istanbul ignore else */
38 if (it.createErrors !== false) {
39 out += ' { keyword: \'' + ($errorKeyword || '_exclusiveLimit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
40 if (it.opts.messages !== false) {
41 out += ' , message: \'' + ($exclusiveKeyword) + ' should be boolean\' ';
43 if (it.opts.verbose) {
44 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
51 out = $$outStack.pop();
52 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
54 out += ' throw new ValidationError([' + (__err) + ']); ';
56 out += ' validate.errors = [' + (__err) + ']; return false; ';
59 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
61 out += ' } else if( ';
63 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
65 out += ' ((exclusive' + ($lvl) + ' = ' + ($schemaValueExcl) + ' === true) ? ' + ($data) + ' ' + ($notOp) + '= ' + ($schemaValue) + ' : ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ') || ' + ($data) + ' !== ' + ($data) + ') { var op' + ($lvl) + ' = exclusive' + ($lvl) + ' ? \'' + ($op) + '\' : \'' + ($op) + '=\';';
67 var $exclusive = $schemaExcl === true,
69 if (!$exclusive) $opStr += '=';
70 var $opExpr = '\'' + $opStr + '\'';
73 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
75 out += ' ' + ($data) + ' ' + ($notOp);
79 out += ' ' + ($schemaValue) + ' || ' + ($data) + ' !== ' + ($data) + ') {';
81 var $errorKeyword = $keyword;
82 var $$outStack = $$outStack || [];
84 out = ''; /* istanbul ignore else */
85 if (it.createErrors !== false) {
86 out += ' { keyword: \'' + ($errorKeyword || '_limit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { comparison: ' + ($opExpr) + ', limit: ' + ($schemaValue) + ', exclusive: ' + ($exclusive) + ' } ';
87 if (it.opts.messages !== false) {
88 out += ' , message: \'should be ' + ($opStr) + ' ';
90 out += '\' + ' + ($schemaValue);
92 out += '' + ($schema) + '\'';
95 if (it.opts.verbose) {
98 out += 'validate.schema' + ($schemaPath);
100 out += '' + ($schema);
102 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
109 out = $$outStack.pop();
110 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
112 out += ' throw new ValidationError([' + (__err) + ']); ';
114 out += ' validate.errors = [' + (__err) + ']; return false; ';
117 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';