ajv/lib/dot/uniqueItems.jst

55 lines
1.3 KiB
Plaintext
Raw Normal View History

{{# def.definitions }}
2015-12-12 16:41:51 +03:00
{{# def.errors }}
2015-12-22 20:03:09 +03:00
{{# def.setupKeyword }}
2015-12-24 21:58:15 +03:00
{{# def.$data }}
2015-05-30 23:08:31 +03:00
2015-06-02 03:59:32 +03:00
2015-12-24 21:58:15 +03:00
{{? ($schema || $isData) && it.opts.uniqueItems !== false }}
{{? $isData }}
var {{=$valid}};
if ({{=$schemaValue}} === false || {{=$schemaValue}} === undefined)
{{=$valid}} = true;
else if (typeof {{=$schemaValue}} != 'boolean')
{{=$valid}} = false;
else {
{{?}}
var i = {{=$data}}.length
, {{=$valid}} = true
, j;
if (i > 1) {
{{ var $itemType = it.schema.items && it.schema.items.type; }}
{{? !$itemType || $itemType == 'object' || $itemType == 'array' }}
outer:
for (;i--;) {
for (j = i; j--;) {
if (equal({{=$data}}[i], {{=$data}}[j])) {
{{=$valid}} = false;
break outer;
}
}
}
{{??}}
var itemIndices = {}, item;
for (;i--;) {
var item = {{=$data}}[i];
if (typeof item != '{{=$itemType}}') continue;
if (itemIndices[item] !== undefined) {
{{=$valid}} = false;
j = itemIndices[item];
break;
2015-06-02 02:14:38 +03:00
}
itemIndices[item] = i;
}
{{?}}
2015-05-31 20:39:12 +03:00
}
2015-12-24 21:58:15 +03:00
{{? $isData }} } {{?}}
if (!{{=$valid}}) {
{{# def.error:'uniqueItems' }}
} {{? $breakOnError }} else { {{?}}
{{??}}
{{? $breakOnError }} if (true) { {{?}}
2015-05-31 20:39:12 +03:00
{{?}}