ejv 2.0.5 → 2.1.1
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/.mocharc.json +1 -1
- package/CHANGELOG.md +26 -0
- package/README-KR.md +166 -165
- package/README.md +182 -178
- package/build/cjs/constants.js +112 -107
- package/build/cjs/constants.js.map +1 -1
- package/build/cjs/ejv.js +245 -177
- package/build/cjs/ejv.js.map +1 -1
- package/build/cjs/index.js +6 -6
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/interfaces.js.map +1 -1
- package/build/cjs/tester.js +12 -8
- package/build/cjs/tester.js.map +1 -1
- package/build/cjs/util.js.map +1 -1
- package/build/constants.d.ts +10 -5
- package/build/esm/constants.js +111 -106
- package/build/esm/constants.js.map +1 -1
- package/build/esm/ejv.js +247 -179
- package/build/esm/ejv.js.map +1 -1
- package/build/esm/index.js +1 -1
- package/build/esm/index.js.map +1 -1
- package/build/esm/interfaces.js.map +1 -1
- package/build/esm/tester.js +11 -8
- package/build/esm/tester.js.map +1 -1
- package/build/esm/util.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/interfaces.d.ts +10 -9
- package/build/tester.d.ts +4 -3
- package/build/util.d.ts +2 -2
- package/eslint.config.mjs +59 -0
- package/package.json +17 -13
- package/spec/ArrayScheme.ts +46 -46
- package/spec/CommonScheme.ts +15 -15
- package/spec/DateScheme.ts +22 -22
- package/spec/NumberScheme.ts +229 -121
- package/spec/ObjectScheme.ts +22 -22
- package/spec/RegExpScheme.ts +5 -5
- package/spec/StringScheme.ts +223 -126
- package/spec/common-test-util.ts +2 -2
- package/spec/ejv.spec.ts +20 -20
- package/spec/testers.spec.ts +5 -5
- package/src/constants.ts +12 -5
- package/src/ejv.ts +291 -202
- package/src/index.ts +1 -1
- package/src/interfaces.ts +11 -12
- package/src/tester.ts +14 -10
- package/src/util.ts +2 -2
- package/tsconfig.json +2 -1
- package/.eslintrc.json +0 -88
package/README.md
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
ejv is JSON validation library. Check your JSON object with simple syntax.
|
|
8
8
|
|
|
9
|
-
> ejv is written by TypeScript, and published by JavaScript. So you can use this library in TypeScript code and
|
|
9
|
+
> ejv is written by TypeScript, and published by JavaScript. So you can use this library in TypeScript code and
|
|
10
|
+
> JavaScript code also.
|
|
10
11
|
|
|
11
12
|
## Install
|
|
12
13
|
|
|
@@ -47,17 +48,18 @@ var ejv = _ejv.ejv;
|
|
|
47
48
|
- TypeScript
|
|
48
49
|
|
|
49
50
|
```typescript
|
|
50
|
-
const error
|
|
51
|
-
|
|
51
|
+
const error: null | EjvError = ejv({
|
|
52
|
+
a: 10
|
|
52
53
|
}, [{
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
key: 'a',
|
|
55
|
+
type: 'number'
|
|
55
56
|
}]);
|
|
56
57
|
|
|
57
58
|
if (!error) {
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
59
|
+
console.log('success');
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
console.log('failed');
|
|
61
63
|
}
|
|
62
64
|
```
|
|
63
65
|
|
|
@@ -65,16 +67,16 @@ if (!error) {
|
|
|
65
67
|
|
|
66
68
|
```javascript
|
|
67
69
|
var error = ejv({
|
|
68
|
-
|
|
70
|
+
a: 10
|
|
69
71
|
}, [{
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
key: 'a',
|
|
73
|
+
type: 'number'
|
|
72
74
|
}]);
|
|
73
75
|
|
|
74
76
|
if (!error) {
|
|
75
|
-
|
|
77
|
+
console.log('success');
|
|
76
78
|
} else {
|
|
77
|
-
|
|
79
|
+
console.log('failed');
|
|
78
80
|
}
|
|
79
81
|
```
|
|
80
82
|
|
|
@@ -112,10 +114,10 @@ This option is available for all validation rules.
|
|
|
112
114
|
|
|
113
115
|
```typescript
|
|
114
116
|
ejv({
|
|
115
|
-
|
|
117
|
+
// empty object
|
|
116
118
|
}, [{
|
|
117
|
-
|
|
118
|
-
|
|
119
|
+
key: 'a',
|
|
120
|
+
optional: true // Error does not occur without proffering declared.
|
|
119
121
|
}]);
|
|
120
122
|
```
|
|
121
123
|
|
|
@@ -126,10 +128,10 @@ This option is available for all validation rules.
|
|
|
126
128
|
|
|
127
129
|
```typescript
|
|
128
130
|
ejv({
|
|
129
|
-
|
|
131
|
+
a: null
|
|
130
132
|
}, [{
|
|
131
|
-
|
|
132
|
-
|
|
133
|
+
key: 'a',
|
|
134
|
+
nullable: true
|
|
133
135
|
}]);
|
|
134
136
|
```
|
|
135
137
|
|
|
@@ -140,36 +142,36 @@ This option is available for the rules of validation: `type: number` and `type:
|
|
|
140
142
|
|
|
141
143
|
```typescript
|
|
142
144
|
ejv({
|
|
143
|
-
|
|
144
|
-
|
|
145
|
+
a: 1,
|
|
146
|
+
b: 'hello'
|
|
145
147
|
}, [{
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
148
|
+
key: 'a',
|
|
149
|
+
type: 'number',
|
|
150
|
+
enum: [1, 2, 3] // allow 1, 2, 3
|
|
149
151
|
}, {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
152
|
+
key: 'b',
|
|
153
|
+
type: 'string',
|
|
154
|
+
enum: ['hello', 'ejv'] // allow 'hello', 'ejv'
|
|
153
155
|
}]);
|
|
154
156
|
```
|
|
155
157
|
|
|
156
|
-
- `
|
|
158
|
+
- `notEnum : number[] | string[]`
|
|
157
159
|
|
|
158
160
|
Not allows the values that are delivered in an array. This result is reverse of the option `enum`.
|
|
159
161
|
This option is available for the rules of validation: `type: number` and `type: string`.
|
|
160
162
|
|
|
161
163
|
```typescript
|
|
162
164
|
ejv({
|
|
163
|
-
|
|
164
|
-
|
|
165
|
+
a: 1,
|
|
166
|
+
b: 'hello'
|
|
165
167
|
}, [{
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
168
|
+
key: 'a',
|
|
169
|
+
type: 'number',
|
|
170
|
+
notEnum: [1, 2, 3] // not allow 1, 2, 3
|
|
169
171
|
}, {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
172
|
+
key: 'b',
|
|
173
|
+
type: 'string',
|
|
174
|
+
notEnum: ['hello', 'ejv'] // not allow 'hello', 'ejv'
|
|
173
175
|
}]);
|
|
174
176
|
```
|
|
175
177
|
|
|
@@ -188,17 +190,17 @@ This option is used only when the `min` option is used.
|
|
|
188
190
|
|
|
189
191
|
```typescript
|
|
190
192
|
ejv({
|
|
191
|
-
|
|
192
|
-
|
|
193
|
+
num1: 10,
|
|
194
|
+
num2: 10
|
|
193
195
|
}, [{
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
196
|
+
key: 'num1',
|
|
197
|
+
type: 'number',
|
|
198
|
+
min: 10 // success
|
|
197
199
|
}, {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
200
|
+
key: 'num2',
|
|
201
|
+
type: 'number',
|
|
202
|
+
min: 10,
|
|
203
|
+
exclusiveMin: true // failed
|
|
202
204
|
}]);
|
|
203
205
|
```
|
|
204
206
|
|
|
@@ -215,17 +217,17 @@ This option is used only when the `min` option is used.
|
|
|
215
217
|
|
|
216
218
|
```typescript
|
|
217
219
|
ejv({
|
|
218
|
-
|
|
219
|
-
|
|
220
|
+
num1: 10,
|
|
221
|
+
num2: 10
|
|
220
222
|
}, [{
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
223
|
+
key: 'num1',
|
|
224
|
+
type: 'number',
|
|
225
|
+
max: 10 // success
|
|
224
226
|
}, {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
key: 'num2',
|
|
228
|
+
type: 'number',
|
|
229
|
+
max: 10,
|
|
230
|
+
exclusiveMax: true // failed
|
|
229
231
|
}]);
|
|
230
232
|
```
|
|
231
233
|
|
|
@@ -235,10 +237,10 @@ Checks the format of the number.
|
|
|
235
237
|
If specified as an array, ejv allow the value if it corresponds to one of the given formats.
|
|
236
238
|
The available formats are as follows.
|
|
237
239
|
|
|
238
|
-
format|example
|
|
239
|
-
|
|
240
|
-
`'integer'
|
|
241
|
-
`'index'
|
|
240
|
+
format | example
|
|
241
|
+
-------------|--------------------------------------------------------------------------------------------------
|
|
242
|
+
`'integer'` | Allows only integer. ex) -1, 0, 1, ...
|
|
243
|
+
`'index'` | Allows only index. This format is same rule with `format : 'integer', min : 0`. ex) 0, 1, 2, ...
|
|
242
244
|
|
|
243
245
|
#### `'string'` options
|
|
244
246
|
|
|
@@ -247,12 +249,12 @@ format|example
|
|
|
247
249
|
Checks the format of string. If specified as an array, ejv will allow the value if it corresponds to one of the given
|
|
248
250
|
formats. The available formats are as follows.
|
|
249
251
|
|
|
250
|
-
format|example
|
|
251
|
-
|
|
252
|
-
`'email'
|
|
253
|
-
`'date'
|
|
254
|
-
`'time'
|
|
255
|
-
`'date-time'
|
|
252
|
+
format | example
|
|
253
|
+
---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
254
|
+
`'email'` | Allows only email. This is based on [RFC 5322 3.4.1](https://tools.ietf.org/html/rfc5322#section-3.4.1). ex) `'email@domain.com'`
|
|
255
|
+
`'date'` | Allows only date string format. This is based on [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601). ex) `'2018-12-29'`
|
|
256
|
+
`'time'` | Allows only time string format. This is based on [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601). ex) `'21:07:35'`
|
|
257
|
+
`'date-time'` | Allows only date-time string format. This is based on [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) and [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601). ex) `'2018-12-29T21:07:35Z'`
|
|
256
258
|
|
|
257
259
|
- `length : number`
|
|
258
260
|
|
|
@@ -260,11 +262,11 @@ Checks the length of string.
|
|
|
260
262
|
|
|
261
263
|
```typescript
|
|
262
264
|
ejv({
|
|
263
|
-
|
|
265
|
+
str: 'hello'
|
|
264
266
|
}, [{
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
267
|
+
key: 'str',
|
|
268
|
+
type: 'string',
|
|
269
|
+
length: 5
|
|
268
270
|
}]);
|
|
269
271
|
````
|
|
270
272
|
|
|
@@ -274,11 +276,11 @@ Checks the minimum length of string.
|
|
|
274
276
|
|
|
275
277
|
```typescript
|
|
276
278
|
ejv({
|
|
277
|
-
|
|
279
|
+
str: 'hello'
|
|
278
280
|
}, [{
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
281
|
+
key: 'str',
|
|
282
|
+
type: 'string',
|
|
283
|
+
minLength: 5
|
|
282
284
|
}]);
|
|
283
285
|
````
|
|
284
286
|
|
|
@@ -288,39 +290,40 @@ Checks the maximum length of string.
|
|
|
288
290
|
|
|
289
291
|
```typescript
|
|
290
292
|
ejv({
|
|
291
|
-
|
|
293
|
+
str: 'hello'
|
|
292
294
|
}, [{
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
295
|
+
key: 'str',
|
|
296
|
+
type: 'string',
|
|
297
|
+
maxLength: 5
|
|
296
298
|
}]);
|
|
297
299
|
````
|
|
298
300
|
|
|
299
301
|
- `pattern : string | string[] | RegExp | RegExp[]`
|
|
300
302
|
|
|
301
303
|
Checks the pattern of string.
|
|
302
|
-
If specified as a string, the string is converted to a regular expression and checked, and if specified as a regular
|
|
304
|
+
If specified as a string, the string is converted to a regular expression and checked, and if specified as a regular
|
|
305
|
+
expression, it checks whether it passes the regular expression.
|
|
303
306
|
If the value of this option is specified as an array, pass the check if one of the rule passes.
|
|
304
307
|
|
|
305
308
|
```typescript
|
|
306
309
|
ejv({
|
|
307
|
-
|
|
310
|
+
str: 'abc'
|
|
308
311
|
}, [{
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
+
key: 'str',
|
|
313
|
+
type: 'string',
|
|
314
|
+
pattern: 'abc'
|
|
312
315
|
}, {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
+
key: 'str',
|
|
317
|
+
type: 'string',
|
|
318
|
+
pattern: ['abc', 'ac']
|
|
316
319
|
}, {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
+
key: 'str',
|
|
321
|
+
type: 'string',
|
|
322
|
+
pattern: /abc/
|
|
320
323
|
}, {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
+
key: 'str',
|
|
325
|
+
type: 'string',
|
|
326
|
+
pattern: [/abc/, /ac/]
|
|
324
327
|
}]);
|
|
325
328
|
```
|
|
326
329
|
|
|
@@ -334,11 +337,11 @@ If you omit this option or specify it as `true`, ejv will allow the empty object
|
|
|
334
337
|
|
|
335
338
|
```typescript
|
|
336
339
|
ejv({
|
|
337
|
-
|
|
340
|
+
obj: {}
|
|
338
341
|
}, [{
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
+
key: 'obj',
|
|
343
|
+
type: 'object',
|
|
344
|
+
allowNoProperty: false // failed
|
|
342
345
|
}]);
|
|
343
346
|
```
|
|
344
347
|
|
|
@@ -349,20 +352,20 @@ The object specified for the validation is recursively processed by ejv().
|
|
|
349
352
|
|
|
350
353
|
```typescript
|
|
351
354
|
ejv({
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
355
|
+
data: {
|
|
356
|
+
num: 10,
|
|
357
|
+
str: 'ejv'
|
|
358
|
+
}
|
|
356
359
|
}, [{
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
360
|
+
key: 'data',
|
|
361
|
+
type: 'object',
|
|
362
|
+
properties: [{
|
|
363
|
+
key: 'num',
|
|
364
|
+
type: 'number'
|
|
365
|
+
}, {
|
|
366
|
+
key: 'str',
|
|
367
|
+
type: 'string'
|
|
368
|
+
}]
|
|
366
369
|
}]);
|
|
367
370
|
```
|
|
368
371
|
|
|
@@ -382,25 +385,25 @@ This option is used only when the `min` option is used.
|
|
|
382
385
|
|
|
383
386
|
```typescript
|
|
384
387
|
ejv({
|
|
385
|
-
|
|
388
|
+
date1: new Date(2019, 11, 30)
|
|
386
389
|
}, [{
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
+
key: 'date1',
|
|
391
|
+
type: 'date',
|
|
392
|
+
min: new Date(2019, 11, 30) // success
|
|
390
393
|
}, {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
394
|
+
key: 'date1',
|
|
395
|
+
type: 'date',
|
|
396
|
+
min: new Date(2019, 11, 30),
|
|
397
|
+
exclusiveMin: true // failed
|
|
395
398
|
}, {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
+
key: 'date1',
|
|
400
|
+
type: 'date',
|
|
401
|
+
min: '2019-12-30T00:00:00Z' // success
|
|
399
402
|
}, {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
403
|
+
key: 'date1',
|
|
404
|
+
type: 'date',
|
|
405
|
+
min: '2019-12-30T00:00:00Z',
|
|
406
|
+
exclusiveMin: true // failed
|
|
404
407
|
}]);
|
|
405
408
|
```
|
|
406
409
|
|
|
@@ -418,25 +421,25 @@ This option is used only when the `max` option is used.
|
|
|
418
421
|
|
|
419
422
|
```typescript
|
|
420
423
|
ejv({
|
|
421
|
-
|
|
424
|
+
date1: new Date(2019, 11, 30)
|
|
422
425
|
}, [{
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
+
key: 'date1',
|
|
427
|
+
type: 'date',
|
|
428
|
+
max: new Date(2019, 11, 30) // success
|
|
426
429
|
}, {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
430
|
+
key: 'date1',
|
|
431
|
+
type: 'date',
|
|
432
|
+
max: new Date(2019, 11, 30),
|
|
433
|
+
exclusiveMax: true // failed
|
|
431
434
|
}, {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
+
key: 'date1',
|
|
436
|
+
type: 'date',
|
|
437
|
+
max: '2019-12-30T00:00:00Z' // success
|
|
435
438
|
}, {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
439
|
+
key: 'date1',
|
|
440
|
+
type: 'date',
|
|
441
|
+
max: '2019-12-30T00:00:00Z',
|
|
442
|
+
exclusiveMax: true // failed
|
|
440
443
|
}]);
|
|
441
444
|
```
|
|
442
445
|
|
|
@@ -448,11 +451,11 @@ Checks the length of the array.
|
|
|
448
451
|
|
|
449
452
|
```typescript
|
|
450
453
|
ejv({
|
|
451
|
-
|
|
454
|
+
arr: [1, 2]
|
|
452
455
|
}, [{
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
+
key: 'arr',
|
|
457
|
+
type: 'array',
|
|
458
|
+
length: 2
|
|
456
459
|
}]);
|
|
457
460
|
````
|
|
458
461
|
|
|
@@ -462,11 +465,11 @@ Checks the minimum length of the array.
|
|
|
462
465
|
|
|
463
466
|
```typescript
|
|
464
467
|
ejv({
|
|
465
|
-
|
|
468
|
+
arr: [1, 2]
|
|
466
469
|
}, [{
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
+
key: 'arr',
|
|
471
|
+
type: 'array',
|
|
472
|
+
minLength: 2
|
|
470
473
|
}]);
|
|
471
474
|
````
|
|
472
475
|
|
|
@@ -476,11 +479,11 @@ Checks the maximum length of the array.
|
|
|
476
479
|
|
|
477
480
|
```typescript
|
|
478
481
|
ejv({
|
|
479
|
-
|
|
482
|
+
arr: [1, 2, 3]
|
|
480
483
|
}, [{
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
+
key: 'arr',
|
|
485
|
+
type: 'array',
|
|
486
|
+
maxLength: 3
|
|
484
487
|
}]);
|
|
485
488
|
````
|
|
486
489
|
|
|
@@ -498,15 +501,15 @@ Schemes specified as arrays are recursively processed by `ejv()`, and processed
|
|
|
498
501
|
|
|
499
502
|
```typescript
|
|
500
503
|
ejv({
|
|
501
|
-
|
|
504
|
+
arr: [1, 2, 3]
|
|
502
505
|
}, [{
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
506
|
+
key: 'arr',
|
|
507
|
+
type: 'array',
|
|
508
|
+
items: [{
|
|
509
|
+
type: 'number',
|
|
510
|
+
min: 1,
|
|
511
|
+
max: 3
|
|
512
|
+
}]
|
|
510
513
|
}])
|
|
511
514
|
```
|
|
512
515
|
|
|
@@ -514,19 +517,20 @@ ejv({
|
|
|
514
517
|
|
|
515
518
|
Specify the type of property to inspect. The values available are as follows.
|
|
516
519
|
|
|
517
|
-
type|example
|
|
518
|
-
|
|
519
|
-
`'boolean'
|
|
520
|
-
`'number'
|
|
521
|
-
`'string'
|
|
522
|
-
`'object'
|
|
523
|
-
`'date'
|
|
524
|
-
`'regexp'
|
|
525
|
-
`'array'
|
|
520
|
+
type | example
|
|
521
|
+
-------------|-------------------------------
|
|
522
|
+
`'boolean'` | `true`, `false`
|
|
523
|
+
`'number'` | `0`, `1`, `1.5`, ...
|
|
524
|
+
`'string'` | `'ejv'`, `'hello'`, ...
|
|
525
|
+
`'object'` | `{}`, `{ key : 123 }`, ...
|
|
526
|
+
`'date'` | `new Date`
|
|
527
|
+
`'regexp'` | `new RegExp(/./)`, `/./`, ...
|
|
528
|
+
`'array'` | `[]`, `[1, 2, 3]`, ...
|
|
526
529
|
|
|
527
530
|
## `EjvError`
|
|
528
531
|
|
|
529
|
-
If the JSON object passes the validation rule, it returns the `null` object, but if it does not pass the inspection
|
|
532
|
+
If the JSON object passes the validation rule, it returns the `null` object, but if it does not pass the inspection
|
|
533
|
+
rule, it returns the instance of the `EjvError` type.
|
|
530
534
|
The `EjvError` object is an object that represents the error that occurred at this time.
|
|
531
535
|
|
|
532
536
|
> You do not always need to use `EjvError` type.
|
|
@@ -557,11 +561,11 @@ usage)
|
|
|
557
561
|
```typescript
|
|
558
562
|
import { ejv, EjvError } from 'ejv';
|
|
559
563
|
|
|
560
|
-
const error
|
|
561
|
-
|
|
564
|
+
const error: null | EjvError = ejv({
|
|
565
|
+
a: 10
|
|
562
566
|
}, [{
|
|
563
|
-
|
|
564
|
-
|
|
567
|
+
key: 'a',
|
|
568
|
+
type: 'string'
|
|
565
569
|
}]);
|
|
566
570
|
|
|
567
571
|
console.log(error.type); // 'TYPE_MISMATCH'
|
|
@@ -584,15 +588,15 @@ This option is used in the type of `object`. You can use `ErrorType` as a key wh
|
|
|
584
588
|
```typescript
|
|
585
589
|
import { ejv, EjvError, ErrorType } from 'ejv';
|
|
586
590
|
|
|
587
|
-
const error
|
|
588
|
-
|
|
591
|
+
const error: null | EjvError = ejv({
|
|
592
|
+
a: 10
|
|
589
593
|
}, [{
|
|
590
|
-
|
|
591
|
-
|
|
594
|
+
key: 'a',
|
|
595
|
+
type: 'string'
|
|
592
596
|
}, {
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
597
|
+
customErrorMsg: {
|
|
598
|
+
[ErrorType.TYPE_MISMATCH]: 'property "a" should be a "string".'
|
|
599
|
+
}
|
|
596
600
|
}]);
|
|
597
601
|
|
|
598
602
|
console.log(error.message); // 'property "a" should be a "string".'
|