1 |
|
2 |
|
3 |
|
4 |
|
5 | var _ = require('lodash'),
|
6 | SchemaType = require('../schematype');
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | var SchemaNumber = module.exports = function(options){
|
16 | SchemaType.call(this, options);
|
17 | };
|
18 |
|
19 | SchemaNumber.__proto__ = SchemaType;
|
20 | SchemaNumber.type = SchemaNumber.prototype.type = Number;
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | SchemaNumber.prototype.__proto__ = SchemaType.prototype;
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | SchemaNumber.prototype.checkRequired = function(value){
|
37 | return value instanceof Number || typeof value === 'number';
|
38 | };
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | SchemaNumber.prototype.cast = function(value){
|
49 | if (value == null) return value;
|
50 | if (value === '') return null;
|
51 | if (value instanceof Number || typeof value === 'number') return value;
|
52 | if (!isNaN(+value)) return +value;
|
53 |
|
54 | return null;
|
55 | };
|
56 |
|
57 | SchemaNumber.prototype.u$inc = function(data, value){
|
58 | if (!data) return +value;
|
59 |
|
60 | return data + +value;
|
61 | };
|
62 |
|
63 | SchemaNumber.prototype.u$dec = function(data, value){
|
64 | if (!data) return -+value;
|
65 |
|
66 | return data - +value;
|
67 | }; |
\ | No newline at end of file |