2 module.exports = function generate_multipleOf(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 out += 'var division' + ($lvl) + ';if (';
22 out += ' ' + ($schemaValue) + ' !== undefined && ( typeof ' + ($schemaValue) + ' != \'number\' || ';
24 out += ' (division' + ($lvl) + ' = ' + ($data) + ' / ' + ($schemaValue) + ', ';
25 if (it.opts.multipleOfPrecision) {
26 out += ' Math.abs(Math.round(division' + ($lvl) + ') - division' + ($lvl) + ') > 1e-' + (it.opts.multipleOfPrecision) + ' ';
28 out += ' division' + ($lvl) + ' !== parseInt(division' + ($lvl) + ') ';
35 var $$outStack = $$outStack || [];
37 out = ''; /* istanbul ignore else */
38 if (it.createErrors !== false) {
39 out += ' { keyword: \'' + ($errorKeyword || 'multipleOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { multipleOf: ' + ($schemaValue) + ' } ';
40 if (it.opts.messages !== false) {
41 out += ' , message: \'should be multiple of ';
43 out += '\' + ' + ($schemaValue);
45 out += '' + ($schema) + '\'';
48 if (it.opts.verbose) {
51 out += 'validate.schema' + ($schemaPath);
53 out += '' + ($schema);
55 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
62 out = $$outStack.pop();
63 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
65 out += ' throw new ValidationError([' + (__err) + ']); ';
67 out += ' validate.errors = [' + (__err) + ']; return false; ';
70 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';