You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+71-14Lines changed: 71 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,20 +42,22 @@ Validators are just functions. It will be executed for each property, and return
42
42
-[Length](#length)
43
43
-[Value](#value)
44
44
-[Custom function](#custom-function)
45
+
-[Date](#date)
46
+
-[Model](#model)
45
47
46
-
## Type
47
-
If the data has not the specifed type, validation will fail, and that field will not be added to final validated data.
48
-
49
-
```javascript
50
-
{
51
-
type:String// Check if data has a JS type (uses typeof)
52
-
}
53
-
```
48
+
## Type
49
+
If the data has not the specifed type, validation will fail, and that field will not be added to final validated data.
50
+
51
+
```javascript
52
+
{
53
+
type:String// Check if data has a JS type (uses typeof)
54
+
}
55
+
```
54
56
55
-
## Length
56
-
Check data length. It uses default .length param, so it's valid for so much types.
57
-
58
-
```javascript
57
+
## Length
58
+
Check data length. It uses default .length param, so it's valid for so much types.
59
+
60
+
```javascript
59
61
{
60
62
length: {
61
63
eq:Number, // Exact allowed value
@@ -65,8 +67,8 @@ Validators are just functions. It will be executed for each property, and return
65
67
}
66
68
```
67
69
68
-
## Value
69
-
Check data length. It uses default .length param, so it's valid for so much types.
70
+
## Value
71
+
Check data length. It uses default .length param, so it's valid for so much types.
70
72
71
73
```javascript
72
74
{
@@ -98,3 +100,58 @@ function is42(value) {
98
100
returntrue;
99
101
}
100
102
```
103
+
104
+
## Date
105
+
Check if data is a JavaScript Date. Just need to set a boolean `date` parameter, like:
106
+
107
+
```javascript
108
+
{
109
+
data:Boolean// Check if data is a JS Date
110
+
}
111
+
```
112
+
> _Remember that JavaScript dates has type `Object`_
113
+
114
+
115
+
## Model
116
+
Yes, models can also validate (and modelate) other models. It's just neccessary the model to exists. To add that model validation, just set a property "model", with the string value of the model name:
117
+
118
+
```javascript
119
+
{
120
+
model:String// Check if data is of a defined model
121
+
}
122
+
```
123
+
An example of when and how to use it, would be a geopoint:
0 commit comments