main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.7 KB
|
Rev | Line | |
---|
[d565449] | 1 | {{# def.definitions }}
|
---|
| 2 | {{# def.errors }}
|
---|
| 3 | {{# def.setupKeyword }}
|
---|
| 4 | {{# def.$data }}
|
---|
| 5 |
|
---|
| 6 |
|
---|
| 7 | {{? ($schema || $isData) && it.opts.uniqueItems !== false }}
|
---|
| 8 | {{? $isData }}
|
---|
| 9 | var {{=$valid}};
|
---|
| 10 | if ({{=$schemaValue}} === false || {{=$schemaValue}} === undefined)
|
---|
| 11 | {{=$valid}} = true;
|
---|
| 12 | else if (typeof {{=$schemaValue}} != 'boolean')
|
---|
| 13 | {{=$valid}} = false;
|
---|
| 14 | else {
|
---|
| 15 | {{?}}
|
---|
| 16 |
|
---|
| 17 | var i = {{=$data}}.length
|
---|
| 18 | , {{=$valid}} = true
|
---|
| 19 | , j;
|
---|
| 20 | if (i > 1) {
|
---|
| 21 | {{
|
---|
| 22 | var $itemType = it.schema.items && it.schema.items.type
|
---|
| 23 | , $typeIsArray = Array.isArray($itemType);
|
---|
| 24 | }}
|
---|
| 25 | {{? !$itemType || $itemType == 'object' || $itemType == 'array' ||
|
---|
| 26 | ($typeIsArray && ($itemType.indexOf('object') >= 0 || $itemType.indexOf('array') >= 0)) }}
|
---|
| 27 | outer:
|
---|
| 28 | for (;i--;) {
|
---|
| 29 | for (j = i; j--;) {
|
---|
| 30 | if (equal({{=$data}}[i], {{=$data}}[j])) {
|
---|
| 31 | {{=$valid}} = false;
|
---|
| 32 | break outer;
|
---|
| 33 | }
|
---|
| 34 | }
|
---|
| 35 | }
|
---|
| 36 | {{??}}
|
---|
| 37 | var itemIndices = {}, item;
|
---|
| 38 | for (;i--;) {
|
---|
| 39 | var item = {{=$data}}[i];
|
---|
| 40 | {{ var $method = 'checkDataType' + ($typeIsArray ? 's' : ''); }}
|
---|
| 41 | if ({{= it.util[$method]($itemType, 'item', it.opts.strictNumbers, true) }}) continue;
|
---|
| 42 | {{? $typeIsArray}}
|
---|
| 43 | if (typeof item == 'string') item = '"' + item;
|
---|
| 44 | {{?}}
|
---|
| 45 | if (typeof itemIndices[item] == 'number') {
|
---|
| 46 | {{=$valid}} = false;
|
---|
| 47 | j = itemIndices[item];
|
---|
| 48 | break;
|
---|
| 49 | }
|
---|
| 50 | itemIndices[item] = i;
|
---|
| 51 | }
|
---|
| 52 | {{?}}
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | {{? $isData }} } {{?}}
|
---|
| 56 |
|
---|
| 57 | if (!{{=$valid}}) {
|
---|
| 58 | {{# def.error:'uniqueItems' }}
|
---|
| 59 | } {{? $breakOnError }} else { {{?}}
|
---|
| 60 | {{??}}
|
---|
| 61 | {{? $breakOnError }} if (true) { {{?}}
|
---|
| 62 | {{?}}
|
---|
Note:
See
TracBrowser
for help on using the repository browser.