1 | var Valida = require('..');
|
2 |
|
3 |
|
4 | var schema = {
|
5 | salary: [
|
6 | { sanitizer: Valida.Sanitizer.toFloat, groups: ['without precision'] },
|
7 | { sanitizer: Valida.Sanitizer.toFloat, precision: 6, groups: ['with precision'] }
|
8 | ]
|
9 | };
|
10 |
|
11 |
|
12 | var person = { salary: '1.541712812' };
|
13 |
|
14 |
|
15 | Valida.process(person, schema, function(err, ctx) {
|
16 |
|
17 | console.log('without precision', person);
|
18 | }, 'without precision');
|
19 |
|
20 |
|
21 | person.salary = 1.541712812;
|
22 |
|
23 |
|
24 | Valida.process(person, schema, function(err, ctx) {
|
25 |
|
26 | console.log('with precision', person);
|
27 | }, 'with precision');
|
28 |
|
29 |
|
30 | person.salary = '12.423423134123';
|
31 |
|
32 |
|
33 | Valida.process(person, schema, function(err, ctx) {
|
34 |
|
35 | console.log('with precision', person);
|
36 | }, 'with precision');
|