UNPKG

768 BJavaScriptView Raw
1var Valida = require('..');
2
3
4var 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
12var person = { salary: '1.541712812' };
13
14
15Valida.process(person, schema, function(err, ctx) {
16 // jshint unused:false
17 console.log('without precision', person);
18}, 'without precision');
19
20
21person.salary = 1.541712812;
22
23
24Valida.process(person, schema, function(err, ctx) {
25 // jshint unused:false
26 console.log('with precision', person);
27}, 'with precision');
28
29
30person.salary = '12.423423134123';
31
32
33Valida.process(person, schema, function(err, ctx) {
34 // jshint unused:false
35 console.log('with precision', person);
36}, 'with precision');