aboutsummaryrefslogtreecommitdiff
path: root/node_modules/ajv/lib/dotjs/uniqueItems.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
committerFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
commitbbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch)
treec58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/ajv/lib/dotjs/uniqueItems.js
parent003fb34971cf63466184351b4db5f7c67df4f444 (diff)
update packages
Diffstat (limited to 'node_modules/ajv/lib/dotjs/uniqueItems.js')
-rw-r--r--node_modules/ajv/lib/dotjs/uniqueItems.js16
1 files changed, 15 insertions, 1 deletions
diff --git a/node_modules/ajv/lib/dotjs/uniqueItems.js b/node_modules/ajv/lib/dotjs/uniqueItems.js
index d9b3185fc..d2dedf5a7 100644
--- a/node_modules/ajv/lib/dotjs/uniqueItems.js
+++ b/node_modules/ajv/lib/dotjs/uniqueItems.js
@@ -21,7 +21,21 @@ module.exports = function generate_uniqueItems(it, $keyword, $ruleType) {
if ($isData) {
out += ' var ' + ($valid) + '; if (' + ($schemaValue) + ' === false || ' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'boolean\') ' + ($valid) + ' = false; else { ';
}
- out += ' var ' + ($valid) + ' = true; if (' + ($data) + '.length > 1) { var i = ' + ($data) + '.length, j; outer: for (;i--;) { for (j = i; j--;) { if (equal(' + ($data) + '[i], ' + ($data) + '[j])) { ' + ($valid) + ' = false; break outer; } } } } ';
+ out += ' var i = ' + ($data) + '.length , ' + ($valid) + ' = true , j; if (i > 1) { ';
+ var $itemType = it.schema.items && it.schema.items.type,
+ $typeIsArray = Array.isArray($itemType);
+ if (!$itemType || $itemType == 'object' || $itemType == 'array' || ($typeIsArray && ($itemType.indexOf('object') >= 0 || $itemType.indexOf('array') >= 0))) {
+ out += ' outer: for (;i--;) { for (j = i; j--;) { if (equal(' + ($data) + '[i], ' + ($data) + '[j])) { ' + ($valid) + ' = false; break outer; } } } ';
+ } else {
+ out += ' var itemIndices = {}, item; for (;i--;) { var item = ' + ($data) + '[i]; ';
+ var $method = 'checkDataType' + ($typeIsArray ? 's' : '');
+ out += ' if (' + (it.util[$method]($itemType, 'item', true)) + ') continue; ';
+ if ($typeIsArray) {
+ out += ' if (typeof item == \'string\') item = \'"\' + item; ';
+ }
+ out += ' if (typeof itemIndices[item] == \'number\') { ' + ($valid) + ' = false; j = itemIndices[item]; break; } itemIndices[item] = i; } ';
+ }
+ out += ' } ';
if ($isData) {
out += ' } ';
}