2 module.exports = function generate_pattern(it, $keyword, $ruleType) {
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;
10 var $data = 'data' + ($dataLvl || '');
11 var $isData = it.opts.$data && $schema && $schema.$data,
14 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
15 $schemaValue = 'schema' + $lvl;
17 $schemaValue = $schema;
19 var $regexp = $isData ? '(new RegExp(' + $schemaValue + '))' : it.usePattern($schema);
22 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || ';
24 out += ' !' + ($regexp) + '.test(' + ($data) + ') ) { ';
25 var $$outStack = $$outStack || [];
27 out = ''; /* istanbul ignore else */
28 if (it.createErrors !== false) {
29 out += ' { keyword: \'' + ('pattern') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { pattern: ';
31 out += '' + ($schemaValue);
33 out += '' + (it.util.toQuotedString($schema));
36 if (it.opts.messages !== false) {
37 out += ' , message: \'should match pattern "';
39 out += '\' + ' + ($schemaValue) + ' + \'';
41 out += '' + (it.util.escapeQuotes($schema));
45 if (it.opts.verbose) {
48 out += 'validate.schema' + ($schemaPath);
50 out += '' + (it.util.toQuotedString($schema));
52 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
59 out = $$outStack.pop();
60 if (!it.compositeRule && $breakOnError) {
61 /* istanbul ignore if */
63 out += ' throw new ValidationError([' + (__err) + ']); ';
65 out += ' validate.errors = [' + (__err) + ']; return false; ';
68 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';