2 module.exports = function generate__limitLength(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 $op = $keyword == 'maxLength' ? '>' : '<';
23 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
25 if (it.opts.unicode === false) {
26 out += ' ' + ($data) + '.length ';
28 out += ' ucs2length(' + ($data) + ') ';
30 out += ' ' + ($op) + ' ' + ($schemaValue) + ') { ';
31 var $errorKeyword = $keyword;
32 var $$outStack = $$outStack || [];
34 out = ''; /* istanbul ignore else */
35 if (it.createErrors !== false) {
36 out += ' { keyword: \'' + ($errorKeyword || '_limitLength') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
37 if (it.opts.messages !== false) {
38 out += ' , message: \'should NOT be ';
39 if ($keyword == 'maxLength') {
46 out += '\' + ' + ($schemaValue) + ' + \'';
48 out += '' + ($schema);
50 out += ' characters\' ';
52 if (it.opts.verbose) {
55 out += 'validate.schema' + ($schemaPath);
57 out += '' + ($schema);
59 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
66 out = $$outStack.pop();
67 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
69 out += ' throw new ValidationError([' + (__err) + ']); ';
71 out += ' validate.errors = [' + (__err) + ']; return false; ';
74 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';