ejv 1.1.11 → 2.0.0
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/.eslintrc.json +88 -0
- package/.mocharc.json +8 -0
- package/CHANGELOG.md +109 -68
- package/LICENSE +21 -21
- package/README-KR.md +596 -592
- package/README.md +599 -595
- package/build/{constants.js → cjs/constants.js} +44 -45
- package/build/cjs/constants.js.map +1 -0
- package/build/cjs/ejv.js +1263 -0
- package/build/cjs/ejv.js.map +1 -0
- package/build/{public_api.js → cjs/index.js} +4 -4
- package/build/cjs/index.js.map +1 -0
- package/build/cjs/interfaces.js +29 -0
- package/build/cjs/interfaces.js.map +1 -0
- package/build/cjs/package.json +1 -0
- package/build/{tester.js → cjs/tester.js} +87 -82
- package/build/cjs/tester.js.map +1 -0
- package/build/cjs/util.js +103 -0
- package/build/cjs/util.js.map +1 -0
- package/build/constants.d.ts +36 -39
- package/build/esm/constants.js +115 -0
- package/build/esm/constants.js.map +1 -0
- package/build/esm/ejv.js +1261 -0
- package/build/esm/ejv.js.map +1 -0
- package/build/esm/index.js +4 -0
- package/build/esm/index.js.map +1 -0
- package/build/esm/interfaces.js +33 -0
- package/build/esm/interfaces.js.map +1 -0
- package/build/esm/package.json +1 -0
- package/build/esm/tester.js +240 -0
- package/build/esm/tester.js.map +1 -0
- package/build/esm/util.js +96 -0
- package/build/esm/util.js.map +1 -0
- package/build/index.d.ts +3 -0
- package/build/interfaces.d.ts +53 -13
- package/build/scripts/add-js-extensions.js +46 -0
- package/build/scripts/add-js-extensions.js.map +1 -0
- package/build/tester.d.ts +16 -17
- package/build/util.d.ts +7 -1
- package/package.json +50 -39
- package/scripts/add-js-extensions.ts +59 -0
- package/spec/ArrayScheme.ts +1021 -0
- package/spec/CommonScheme.ts +251 -0
- package/spec/DateScheme.ts +472 -0
- package/spec/NumberScheme.ts +1032 -0
- package/spec/ObjectScheme.ts +499 -0
- package/spec/RegExpScheme.ts +112 -0
- package/spec/StringScheme.ts +1239 -0
- package/spec/common-test-util.ts +63 -0
- package/spec/ejv.spec.ts +209 -4634
- package/spec/testers.spec.ts +833 -832
- package/src/constants.ts +155 -156
- package/src/ejv.ts +1648 -1071
- package/src/index.ts +14 -0
- package/src/interfaces.ts +149 -63
- package/src/tester.ts +308 -302
- package/src/util.ts +124 -59
- package/tsconfig.cjs.json +8 -0
- package/tsconfig.esm.json +7 -0
- package/tsconfig.json +22 -19
- package/tsconfig.scripts.json +14 -0
- package/tsconfig.types.json +9 -0
- package/build/constants.js.map +0 -1
- package/build/ejv.js +0 -687
- package/build/ejv.js.map +0 -1
- package/build/interfaces.js +0 -15
- package/build/interfaces.js.map +0 -1
- package/build/public_api.d.ts +0 -3
- package/build/public_api.js.map +0 -1
- package/build/tester.js.map +0 -1
- package/build/util.js +0 -68
- package/build/util.js.map +0 -1
- package/spec/common-test-runner.ts +0 -17
- package/src/public_api.ts +0 -3
- package/tsconfig.spec.json +0 -19
package/src/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { ejv } from './ejv';
|
|
2
|
+
export { DataType, NumberFormat, StringFormat, ErrorMsg, ErrorType } from './constants';
|
|
3
|
+
export {
|
|
4
|
+
BooleanScheme,
|
|
5
|
+
NumberScheme,
|
|
6
|
+
StringScheme,
|
|
7
|
+
ObjectScheme,
|
|
8
|
+
ArrayScheme,
|
|
9
|
+
RegExpScheme,
|
|
10
|
+
DateScheme,
|
|
11
|
+
EjvError,
|
|
12
|
+
Scheme,
|
|
13
|
+
Options
|
|
14
|
+
} from './interfaces';
|
package/src/interfaces.ts
CHANGED
|
@@ -1,63 +1,149 @@
|
|
|
1
|
-
import { DataType, ErrorType, NumberFormat, StringFormat } from './constants';
|
|
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
|
-
|
|
1
|
+
import { DataType, ErrorType, NumberFormat, StringFormat } from './constants';
|
|
2
|
+
|
|
3
|
+
export type AllDataType = string | string[] | DataType | DataType[];
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
interface CommonScheme {
|
|
7
|
+
parent?: Scheme;
|
|
8
|
+
|
|
9
|
+
key?: string; // can be omitted in array items
|
|
10
|
+
type?: AllDataType; // optional for not
|
|
11
|
+
|
|
12
|
+
optional?: boolean; // false
|
|
13
|
+
nullable?: boolean; // false
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// no additional rule
|
|
17
|
+
export type BooleanScheme = CommonScheme;
|
|
18
|
+
|
|
19
|
+
export interface MinMax<T> {
|
|
20
|
+
min?: T;
|
|
21
|
+
exclusiveMin?: boolean; // default false
|
|
22
|
+
|
|
23
|
+
max?: T;
|
|
24
|
+
exclusiveMax?: boolean; // default false
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface MinMaxScheme<T> extends CommonScheme, MinMax<T> {
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface NumberScheme extends MinMaxScheme<number> {
|
|
31
|
+
value?: number; // TODO: need to add
|
|
32
|
+
|
|
33
|
+
enum?: number[];
|
|
34
|
+
|
|
35
|
+
format?: string | string[] | NumberFormat | NumberFormat[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface StringScheme extends CommonScheme {
|
|
39
|
+
value?: string; // TODO: need to add
|
|
40
|
+
|
|
41
|
+
enum?: string[];
|
|
42
|
+
|
|
43
|
+
format?: string | string[] | StringFormat | StringFormat[];
|
|
44
|
+
pattern?: string | string[] | RegExp | RegExp[];
|
|
45
|
+
|
|
46
|
+
length?: number;
|
|
47
|
+
minLength?: number;
|
|
48
|
+
maxLength?: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface ObjectScheme extends CommonScheme {
|
|
52
|
+
properties?: Scheme[];
|
|
53
|
+
allowNoProperty?: boolean; // true
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
/* eslint-disable @typescript-eslint/no-empty-interface */
|
|
58
|
+
export interface DateScheme extends MinMaxScheme<string | Date> {
|
|
59
|
+
// min, max string for date string
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// no additional rule
|
|
63
|
+
export type RegExpScheme = CommonScheme;
|
|
64
|
+
|
|
65
|
+
export interface ArrayScheme extends CommonScheme {
|
|
66
|
+
unique?: boolean; // false
|
|
67
|
+
items?: AllDataType | Scheme | Scheme[];
|
|
68
|
+
|
|
69
|
+
length?: number;
|
|
70
|
+
minLength?: number;
|
|
71
|
+
maxLength?: number;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export type Scheme =
|
|
75
|
+
BooleanScheme
|
|
76
|
+
| NumberScheme
|
|
77
|
+
| StringScheme
|
|
78
|
+
| ObjectScheme
|
|
79
|
+
| DateScheme
|
|
80
|
+
| RegExpScheme
|
|
81
|
+
| ArrayScheme;
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
export interface Options {
|
|
85
|
+
customErrorMsg?: {
|
|
86
|
+
[key in ErrorType]?: string;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface InternalOptions extends Options {
|
|
91
|
+
path: string[];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export class EjvError {
|
|
95
|
+
public type: ErrorType;
|
|
96
|
+
public message: string;
|
|
97
|
+
|
|
98
|
+
public data: unknown;
|
|
99
|
+
public path: string | undefined;
|
|
100
|
+
|
|
101
|
+
public errorScheme: Scheme | undefined;
|
|
102
|
+
public errorData: unknown | undefined;
|
|
103
|
+
|
|
104
|
+
public isSchemeError: boolean;
|
|
105
|
+
public isDataError: boolean;
|
|
106
|
+
|
|
107
|
+
constructor (param: {
|
|
108
|
+
type: ErrorType,
|
|
109
|
+
message: string,
|
|
110
|
+
|
|
111
|
+
data: unknown,
|
|
112
|
+
path?: string[],
|
|
113
|
+
|
|
114
|
+
errorScheme?: Scheme,
|
|
115
|
+
errorData?: unknown,
|
|
116
|
+
|
|
117
|
+
isSchemeError?: boolean
|
|
118
|
+
}) {
|
|
119
|
+
this.type = param.type;
|
|
120
|
+
this.message = param.message;
|
|
121
|
+
|
|
122
|
+
this.data = param.data;
|
|
123
|
+
|
|
124
|
+
if ('path' in param && param.path !== undefined) {
|
|
125
|
+
this.path = param.path.join('/');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if ('errorScheme' in param) {
|
|
129
|
+
this.errorScheme = param.errorScheme;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if ('errorData' in param) {
|
|
133
|
+
this.errorData = param.errorData;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (param.isSchemeError) {
|
|
137
|
+
this.isSchemeError = true;
|
|
138
|
+
this.isDataError = false;
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
this.isSchemeError = false;
|
|
142
|
+
this.isDataError = true;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface AnyObject {
|
|
148
|
+
[key: string]: unknown;
|
|
149
|
+
}
|