1
+ import Core from "./cores/CoreInterface" ;
2
+ import { JSONValidator } from "./types" ;
3
+
4
+
1
5
/**
2
6
* @throws Error
3
7
* Adds a custom error. May override existing errors
4
8
*
5
- * @param { Core } core
6
- * @param { String } errorId - id of error @see /lib/validation/errors
7
- * @param {Function } errorCreator - function returning an error-object @see /lib/utils/createCustomError
9
+ * @param core
10
+ * @param errorId - id of error @see /lib/validation/errors
11
+ * @param {Function } errorCreator - function returning an error-object @see /lib/utils/createCustomError
8
12
*/
9
- function addError ( core , errorId , errorCreator ) {
13
+ function addError ( core : Core , errorId : string , errorCreator ) {
10
14
if ( typeof errorCreator !== "function" ) {
11
15
throw new Error ( `Error callback 'errorCreator' must be of type function. Received ${ typeof errorCreator } ` ) ;
12
16
}
13
17
core . errors [ errorId ] = errorCreator ;
14
18
}
15
19
20
+
16
21
/**
17
22
* Adds a custom format validator. Existing format may not be overriden (may still be modified manually)
18
- * @param { Core } core
19
- * @param { String } formatType - format type (i.e. `format: "html"`)
20
- * @param { Function } validationFunction - called with (core, schema, value, pointer)
23
+ * @param core
24
+ * @param formatType - format type (i.e. `format: "html"`)
25
+ * @param validationFunction - called with (core, schema, value, pointer)
21
26
*/
22
- function addFormat ( core , formatType , validationFunction ) {
27
+ function addFormat ( core : Core , formatType : string , validationFunction : JSONValidator ) {
23
28
if ( typeof validationFunction !== "function" ) {
24
29
throw new Error ( `Validation function expected. Received ${ typeof validationFunction } ` ) ;
25
30
}
@@ -30,15 +35,16 @@ function addFormat(core, formatType, validationFunction) {
30
35
throw new Error ( `A format '${ formatType } ' is already registered to validation` ) ;
31
36
}
32
37
38
+
33
39
/**
34
40
* Adds a custom keyword validation to a specific type. May not override existing keywords.
35
41
*
36
- * @param { Core } core
37
- * @param { String } datatype - valid datatype like "object", "array", "string", etc
38
- * @param { String } keyword - The keyword to add, i.e. `minWidth: ...`
39
- * @param { Function } validationFunction - called with (core, schema, value, pointer)
42
+ * @param core
43
+ * @param datatype - valid datatype like "object", "array", "string", etc
44
+ * @param keyword - The keyword to add, i.e. `minWidth: ...`
45
+ * @param validationFunction - called with (core, schema, value, pointer)
40
46
*/
41
- function addKeyword ( core , datatype , keyword , validationFunction ) {
47
+ function addKeyword ( core : Core , datatype : string , keyword : string , validationFunction : JSONValidator ) {
42
48
if ( typeof validationFunction !== "function" ) {
43
49
throw new Error ( `Validation function expected. Received ${ typeof validationFunction } ` ) ;
44
50
}
@@ -52,7 +58,7 @@ function addKeyword(core, datatype, keyword, validationFunction) {
52
58
}
53
59
54
60
55
- module . exports = {
61
+ export default {
56
62
error : addError ,
57
63
format : addFormat ,
58
64
keyword : addKeyword
0 commit comments