[d565449] | 1 | {{# def.definitions }}
|
---|
| 2 | {{# def.errors }}
|
---|
| 3 | {{# def.setupKeyword }}
|
---|
| 4 | {{# def.$data }}
|
---|
| 5 |
|
---|
| 6 | {{## def.setExclusiveLimit:
|
---|
| 7 | $exclusive = true;
|
---|
| 8 | $errorKeyword = $exclusiveKeyword;
|
---|
| 9 | $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
|
---|
| 10 | #}}
|
---|
| 11 |
|
---|
| 12 | {{
|
---|
| 13 | var $isMax = $keyword == 'maximum'
|
---|
| 14 | , $exclusiveKeyword = $isMax ? 'exclusiveMaximum' : 'exclusiveMinimum'
|
---|
| 15 | , $schemaExcl = it.schema[$exclusiveKeyword]
|
---|
| 16 | , $isDataExcl = it.opts.$data && $schemaExcl && $schemaExcl.$data
|
---|
| 17 | , $op = $isMax ? '<' : '>'
|
---|
| 18 | , $notOp = $isMax ? '>' : '<'
|
---|
| 19 | , $errorKeyword = undefined;
|
---|
| 20 |
|
---|
| 21 | if (!($isData || typeof $schema == 'number' || $schema === undefined)) {
|
---|
| 22 | throw new Error($keyword + ' must be number');
|
---|
| 23 | }
|
---|
| 24 | if (!($isDataExcl || $schemaExcl === undefined
|
---|
| 25 | || typeof $schemaExcl == 'number'
|
---|
| 26 | || typeof $schemaExcl == 'boolean')) {
|
---|
| 27 | throw new Error($exclusiveKeyword + ' must be number or boolean');
|
---|
| 28 | }
|
---|
| 29 | }}
|
---|
| 30 |
|
---|
| 31 | {{? $isDataExcl }}
|
---|
| 32 | {{
|
---|
| 33 | var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr)
|
---|
| 34 | , $exclusive = 'exclusive' + $lvl
|
---|
| 35 | , $exclType = 'exclType' + $lvl
|
---|
| 36 | , $exclIsNumber = 'exclIsNumber' + $lvl
|
---|
| 37 | , $opExpr = 'op' + $lvl
|
---|
| 38 | , $opStr = '\' + ' + $opExpr + ' + \'';
|
---|
| 39 | }}
|
---|
| 40 | var schemaExcl{{=$lvl}} = {{=$schemaValueExcl}};
|
---|
| 41 | {{ $schemaValueExcl = 'schemaExcl' + $lvl; }}
|
---|
| 42 |
|
---|
| 43 | var {{=$exclusive}};
|
---|
| 44 | var {{=$exclType}} = typeof {{=$schemaValueExcl}};
|
---|
| 45 | if ({{=$exclType}} != 'boolean' && {{=$exclType}} != 'undefined' && {{=$exclType}} != 'number') {
|
---|
| 46 | {{ var $errorKeyword = $exclusiveKeyword; }}
|
---|
| 47 | {{# def.error:'_exclusiveLimit' }}
|
---|
| 48 | } else if ({{# def.$dataNotType:'number' }}
|
---|
| 49 | {{=$exclType}} == 'number'
|
---|
| 50 | ? (
|
---|
| 51 | ({{=$exclusive}} = {{=$schemaValue}} === undefined || {{=$schemaValueExcl}} {{=$op}}= {{=$schemaValue}})
|
---|
| 52 | ? {{=$data}} {{=$notOp}}= {{=$schemaValueExcl}}
|
---|
| 53 | : {{=$data}} {{=$notOp}} {{=$schemaValue}}
|
---|
| 54 | )
|
---|
| 55 | : (
|
---|
| 56 | ({{=$exclusive}} = {{=$schemaValueExcl}} === true)
|
---|
| 57 | ? {{=$data}} {{=$notOp}}= {{=$schemaValue}}
|
---|
| 58 | : {{=$data}} {{=$notOp}} {{=$schemaValue}}
|
---|
| 59 | )
|
---|
| 60 | || {{=$data}} !== {{=$data}}) {
|
---|
| 61 | var op{{=$lvl}} = {{=$exclusive}} ? '{{=$op}}' : '{{=$op}}=';
|
---|
| 62 | {{
|
---|
| 63 | if ($schema === undefined) {
|
---|
| 64 | $errorKeyword = $exclusiveKeyword;
|
---|
| 65 | $errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
|
---|
| 66 | $schemaValue = $schemaValueExcl;
|
---|
| 67 | $isData = $isDataExcl;
|
---|
| 68 | }
|
---|
| 69 | }}
|
---|
| 70 | {{??}}
|
---|
| 71 | {{
|
---|
| 72 | var $exclIsNumber = typeof $schemaExcl == 'number'
|
---|
| 73 | , $opStr = $op; /*used in error*/
|
---|
| 74 | }}
|
---|
| 75 |
|
---|
| 76 | {{? $exclIsNumber && $isData }}
|
---|
| 77 | {{ var $opExpr = '\'' + $opStr + '\''; /*used in error*/ }}
|
---|
| 78 | if ({{# def.$dataNotType:'number' }}
|
---|
| 79 | ( {{=$schemaValue}} === undefined
|
---|
| 80 | || {{=$schemaExcl}} {{=$op}}= {{=$schemaValue}}
|
---|
| 81 | ? {{=$data}} {{=$notOp}}= {{=$schemaExcl}}
|
---|
| 82 | : {{=$data}} {{=$notOp}} {{=$schemaValue}} )
|
---|
| 83 | || {{=$data}} !== {{=$data}}) {
|
---|
| 84 | {{??}}
|
---|
| 85 | {{
|
---|
| 86 | if ($exclIsNumber && $schema === undefined) {
|
---|
| 87 | {{# def.setExclusiveLimit }}
|
---|
| 88 | $schemaValue = $schemaExcl;
|
---|
| 89 | $notOp += '=';
|
---|
| 90 | } else {
|
---|
| 91 | if ($exclIsNumber)
|
---|
| 92 | $schemaValue = Math[$isMax ? 'min' : 'max']($schemaExcl, $schema);
|
---|
| 93 |
|
---|
| 94 | if ($schemaExcl === ($exclIsNumber ? $schemaValue : true)) {
|
---|
| 95 | {{# def.setExclusiveLimit }}
|
---|
| 96 | $notOp += '=';
|
---|
| 97 | } else {
|
---|
| 98 | $exclusive = false;
|
---|
| 99 | $opStr += '=';
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | var $opExpr = '\'' + $opStr + '\''; /*used in error*/
|
---|
| 104 | }}
|
---|
| 105 |
|
---|
| 106 | if ({{# def.$dataNotType:'number' }}
|
---|
| 107 | {{=$data}} {{=$notOp}} {{=$schemaValue}}
|
---|
| 108 | || {{=$data}} !== {{=$data}}) {
|
---|
| 109 | {{?}}
|
---|
| 110 | {{?}}
|
---|
| 111 | {{ $errorKeyword = $errorKeyword || $keyword; }}
|
---|
| 112 | {{# def.error:'_limit' }}
|
---|
| 113 | } {{? $breakOnError }} else { {{?}}
|
---|