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