schema-shield 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/formats.d.ts +3 -0
- package/dist/formats.d.ts.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1289 -0
- package/dist/index.min.js +1 -0
- package/dist/index.min.js.map +1 -0
- package/dist/index.mjs +1267 -0
- package/dist/keywords/array-keywords.d.ts +3 -0
- package/dist/keywords/array-keywords.d.ts.map +1 -0
- package/dist/keywords/number-keywords.d.ts +3 -0
- package/dist/keywords/number-keywords.d.ts.map +1 -0
- package/dist/keywords/object-keywords.d.ts +3 -0
- package/dist/keywords/object-keywords.d.ts.map +1 -0
- package/dist/keywords/other-keywords.d.ts +3 -0
- package/dist/keywords/other-keywords.d.ts.map +1 -0
- package/dist/keywords/string-keywords.d.ts +3 -0
- package/dist/keywords/string-keywords.d.ts.map +1 -0
- package/dist/keywords.d.ts +3 -0
- package/dist/keywords.d.ts.map +1 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +13 -0
- package/dist/utils.d.ts.map +1 -0
- package/lib/formats.ts +56 -0
- package/lib/index.ts +308 -0
- package/lib/keywords/array-keywords.ts +204 -0
- package/lib/keywords/number-keywords.ts +79 -0
- package/lib/keywords/object-keywords.ts +230 -0
- package/lib/keywords/other-keywords.ts +248 -0
- package/lib/keywords/string-keywords.ts +165 -0
- package/lib/keywords.ts +14 -0
- package/lib/types.ts +176 -0
- package/lib/utils.ts +79 -0
- package/package.json +189 -0
- package/tsconfig.json +16 -0
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
## Schema Shield
|
|
2
|
+
|
|
3
|
+
`SchemaShield` is a JavaScript library for Node.js and the web that makes it easy and fast to validate JSON objects against JSON schemas. It helps ensure that your data is compliant with the specified schema, while also protecting against invalid input, so you can maintain data integrity and accuracy.
|
|
4
|
+
|
|
5
|
+
With `SchemaShield`, you can be confident that your data is fully compliant with JSON Schema draft 4 through 7, making it a reliable solution for validating your data.
|
|
6
|
+
|
|
7
|
+
Plus, it offers TypeScript support, so you can ensure type safety while building your applications.
|
|
8
|
+
|
|
9
|
+
`SchemaShield` is built with performance in mind, so you can quickly validate your JSON data without any slowdowns.
|
|
10
|
+
|
|
11
|
+
Whether you're working with Node.js or the web, `SchemaShield` is a robust and secure solution that you can count on for efficient and accurate data validation.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formats.d.ts","sourceRoot":"","sources":["../lib/formats.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAsC,MAAM,SAAS,CAAC;AAqB7E,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAkClD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ValidationError } from "./utils";
|
|
2
|
+
export interface ValidationErrorProps {
|
|
3
|
+
pointer: string;
|
|
4
|
+
value: any;
|
|
5
|
+
code: string;
|
|
6
|
+
}
|
|
7
|
+
export interface Result {
|
|
8
|
+
valid: boolean;
|
|
9
|
+
errors: ValidationError[];
|
|
10
|
+
data: any;
|
|
11
|
+
}
|
|
12
|
+
export interface ValidatorFunction {
|
|
13
|
+
(schema: CompiledSchema, data: any, pointer: string, schemaShieldInstance: SchemaShield): Result;
|
|
14
|
+
}
|
|
15
|
+
export interface FormatFunction {
|
|
16
|
+
(data: any): boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface CompiledSchema {
|
|
19
|
+
pointer: string;
|
|
20
|
+
validator?: ValidatorFunction;
|
|
21
|
+
type?: string;
|
|
22
|
+
validators?: ValidatorFunction[];
|
|
23
|
+
keywords?: Record<string, ValidatorFunction>;
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}
|
|
26
|
+
export interface Validator {
|
|
27
|
+
(data: any): Result;
|
|
28
|
+
compiledSchema: CompiledSchema;
|
|
29
|
+
}
|
|
30
|
+
export declare class SchemaShield {
|
|
31
|
+
types: Map<string, ValidatorFunction>;
|
|
32
|
+
formats: Map<string, FormatFunction>;
|
|
33
|
+
keywords: Map<string, ValidatorFunction>;
|
|
34
|
+
constructor();
|
|
35
|
+
addType(name: string, validator: ValidatorFunction): void;
|
|
36
|
+
addFormat(name: string, validator: FormatFunction): void;
|
|
37
|
+
addKeyword(name: string, validator: ValidatorFunction): void;
|
|
38
|
+
compile(schema: any): Validator;
|
|
39
|
+
private compileSchema;
|
|
40
|
+
private handleArraySchema;
|
|
41
|
+
private handleObjectSchema;
|
|
42
|
+
private validateTypes;
|
|
43
|
+
private validateKeywords;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAY,MAAM,SAAS,CAAC;AAMpD,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,GAAG,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,IAAI,EAAE,GAAG,CAAC;CACX;AAED,MAAM,WAAW,iBAAiB;IAChC,CACE,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,GAAG,EACT,OAAO,EAAE,MAAM,EACf,oBAAoB,EAAE,YAAY,GACjC,MAAM,CAAC;CACX;AAED,MAAM,WAAW,cAAc;IAC7B,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,iBAAiB,CAAC;IAC9B,IAAI,CAAC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