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
Add a custom handler for the `format` keyword. Whenever a schema uses the `format` keyword, with the given by `formatName`, your handler will be called.
144
+
145
+
The handler receives the value to be validated, and returns `null` if the value is valid, or a `string` (description of the error) if the value is not valid.
146
+
119
147
### Loaders
120
148
121
149
A loader can be passed to the constructor, or you can set the `loader` property at any time. You can define your own loader. **JaySchema** also includes one built-in loader for your convenience:
@@ -153,7 +181,7 @@ Pass a `loader` callback to the `JaySchema` constructor. When an external schema
153
181
This works with synchronous or async code.
154
182
155
183
1. First, `register()` the main schemas you plan to use.
156
-
2. Next, call `getMissingSchemas`, which returns an array of externally-referenced schemas.
184
+
2. Next, call `getMissingSchemas`, which returns an array of externally-referenced schemas.
157
185
3. Retrieve and `register()` each missing schema.
158
186
4. Repeat from step 2 until there are no more missing schemas.
159
187
@@ -169,7 +197,7 @@ If, instead, you want the list of *all* missing schemas referenced by all regist
169
197
170
198
## Format specifiers
171
199
172
-
**JaySchema**supports the following values for the optional `format` keyword:
200
+
For the `format` keyword, **JaySchema** allows you to add custom validation functions (see [`addFormat`](#jayschemaprototypeaddformatformatname-handler)). In addition, the following built-in formats are supported:
173
201
174
202
* `date-time`: Must match the `date-time` specification given in [RFC 3339, Section 5.6](https://tools.ietf.org/html/rfc3339#section-5.6). This expects *both* a date and a time. For date-only validation or time-only validation, JaySchema supports the older draft v3 `date` and `time` formats.
175
203
* `hostname`: Must match the “Preferred name syntax” given in [RFC 1034, Section 3.5](https://tools.ietf.org/html/rfc1034#section-3.5), with the exception that hostnames are permitted to begin with a digit, as per [RFC 1123 Section 2.1](http://tools.ietf.org/html/rfc1123#section-2.1).
Copy file name to clipboardExpand all lines: Release Notes.md
+6-2Lines changed: 6 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,14 @@
1
+
#0.3.0
2
+
3
+
***FEATURE:**[Custom `format` validators](https://github.com/natesilva/jayschema#jayschemaprototypeaddformatformatname-handler) are now supported. The syntax is compatible with that of [tv4](https://github.com/geraintluff/tv4#addformatformat-validationfunction). Thanks to [alexkwolfe](https://github.com/alexkwolfe) for the suggestion.
4
+
1
5
# 0.2.8
2
6
3
-
***BUGFIX:**`enum` properties with `null` values now work. Thanks to [alexkwolfe](https://github.com/alexkwolfe).
7
+
***BUGFIX**:`enum` properties with `null` values now work. Thanks to [alexkwolfe](https://github.com/alexkwolfe).
4
8
5
9
# 0.2.7
6
10
7
-
***BUGFIX:** Handle falsy values correctly in `ValidationError`. Thanks to [larose](https://github.com/larose).
11
+
***BUGFIX**: Handle falsy values correctly in `ValidationError`. Thanks to [larose](https://github.com/larose).
8
12
* Other code cleanups. Thanks again to [larose](https://github.com/larose).
0 commit comments