forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
z-schema.d.ts
97 lines (83 loc) · 2.96 KB
/
z-schema.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Type definitions for z-schema v3.16.0
// Project: https://github.com/zaggino/z-schema
// Definitions by: Adam Meadows <https://github.com/job13er>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace ZSchema {
export interface Options {
asyncTimeout?: number;
forceAdditional?: boolean;
assumeAdditional?: boolean;
forceItems?: boolean;
forceMinItems?: boolean;
forceMaxItems?: boolean;
forceMinLength?: boolean;
forceMaxLength?: boolean;
forceProperties?: boolean;
ignoreUnresolvableReferences?: boolean;
noExtraKeywords?: boolean;
noTypeless?: boolean;
noEmptyStrings?: boolean;
noEmptyArrays?: boolean;
strictUris?: boolean;
strictMode?: boolean;
reportPathAsArray?: boolean;
breakOnFirstError?: boolean;
pedanticCheck?: boolean;
ignoreUnknownFormats?: boolean;
}
export interface SchemaError {
code: string;
description: string;
message: string;
params: string[];
path: string;
}
export class Validator {
/**
* Register a custom format.
*
* @param name - name of the custom format
* @param validatorFunction - custom format validator function.
* Returns `true` if `value` matches the custom format.
*/
public static registerFormat(formatName: string, validatorFunction: (value: any) => boolean): void;
/**
* Unregister a format.
*
* @param name - name of the custom format
*/
public static unregisterFormat(name: string): void;
/**
* Get the list of all registered formats.
*
* Both the names of the burned-in formats and the custom format names are
* returned by this function.
*
* @returns {string[]} the list of all registered format names.
*/
public static getRegisteredFormats(): string[];
public static getDefaultOptions(): Options;
constructor(options: Options);
/**
* @param schema - JSON object representing schema
* @returns {boolean} true if schema is valid.
*/
validateSchema(schema: any): boolean;
/**
* @param json - either a JSON string or a parsed JSON object
* @param schema - the JSON object representing the schema
* @returns true if json matches schema
*/
validate(json: any, schema: any): boolean;
/**
* @param json - either a JSON string or a parsed JSON object
* @param schema - the JSON object representing the schema
*/
validate(json: any, schema: any, callback: (err: any, valid: boolean) => void): void;
getLastError(): SchemaError;
getLastErrors(): SchemaError[];
}
}
declare module "z-schema" {
export = ZSchema.Validator;
}