1 |
|
2 |
|
3 |
|
4 |
|
5 | var _ = require('lodash'),
|
6 | SchemaType = require('../schematype');
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | var SchemaString = module.exports = function(options){
|
17 | SchemaType.call(this, options);
|
18 |
|
19 | if (options && options.ref) this.ref = options.ref;
|
20 | };
|
21 |
|
22 | SchemaString.type = SchemaString.prototype.type = String;
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | SchemaString.__proto__ = SchemaType;
|
29 | SchemaString.prototype.__proto__ = SchemaType.prototype;
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | SchemaString.prototype.checkRequired = function(value){
|
40 | return value instanceof String || typeof value === 'string';
|
41 | };
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | SchemaString.prototype.cast = function(value){
|
52 | if (value == null) return value;
|
53 | if (value instanceof String || typeof value === 'string') return value;
|
54 |
|
55 | if (value.toString){
|
56 | return value.toString();
|
57 | } else {
|
58 | return null;
|
59 | }
|
60 | };
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | var compare = SchemaString.prototype.compare = function(data, value){
|
72 | if (value instanceof RegExp){
|
73 | return value.test(data);
|
74 | } else {
|
75 | return data == value;
|
76 | }
|
77 | }; |
\ | No newline at end of file |