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.
Files changed (49) hide show
  1. package/.mocharc.json +1 -1
  2. package/CHANGELOG.md +26 -0
  3. package/README-KR.md +166 -165
  4. package/README.md +182 -178
  5. package/build/cjs/constants.js +112 -107
  6. package/build/cjs/constants.js.map +1 -1
  7. package/build/cjs/ejv.js +245 -177
  8. package/build/cjs/ejv.js.map +1 -1
  9. package/build/cjs/index.js +6 -6
  10. package/build/cjs/index.js.map +1 -1
  11. package/build/cjs/interfaces.js.map +1 -1
  12. package/build/cjs/tester.js +12 -8
  13. package/build/cjs/tester.js.map +1 -1
  14. package/build/cjs/util.js.map +1 -1
  15. package/build/constants.d.ts +10 -5
  16. package/build/esm/constants.js +111 -106
  17. package/build/esm/constants.js.map +1 -1
  18. package/build/esm/ejv.js +247 -179
  19. package/build/esm/ejv.js.map +1 -1
  20. package/build/esm/index.js +1 -1
  21. package/build/esm/index.js.map +1 -1
  22. package/build/esm/interfaces.js.map +1 -1
  23. package/build/esm/tester.js +11 -8
  24. package/build/esm/tester.js.map +1 -1
  25. package/build/esm/util.js.map +1 -1
  26. package/build/index.d.ts +1 -1
  27. package/build/interfaces.d.ts +10 -9
  28. package/build/tester.d.ts +4 -3
  29. package/build/util.d.ts +2 -2
  30. package/eslint.config.mjs +59 -0
  31. package/package.json +17 -13
  32. package/spec/ArrayScheme.ts +46 -46
  33. package/spec/CommonScheme.ts +15 -15
  34. package/spec/DateScheme.ts +22 -22
  35. package/spec/NumberScheme.ts +229 -121
  36. package/spec/ObjectScheme.ts +22 -22
  37. package/spec/RegExpScheme.ts +5 -5
  38. package/spec/StringScheme.ts +223 -126
  39. package/spec/common-test-util.ts +2 -2
  40. package/spec/ejv.spec.ts +20 -20
  41. package/spec/testers.spec.ts +5 -5
  42. package/src/constants.ts +12 -5
  43. package/src/ejv.ts +291 -202
  44. package/src/index.ts +1 -1
  45. package/src/interfaces.ts +11 -12
  46. package/src/tester.ts +14 -10
  47. package/src/util.ts +2 -2
  48. package/tsconfig.json +2 -1
  49. package/.eslintrc.json +0 -88
package/build/cjs/ejv.js CHANGED
@@ -22,8 +22,8 @@ const _ejv = (data, schemes, options) => {
22
22
  // check schemes
23
23
  if (!(0, tester_1.definedTester)(schemes) || schemes === null) {
24
24
  return new interfaces_1.EjvError({
25
- type: constants_1.ErrorType.NO_SCHEME,
26
- message: constants_1.ErrorMsg.NO_SCHEME,
25
+ type: constants_1.ERROR_TYPE.NO_SCHEME,
26
+ message: constants_1.ERROR_MESSAGE.NO_SCHEME,
27
27
  data: data,
28
28
  errorScheme: schemes,
29
29
  isSchemeError: true
@@ -31,17 +31,17 @@ const _ejv = (data, schemes, options) => {
31
31
  }
32
32
  if (!(0, tester_1.arrayTester)(schemes)) {
33
33
  return new interfaces_1.EjvError({
34
- type: constants_1.ErrorType.INVALID_SCHEMES,
35
- message: constants_1.ErrorMsg.NO_ARRAY_SCHEME,
34
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
35
+ message: constants_1.ERROR_MESSAGE.NO_ARRAY_SCHEME,
36
36
  data: data,
37
37
  errorScheme: schemes,
38
38
  isSchemeError: true
39
39
  });
40
40
  }
41
- if (!(0, tester_1.arrayTypeOfTester)(schemes, constants_1.DataType.OBJECT)) {
41
+ if (!(0, tester_1.arrayTypeOfTester)(schemes, constants_1.DATA_TYPE.OBJECT)) {
42
42
  return new interfaces_1.EjvError({
43
- type: constants_1.ErrorType.INVALID_SCHEMES,
44
- message: constants_1.ErrorMsg.NO_OBJECT_ARRAY_SCHEME,
43
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
44
+ message: constants_1.ERROR_MESSAGE.NO_OBJECT_ARRAY_SCHEME,
45
45
  data: data,
46
46
  errorScheme: schemes,
47
47
  isSchemeError: true
@@ -49,8 +49,8 @@ const _ejv = (data, schemes, options) => {
49
49
  }
50
50
  if (!(0, tester_1.minLengthTester)(schemes, 1)) {
51
51
  return new interfaces_1.EjvError({
52
- type: constants_1.ErrorType.INVALID_SCHEMES,
53
- message: constants_1.ErrorMsg.EMPTY_SCHEME,
52
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
53
+ message: constants_1.ERROR_MESSAGE.EMPTY_SCHEME,
54
54
  data: data,
55
55
  errorScheme: schemes,
56
56
  isSchemeError: true
@@ -70,14 +70,14 @@ const _ejv = (data, schemes, options) => {
70
70
  const types = _getEffectiveTypes(scheme);
71
71
  if (!(0, tester_1.definedTester)(types)) {
72
72
  return new interfaces_1.EjvError({
73
- type: constants_1.ErrorType.INVALID_SCHEMES,
74
- message: constants_1.ErrorMsg.SCHEMES_SHOULD_HAVE_TYPE,
73
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
74
+ message: constants_1.ERROR_MESSAGE.SCHEMES_SHOULD_HAVE_TYPE,
75
75
  data: data,
76
76
  errorScheme: scheme,
77
77
  isSchemeError: true
78
78
  });
79
79
  }
80
- const allDataType = Object.values(constants_1.DataType);
80
+ const allDataType = Object.values(constants_1.DATA_TYPE);
81
81
  const typeError = types.find((type) => {
82
82
  return !(0, tester_1.definedTester)(type)
83
83
  || !(0, tester_1.stringTester)(type)
@@ -85,8 +85,8 @@ const _ejv = (data, schemes, options) => {
85
85
  });
86
86
  if (typeError) {
87
87
  return new interfaces_1.EjvError({
88
- type: constants_1.ErrorType.INVALID_SCHEMES,
89
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.SCHEMES_HAS_INVALID_TYPE, {
88
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
89
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.SCHEMES_HAS_INVALID_TYPE, {
90
90
  placeholders: [typeError]
91
91
  }),
92
92
  data: data,
@@ -100,8 +100,8 @@ const _ejv = (data, schemes, options) => {
100
100
  });
101
101
  const notUniqueItemsSifted = (0, util_1.sift)(notUniqueItems);
102
102
  return new interfaces_1.EjvError({
103
- type: constants_1.ErrorType.INVALID_SCHEMES,
104
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.SCHEMES_HAS_DUPLICATED_TYPE, {
103
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
104
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.SCHEMES_HAS_DUPLICATED_TYPE, {
105
105
  placeholders: [notUniqueItemsSifted.join(', ')]
106
106
  }),
107
107
  data: data,
@@ -112,8 +112,8 @@ const _ejv = (data, schemes, options) => {
112
112
  if (!(0, tester_1.definedTester)(value)) {
113
113
  if (scheme.optional !== true) {
114
114
  result = new interfaces_1.EjvError({
115
- type: constants_1.ErrorType.REQUIRED,
116
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.REQUIRED),
115
+ type: constants_1.ERROR_TYPE.REQUIRED,
116
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.REQUIRED),
117
117
  data,
118
118
  path: _options.path,
119
119
  errorScheme: scheme,
@@ -128,8 +128,8 @@ const _ejv = (data, schemes, options) => {
128
128
  if (value === null) {
129
129
  if (scheme.nullable !== true) {
130
130
  result = new interfaces_1.EjvError({
131
- type: constants_1.ErrorType.REQUIRED,
132
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.REQUIRED),
131
+ type: constants_1.ERROR_TYPE.REQUIRED,
132
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.REQUIRED),
133
133
  data,
134
134
  path: _options.path,
135
135
  errorScheme: scheme,
@@ -149,8 +149,8 @@ const _ejv = (data, schemes, options) => {
149
149
  if (!(0, tester_1.arrayTester)(scheme.type)) {
150
150
  if (scheme.type !== typeResolved) {
151
151
  result = new interfaces_1.EjvError({
152
- type: constants_1.ErrorType.TYPE_MISMATCH,
153
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.TYPE_MISMATCH, {
152
+ type: constants_1.ERROR_TYPE.TYPE_MISMATCH,
153
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.TYPE_MISMATCH, {
154
154
  placeholders: [scheme.type]
155
155
  }),
156
156
  data,
@@ -163,8 +163,8 @@ const _ejv = (data, schemes, options) => {
163
163
  else {
164
164
  if (!scheme.type.includes(typeResolved)) {
165
165
  result = new interfaces_1.EjvError({
166
- type: constants_1.ErrorType.TYPE_MISMATCH_ONE_OF,
167
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.TYPE_MISMATCH_ONE_OF, {
166
+ type: constants_1.ERROR_TYPE.TYPE_MISMATCH_ONE_OF,
167
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.TYPE_MISMATCH_ONE_OF, {
168
168
  placeholders: [JSON.stringify(scheme.type)]
169
169
  }),
170
170
  data,
@@ -182,8 +182,8 @@ const _ejv = (data, schemes, options) => {
182
182
  const typesForMsg = scheme.type || ((_a = scheme.parent) === null || _a === void 0 ? void 0 : _a.type);
183
183
  if (!(0, tester_1.arrayTester)(typesForMsg)) {
184
184
  result = new interfaces_1.EjvError({
185
- type: constants_1.ErrorType.TYPE_MISMATCH,
186
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.TYPE_MISMATCH, {
185
+ type: constants_1.ERROR_TYPE.TYPE_MISMATCH,
186
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.TYPE_MISMATCH, {
187
187
  placeholders: [typesForMsg]
188
188
  }),
189
189
  data,
@@ -194,8 +194,8 @@ const _ejv = (data, schemes, options) => {
194
194
  }
195
195
  else {
196
196
  result = new interfaces_1.EjvError({
197
- type: constants_1.ErrorType.TYPE_MISMATCH_ONE_OF,
198
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.TYPE_MISMATCH_ONE_OF, {
197
+ type: constants_1.ERROR_TYPE.TYPE_MISMATCH_ONE_OF,
198
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.TYPE_MISMATCH_ONE_OF, {
199
199
  placeholders: [JSON.stringify(typesForMsg)]
200
200
  }),
201
201
  data,
@@ -208,24 +208,24 @@ const _ejv = (data, schemes, options) => {
208
208
  }
209
209
  // additional check for type resolved
210
210
  switch (typeResolved) {
211
- case constants_1.DataType.NUMBER: {
211
+ case constants_1.DATA_TYPE.NUMBER: {
212
212
  const valueAsNumber = value;
213
213
  const numberScheme = scheme;
214
214
  if ((0, tester_1.definedTester)(numberScheme.enum)) {
215
215
  if (!(0, tester_1.arrayTester)(numberScheme.enum)) {
216
216
  return new interfaces_1.EjvError({
217
- type: constants_1.ErrorType.INVALID_SCHEMES,
218
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.ENUM_SHOULD_BE_ARRAY),
217
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
218
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.ENUM_SHOULD_BE_ARRAY),
219
219
  data: data,
220
220
  errorScheme: numberScheme,
221
221
  isSchemeError: true
222
222
  });
223
223
  }
224
224
  const enumArr = numberScheme.enum;
225
- if (!(0, tester_1.arrayTypeOfTester)(enumArr, constants_1.DataType.NUMBER)) {
225
+ if (!(0, tester_1.arrayTypeOfTester)(enumArr, constants_1.DATA_TYPE.NUMBER)) {
226
226
  return new interfaces_1.EjvError({
227
- type: constants_1.ErrorType.INVALID_SCHEMES,
228
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.ENUM_SHOULD_BE_NUMBERS),
227
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
228
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.ENUM_SHOULD_BE_NUMBERS),
229
229
  data: data,
230
230
  errorScheme: numberScheme,
231
231
  isSchemeError: true
@@ -233,8 +233,42 @@ const _ejv = (data, schemes, options) => {
233
233
  }
234
234
  if (!(0, tester_1.enumTester)(valueAsNumber, enumArr)) {
235
235
  result = new interfaces_1.EjvError({
236
- type: constants_1.ErrorType.ONE_VALUE_OF,
237
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.ONE_VALUE_OF, {
236
+ type: constants_1.ERROR_TYPE.ONE_VALUE_OF,
237
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.ONE_VALUE_OF, {
238
+ placeholders: [JSON.stringify(enumArr)]
239
+ }),
240
+ data,
241
+ path: _options.path,
242
+ errorScheme: numberScheme,
243
+ errorData: value
244
+ });
245
+ break;
246
+ }
247
+ }
248
+ if ((0, tester_1.definedTester)(numberScheme.notEnum)) {
249
+ if (!(0, tester_1.arrayTester)(numberScheme.notEnum)) {
250
+ return new interfaces_1.EjvError({
251
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
252
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.NOT_ENUM_SHOULD_BE_ARRAY),
253
+ data: data,
254
+ errorScheme: numberScheme,
255
+ isSchemeError: true
256
+ });
257
+ }
258
+ const enumArr = numberScheme.notEnum;
259
+ if (!(0, tester_1.arrayTypeOfTester)(enumArr, constants_1.DATA_TYPE.NUMBER)) {
260
+ return new interfaces_1.EjvError({
261
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
262
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.NOT_ENUM_SHOULD_BE_NUMBERS),
263
+ data: data,
264
+ errorScheme: numberScheme,
265
+ isSchemeError: true
266
+ });
267
+ }
268
+ if (!(0, tester_1.notEnumTester)(valueAsNumber, enumArr)) {
269
+ result = new interfaces_1.EjvError({
270
+ type: constants_1.ERROR_TYPE.NOT_ONE_VALUE_OF,
271
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.NOT_ONE_VALUE_OF, {
238
272
  placeholders: [JSON.stringify(enumArr)]
239
273
  }),
240
274
  data,
@@ -252,8 +286,8 @@ const _ejv = (data, schemes, options) => {
252
286
  : (_c = scheme.parent) === null || _c === void 0 ? void 0 : _c.min;
253
287
  if (!(0, tester_1.numberTester)(effectiveMin)) {
254
288
  return new interfaces_1.EjvError({
255
- type: constants_1.ErrorType.INVALID_SCHEMES,
256
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.MIN_SHOULD_BE_NUMBER),
289
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
290
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.MIN_SHOULD_BE_NUMBER),
257
291
  data: data,
258
292
  errorScheme: numberScheme,
259
293
  isSchemeError: true
@@ -262,8 +296,8 @@ const _ejv = (data, schemes, options) => {
262
296
  if ((0, tester_1.definedTester)(numberScheme.exclusiveMin)) {
263
297
  if (!(0, tester_1.booleanTester)(numberScheme.exclusiveMin)) {
264
298
  return new interfaces_1.EjvError({
265
- type: constants_1.ErrorType.INVALID_SCHEMES,
266
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.EXCLUSIVE_MIN_SHOULD_BE_BOOLEAN),
299
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
300
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.EXCLUSIVE_MIN_SHOULD_BE_BOOLEAN),
267
301
  data: data,
268
302
  errorScheme: numberScheme,
269
303
  isSchemeError: true
@@ -273,8 +307,8 @@ const _ejv = (data, schemes, options) => {
273
307
  if (numberScheme.exclusiveMin) {
274
308
  if (!(0, tester_1.exclusiveMinNumberTester)(valueAsNumber, effectiveMin)) {
275
309
  result = new interfaces_1.EjvError({
276
- type: constants_1.ErrorType.BIGGER_THAN,
277
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.BIGGER_THAN, {
310
+ type: constants_1.ERROR_TYPE.BIGGER_THAN,
311
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.BIGGER_THAN, {
278
312
  placeholders: [effectiveMin]
279
313
  }),
280
314
  data,
@@ -288,8 +322,8 @@ const _ejv = (data, schemes, options) => {
288
322
  else {
289
323
  if (!(0, tester_1.minNumberTester)(valueAsNumber, effectiveMin)) {
290
324
  result = new interfaces_1.EjvError({
291
- type: constants_1.ErrorType.BIGGER_THAN_OR_EQUAL,
292
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.BIGGER_THAN_OR_EQUAL, {
325
+ type: constants_1.ERROR_TYPE.BIGGER_THAN_OR_EQUAL,
326
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.BIGGER_THAN_OR_EQUAL, {
293
327
  placeholders: [effectiveMin]
294
328
  }),
295
329
  data,
@@ -308,8 +342,8 @@ const _ejv = (data, schemes, options) => {
308
342
  : (_e = scheme.parent) === null || _e === void 0 ? void 0 : _e.max;
309
343
  if (!(0, tester_1.numberTester)(effectiveMax)) {
310
344
  return new interfaces_1.EjvError({
311
- type: constants_1.ErrorType.INVALID_SCHEMES,
312
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.MAX_SHOULD_BE_NUMBER),
345
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
346
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.MAX_SHOULD_BE_NUMBER),
313
347
  data: data,
314
348
  errorScheme: numberScheme,
315
349
  isSchemeError: true
@@ -318,8 +352,8 @@ const _ejv = (data, schemes, options) => {
318
352
  if ((0, tester_1.definedTester)(numberScheme.exclusiveMax)) {
319
353
  if (!(0, tester_1.booleanTester)(numberScheme.exclusiveMax)) {
320
354
  return new interfaces_1.EjvError({
321
- type: constants_1.ErrorType.INVALID_SCHEMES,
322
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.EXCLUSIVE_MAX_SHOULD_BE_BOOLEAN),
355
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
356
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.EXCLUSIVE_MAX_SHOULD_BE_BOOLEAN),
323
357
  data: data,
324
358
  errorScheme: numberScheme,
325
359
  isSchemeError: true
@@ -329,8 +363,8 @@ const _ejv = (data, schemes, options) => {
329
363
  if (numberScheme.exclusiveMax) {
330
364
  if (!(0, tester_1.exclusiveMaxNumberTester)(valueAsNumber, effectiveMax)) {
331
365
  result = new interfaces_1.EjvError({
332
- type: constants_1.ErrorType.SMALLER_THAN,
333
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.SMALLER_THAN, {
366
+ type: constants_1.ERROR_TYPE.SMALLER_THAN,
367
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.SMALLER_THAN, {
334
368
  placeholders: [effectiveMax]
335
369
  }),
336
370
  data,
@@ -344,8 +378,8 @@ const _ejv = (data, schemes, options) => {
344
378
  else {
345
379
  if (!(0, tester_1.maxNumberTester)(valueAsNumber, effectiveMax)) {
346
380
  result = new interfaces_1.EjvError({
347
- type: constants_1.ErrorType.SMALLER_THAN_OR_EQUAL,
348
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.SMALLER_THAN_OR_EQUAL, {
381
+ type: constants_1.ERROR_TYPE.SMALLER_THAN_OR_EQUAL,
382
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.SMALLER_THAN_OR_EQUAL, {
349
383
  placeholders: [effectiveMax]
350
384
  }),
351
385
  data,
@@ -359,13 +393,13 @@ const _ejv = (data, schemes, options) => {
359
393
  }
360
394
  if ((0, tester_1.definedTester)(numberScheme.format)) {
361
395
  let formats;
362
- const allNumberFormat = Object.values(constants_1.NumberFormat);
396
+ const allNumberFormat = Object.values(constants_1.NUMBER_FORMAT);
363
397
  if (!(0, tester_1.arrayTester)(numberScheme.format)) {
364
398
  const formatAsString = numberScheme.format;
365
399
  if (!(0, tester_1.enumTester)(formatAsString, allNumberFormat)) {
366
400
  return new interfaces_1.EjvError({
367
- type: constants_1.ErrorType.INVALID_SCHEMES,
368
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.INVALID_NUMBER_FORMAT, {
401
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
402
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.INVALID_NUMBER_FORMAT, {
369
403
  placeholders: [formatAsString]
370
404
  }),
371
405
  data: data,
@@ -382,8 +416,8 @@ const _ejv = (data, schemes, options) => {
382
416
  });
383
417
  if (errorFormat) {
384
418
  return new interfaces_1.EjvError({
385
- type: constants_1.ErrorType.INVALID_SCHEMES,
386
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.INVALID_NUMBER_FORMAT, {
419
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
420
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.INVALID_NUMBER_FORMAT, {
387
421
  placeholders: [errorFormat]
388
422
  }),
389
423
  data: data,
@@ -396,10 +430,10 @@ const _ejv = (data, schemes, options) => {
396
430
  const someFormatIsWrong = formats.some((format) => {
397
431
  let valid = false;
398
432
  switch (format) {
399
- case constants_1.NumberFormat.INTEGER:
433
+ case constants_1.NUMBER_FORMAT.INTEGER:
400
434
  valid = (0, tester_1.integerTester)(valueAsNumber);
401
435
  break;
402
- case constants_1.NumberFormat.INDEX:
436
+ case constants_1.NUMBER_FORMAT.INDEX:
403
437
  valid = (0, tester_1.indexTester)(valueAsNumber);
404
438
  break;
405
439
  }
@@ -408,8 +442,8 @@ const _ejv = (data, schemes, options) => {
408
442
  if (!someFormatIsWrong) {
409
443
  if (!(0, tester_1.arrayTester)(numberScheme.format)) {
410
444
  result = new interfaces_1.EjvError({
411
- type: constants_1.ErrorType.FORMAT,
412
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.FORMAT, {
445
+ type: constants_1.ERROR_TYPE.FORMAT,
446
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.FORMAT, {
413
447
  placeholders: [numberScheme.format]
414
448
  }),
415
449
  data,
@@ -420,8 +454,8 @@ const _ejv = (data, schemes, options) => {
420
454
  }
421
455
  else {
422
456
  result = new interfaces_1.EjvError({
423
- type: constants_1.ErrorType.FORMAT_ONE_OF,
424
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.FORMAT_ONE_OF, {
457
+ type: constants_1.ERROR_TYPE.FORMAT_ONE_OF,
458
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.FORMAT_ONE_OF, {
425
459
  placeholders: [JSON.stringify(numberScheme.format)]
426
460
  }),
427
461
  data,
@@ -435,24 +469,24 @@ const _ejv = (data, schemes, options) => {
435
469
  }
436
470
  break;
437
471
  }
438
- case constants_1.DataType.STRING: {
472
+ case constants_1.DATA_TYPE.STRING: {
439
473
  const valueAsString = value;
440
474
  const stringScheme = scheme;
441
475
  if ((0, tester_1.definedTester)(stringScheme.enum)) {
442
476
  if (!(0, tester_1.arrayTester)(stringScheme.enum)) {
443
477
  return new interfaces_1.EjvError({
444
- type: constants_1.ErrorType.INVALID_SCHEMES,
445
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.ENUM_SHOULD_BE_ARRAY),
478
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
479
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.ENUM_SHOULD_BE_ARRAY),
446
480
  data: data,
447
481
  errorScheme: stringScheme,
448
482
  isSchemeError: true
449
483
  });
450
484
  }
451
485
  const enumArr = stringScheme.enum;
452
- if (!(0, tester_1.arrayTypeOfTester)(enumArr, constants_1.DataType.STRING)) {
486
+ if (!(0, tester_1.arrayTypeOfTester)(enumArr, constants_1.DATA_TYPE.STRING)) {
453
487
  return new interfaces_1.EjvError({
454
- type: constants_1.ErrorType.INVALID_SCHEMES,
455
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.ENUM_SHOULD_BE_STRINGS),
488
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
489
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.ENUM_SHOULD_BE_STRINGS),
456
490
  data: data,
457
491
  errorScheme: stringScheme,
458
492
  isSchemeError: true
@@ -460,8 +494,8 @@ const _ejv = (data, schemes, options) => {
460
494
  }
461
495
  if (!(0, tester_1.enumTester)(valueAsString, enumArr)) {
462
496
  result = new interfaces_1.EjvError({
463
- type: constants_1.ErrorType.ONE_VALUE_OF,
464
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.ONE_VALUE_OF, {
497
+ type: constants_1.ERROR_TYPE.ONE_VALUE_OF,
498
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.ONE_VALUE_OF, {
465
499
  placeholders: [JSON.stringify(stringScheme.enum)]
466
500
  }),
467
501
  data,
@@ -472,12 +506,46 @@ const _ejv = (data, schemes, options) => {
472
506
  break;
473
507
  }
474
508
  }
509
+ if ((0, tester_1.definedTester)(stringScheme.notEnum)) {
510
+ if (!(0, tester_1.arrayTester)(stringScheme.notEnum)) {
511
+ return new interfaces_1.EjvError({
512
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
513
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.NOT_ENUM_SHOULD_BE_ARRAY),
514
+ data: data,
515
+ errorScheme: stringScheme,
516
+ isSchemeError: true
517
+ });
518
+ }
519
+ const enumArr = stringScheme.notEnum;
520
+ if (!(0, tester_1.arrayTypeOfTester)(enumArr, constants_1.DATA_TYPE.STRING)) {
521
+ return new interfaces_1.EjvError({
522
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
523
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.NOT_ENUM_SHOULD_BE_STRINGS),
524
+ data: data,
525
+ errorScheme: stringScheme,
526
+ isSchemeError: true
527
+ });
528
+ }
529
+ if (!(0, tester_1.notEnumTester)(valueAsString, enumArr)) {
530
+ result = new interfaces_1.EjvError({
531
+ type: constants_1.ERROR_TYPE.NOT_ONE_VALUE_OF,
532
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.NOT_ONE_VALUE_OF, {
533
+ placeholders: [JSON.stringify(stringScheme.notEnum)]
534
+ }),
535
+ data,
536
+ path: _options.path,
537
+ errorScheme: stringScheme,
538
+ errorData: value
539
+ });
540
+ break;
541
+ }
542
+ }
475
543
  if ((0, tester_1.definedTester)(stringScheme.length)) {
476
544
  const length = stringScheme.length;
477
545
  if (!((0, tester_1.numberTester)(length) && (0, tester_1.integerTester)(length))) {
478
546
  return new interfaces_1.EjvError({
479
- type: constants_1.ErrorType.INVALID_SCHEMES,
480
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.LENGTH_SHOULD_BE_INTEGER),
547
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
548
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.LENGTH_SHOULD_BE_INTEGER),
481
549
  data: data,
482
550
  errorScheme: stringScheme,
483
551
  isSchemeError: true
@@ -485,8 +553,8 @@ const _ejv = (data, schemes, options) => {
485
553
  }
486
554
  if (!(0, tester_1.lengthTester)(valueAsString, length)) {
487
555
  result = new interfaces_1.EjvError({
488
- type: constants_1.ErrorType.LENGTH,
489
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.LENGTH, {
556
+ type: constants_1.ERROR_TYPE.LENGTH,
557
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.LENGTH, {
490
558
  placeholders: [length]
491
559
  }),
492
560
  data,
@@ -501,8 +569,8 @@ const _ejv = (data, schemes, options) => {
501
569
  const minLength = stringScheme.minLength;
502
570
  if (!((0, tester_1.numberTester)(minLength) && (0, tester_1.integerTester)(minLength))) {
503
571
  return new interfaces_1.EjvError({
504
- type: constants_1.ErrorType.INVALID_SCHEMES,
505
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.MIN_LENGTH_SHOULD_BE_INTEGER),
572
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
573
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.MIN_LENGTH_SHOULD_BE_INTEGER),
506
574
  data: data,
507
575
  errorScheme: stringScheme,
508
576
  isSchemeError: true
@@ -510,8 +578,8 @@ const _ejv = (data, schemes, options) => {
510
578
  }
511
579
  if (!(0, tester_1.minLengthTester)(valueAsString, minLength)) {
512
580
  result = new interfaces_1.EjvError({
513
- type: constants_1.ErrorType.MIN_LENGTH,
514
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.MIN_LENGTH, {
581
+ type: constants_1.ERROR_TYPE.MIN_LENGTH,
582
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.MIN_LENGTH, {
515
583
  placeholders: ['' + minLength]
516
584
  }),
517
585
  data,
@@ -526,8 +594,8 @@ const _ejv = (data, schemes, options) => {
526
594
  const maxLength = stringScheme.maxLength;
527
595
  if (!((0, tester_1.numberTester)(maxLength) && (0, tester_1.integerTester)(maxLength))) {
528
596
  return new interfaces_1.EjvError({
529
- type: constants_1.ErrorType.INVALID_SCHEMES,
530
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.MAX_LENGTH_SHOULD_BE_INTEGER),
597
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
598
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.MAX_LENGTH_SHOULD_BE_INTEGER),
531
599
  data: data,
532
600
  errorScheme: stringScheme,
533
601
  isSchemeError: true
@@ -535,8 +603,8 @@ const _ejv = (data, schemes, options) => {
535
603
  }
536
604
  if (!(0, tester_1.maxLengthTester)(valueAsString, maxLength)) {
537
605
  result = new interfaces_1.EjvError({
538
- type: constants_1.ErrorType.MAX_LENGTH,
539
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.MAX_LENGTH, {
606
+ type: constants_1.ERROR_TYPE.MAX_LENGTH,
607
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.MAX_LENGTH, {
540
608
  placeholders: ['' + maxLength]
541
609
  }),
542
610
  data,
@@ -549,13 +617,13 @@ const _ejv = (data, schemes, options) => {
549
617
  }
550
618
  if ((0, tester_1.definedTester)(stringScheme.format)) {
551
619
  let formats;
552
- const allStringFormat = Object.values(constants_1.StringFormat);
620
+ const allStringFormat = Object.values(constants_1.STRING_FORMAT);
553
621
  if (!(0, tester_1.arrayTester)(stringScheme.format)) {
554
622
  const formatAsString = stringScheme.format;
555
623
  if (!(0, tester_1.enumTester)(formatAsString, allStringFormat)) {
556
624
  return new interfaces_1.EjvError({
557
- type: constants_1.ErrorType.INVALID_SCHEMES,
558
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.INVALID_STRING_FORMAT, {
625
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
626
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.INVALID_STRING_FORMAT, {
559
627
  placeholders: [formatAsString]
560
628
  }),
561
629
  data: data,
@@ -572,8 +640,8 @@ const _ejv = (data, schemes, options) => {
572
640
  });
573
641
  if (errorFormat) {
574
642
  return new interfaces_1.EjvError({
575
- type: constants_1.ErrorType.INVALID_SCHEMES,
576
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.INVALID_STRING_FORMAT, {
643
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
644
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.INVALID_STRING_FORMAT, {
577
645
  placeholders: [errorFormat]
578
646
  }),
579
647
  data: data,
@@ -586,16 +654,16 @@ const _ejv = (data, schemes, options) => {
586
654
  const foundFormatMatching = formats.some((format) => {
587
655
  let valid = false;
588
656
  switch (format) {
589
- case constants_1.StringFormat.EMAIL:
657
+ case constants_1.STRING_FORMAT.EMAIL:
590
658
  valid = (0, tester_1.emailTester)(valueAsString);
591
659
  break;
592
- case constants_1.StringFormat.DATE:
660
+ case constants_1.STRING_FORMAT.DATE:
593
661
  valid = (0, tester_1.dateFormatTester)(valueAsString);
594
662
  break;
595
- case constants_1.StringFormat.TIME:
663
+ case constants_1.STRING_FORMAT.TIME:
596
664
  valid = (0, tester_1.timeFormatTester)(valueAsString);
597
665
  break;
598
- case constants_1.StringFormat.DATE_TIME:
666
+ case constants_1.STRING_FORMAT.DATE_TIME:
599
667
  valid = (0, tester_1.dateTimeFormatTester)(valueAsString);
600
668
  break;
601
669
  }
@@ -604,8 +672,8 @@ const _ejv = (data, schemes, options) => {
604
672
  if (!foundFormatMatching) {
605
673
  if (!(0, tester_1.arrayTester)(stringScheme.format)) {
606
674
  result = new interfaces_1.EjvError({
607
- type: constants_1.ErrorType.FORMAT,
608
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.FORMAT, {
675
+ type: constants_1.ERROR_TYPE.FORMAT,
676
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.FORMAT, {
609
677
  placeholders: [stringScheme.format]
610
678
  }),
611
679
  data,
@@ -616,8 +684,8 @@ const _ejv = (data, schemes, options) => {
616
684
  }
617
685
  else {
618
686
  result = new interfaces_1.EjvError({
619
- type: constants_1.ErrorType.FORMAT_ONE_OF,
620
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.FORMAT_ONE_OF, {
687
+ type: constants_1.ERROR_TYPE.FORMAT_ONE_OF,
688
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.FORMAT_ONE_OF, {
621
689
  placeholders: [JSON.stringify(stringScheme.format)]
622
690
  }),
623
691
  data,
@@ -633,8 +701,8 @@ const _ejv = (data, schemes, options) => {
633
701
  // check parameter
634
702
  if (stringScheme.pattern === null) {
635
703
  return new interfaces_1.EjvError({
636
- type: constants_1.ErrorType.INVALID_SCHEMES,
637
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.INVALID_STRING_PATTERN, {
704
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
705
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.INVALID_STRING_PATTERN, {
638
706
  placeholders: ['null']
639
707
  }),
640
708
  data: data,
@@ -677,8 +745,8 @@ const _ejv = (data, schemes, options) => {
677
745
  const patternsAsArray = stringScheme.pattern;
678
746
  if (!(0, tester_1.minLengthTester)(patternsAsArray, 1)) { // empty array
679
747
  return new interfaces_1.EjvError({
680
- type: constants_1.ErrorType.INVALID_SCHEMES,
681
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.INVALID_STRING_PATTERN, {
748
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
749
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.INVALID_STRING_PATTERN, {
682
750
  placeholders: [createArrayErrorMsg(patternsAsArray)]
683
751
  }),
684
752
  data: data,
@@ -689,7 +757,7 @@ const _ejv = (data, schemes, options) => {
689
757
  try {
690
758
  const regExpPatterns = patternsAsArray.map((pattern) => {
691
759
  if (!isValidPattern(pattern)) {
692
- throw new Error((0, util_1.createErrorMsg)(constants_1.ErrorMsg.INVALID_STRING_PATTERN, {
760
+ throw new Error((0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.INVALID_STRING_PATTERN, {
693
761
  placeholders: [createArrayErrorMsg(patternsAsArray)]
694
762
  }));
695
763
  }
@@ -701,8 +769,8 @@ const _ejv = (data, schemes, options) => {
701
769
  });
702
770
  if (!foundMatchPattern) {
703
771
  result = new interfaces_1.EjvError({
704
- type: constants_1.ErrorType.PATTERN_ONE_OF,
705
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.PATTERN_ONE_OF, {
772
+ type: constants_1.ERROR_TYPE.PATTERN_ONE_OF,
773
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.PATTERN_ONE_OF, {
706
774
  placeholders: [createArrayErrorMsg(patternsAsArray)]
707
775
  }),
708
776
  data,
@@ -713,10 +781,10 @@ const _ejv = (data, schemes, options) => {
713
781
  break;
714
782
  }
715
783
  }
716
- catch (e) {
784
+ catch (e) { // eslint-disable-line @typescript-eslint/no-unused-vars
717
785
  return new interfaces_1.EjvError({
718
- type: constants_1.ErrorType.INVALID_SCHEMES,
719
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.INVALID_STRING_PATTERN, {
786
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
787
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.INVALID_STRING_PATTERN, {
720
788
  placeholders: [createArrayErrorMsg(patternsAsArray)]
721
789
  }),
722
790
  data: data,
@@ -729,8 +797,8 @@ const _ejv = (data, schemes, options) => {
729
797
  const patternAsOne = stringScheme.pattern;
730
798
  if (!isValidPattern(patternAsOne)) {
731
799
  return new interfaces_1.EjvError({
732
- type: constants_1.ErrorType.INVALID_SCHEMES,
733
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.INVALID_STRING_PATTERN, {
800
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
801
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.INVALID_STRING_PATTERN, {
734
802
  placeholders: [patternToString(patternAsOne)]
735
803
  }),
736
804
  data: data,
@@ -742,8 +810,8 @@ const _ejv = (data, schemes, options) => {
742
810
  const regExp = new RegExp(patternAsOne);
743
811
  if (!(0, tester_1.stringRegExpTester)(valueAsString, regExp)) {
744
812
  result = new interfaces_1.EjvError({
745
- type: constants_1.ErrorType.PATTERN,
746
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.PATTERN, {
813
+ type: constants_1.ERROR_TYPE.PATTERN,
814
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.PATTERN, {
747
815
  placeholders: [patternToString(patternAsOne)]
748
816
  }),
749
817
  data,
@@ -757,14 +825,14 @@ const _ejv = (data, schemes, options) => {
757
825
  }
758
826
  break;
759
827
  }
760
- case constants_1.DataType.OBJECT: {
828
+ case constants_1.DATA_TYPE.OBJECT: {
761
829
  const valueAsObject = value;
762
830
  const objectScheme = scheme;
763
831
  if ((0, tester_1.definedTester)(objectScheme.allowNoProperty)) {
764
832
  if (!(0, tester_1.booleanTester)(objectScheme.allowNoProperty)) {
765
833
  return new interfaces_1.EjvError({
766
- type: constants_1.ErrorType.INVALID_SCHEMES,
767
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.ALLOW_NO_PROPERTY_SHOULD_BE_BOOLEAN),
834
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
835
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.ALLOW_NO_PROPERTY_SHOULD_BE_BOOLEAN),
768
836
  data: data,
769
837
  errorScheme: objectScheme,
770
838
  isSchemeError: true
@@ -772,8 +840,8 @@ const _ejv = (data, schemes, options) => {
772
840
  }
773
841
  if (!objectScheme.allowNoProperty && !(0, tester_1.hasPropertyTester)(valueAsObject)) {
774
842
  result = new interfaces_1.EjvError({
775
- type: constants_1.ErrorType.PROPERTY,
776
- message: constants_1.ErrorMsg.PROPERTY,
843
+ type: constants_1.ERROR_TYPE.PROPERTY,
844
+ message: constants_1.ERROR_MESSAGE.PROPERTY,
777
845
  data,
778
846
  path: _options.path,
779
847
  errorScheme: objectScheme,
@@ -785,8 +853,8 @@ const _ejv = (data, schemes, options) => {
785
853
  if ((0, tester_1.definedTester)(objectScheme.properties)) {
786
854
  if (!(0, tester_1.arrayTester)(objectScheme.properties)) {
787
855
  return new interfaces_1.EjvError({
788
- type: constants_1.ErrorType.INVALID_SCHEMES,
789
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.PROPERTIES_SHOULD_BE_ARRAY),
856
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
857
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.PROPERTIES_SHOULD_BE_ARRAY),
790
858
  data: data,
791
859
  errorScheme: objectScheme,
792
860
  isSchemeError: true
@@ -795,17 +863,17 @@ const _ejv = (data, schemes, options) => {
795
863
  const properties = objectScheme.properties;
796
864
  if (!(0, tester_1.minLengthTester)(properties, 1)) {
797
865
  return new interfaces_1.EjvError({
798
- type: constants_1.ErrorType.INVALID_SCHEMES,
799
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.PROPERTIES_SHOULD_HAVE_ITEMS),
866
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
867
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.PROPERTIES_SHOULD_HAVE_ITEMS),
800
868
  data: data,
801
869
  errorScheme: objectScheme,
802
870
  isSchemeError: true
803
871
  });
804
872
  }
805
- if (!(0, tester_1.arrayTypeOfTester)(properties, constants_1.DataType.OBJECT)) {
873
+ if (!(0, tester_1.arrayTypeOfTester)(properties, constants_1.DATA_TYPE.OBJECT)) {
806
874
  return new interfaces_1.EjvError({
807
- type: constants_1.ErrorType.INVALID_SCHEMES,
808
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.PROPERTIES_SHOULD_BE_ARRAY_OF_OBJECT),
875
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
876
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.PROPERTIES_SHOULD_BE_ARRAY_OF_OBJECT),
809
877
  data: data,
810
878
  errorScheme: objectScheme,
811
879
  isSchemeError: true
@@ -813,8 +881,8 @@ const _ejv = (data, schemes, options) => {
813
881
  }
814
882
  if (!(0, tester_1.objectTester)(value)) {
815
883
  result = new interfaces_1.EjvError({
816
- type: constants_1.ErrorType.TYPE_MISMATCH,
817
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.TYPE_MISMATCH, {
884
+ type: constants_1.ERROR_TYPE.TYPE_MISMATCH,
885
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.TYPE_MISMATCH, {
818
886
  placeholders: ['object']
819
887
  }),
820
888
  data,
@@ -836,7 +904,7 @@ const _ejv = (data, schemes, options) => {
836
904
  }
837
905
  break;
838
906
  }
839
- case constants_1.DataType.DATE: {
907
+ case constants_1.DATA_TYPE.DATE: {
840
908
  const valueAsDate = value;
841
909
  const dateScheme = scheme;
842
910
  const parentDateScheme = scheme.parent;
@@ -848,8 +916,8 @@ const _ejv = (data, schemes, options) => {
848
916
  || (0, tester_1.dateTimeFormatTester)(minDateCandidate)))
849
917
  || (0, tester_1.dateTester)(minDateCandidate))) {
850
918
  return new interfaces_1.EjvError({
851
- type: constants_1.ErrorType.INVALID_SCHEMES,
852
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.MIN_DATE_SHOULD_BE_DATE_OR_STRING),
919
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
920
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.MIN_DATE_SHOULD_BE_DATE_OR_STRING),
853
921
  data: data,
854
922
  errorScheme: dateScheme,
855
923
  isSchemeError: true
@@ -859,8 +927,8 @@ const _ejv = (data, schemes, options) => {
859
927
  if ((0, tester_1.definedTester)(dateScheme.exclusiveMin)) {
860
928
  if (!(0, tester_1.booleanTester)(dateScheme.exclusiveMin)) {
861
929
  return new interfaces_1.EjvError({
862
- type: constants_1.ErrorType.INVALID_SCHEMES,
863
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.EXCLUSIVE_MIN_SHOULD_BE_BOOLEAN),
930
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
931
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.EXCLUSIVE_MIN_SHOULD_BE_BOOLEAN),
864
932
  data: data,
865
933
  errorScheme: dateScheme,
866
934
  isSchemeError: true
@@ -869,8 +937,8 @@ const _ejv = (data, schemes, options) => {
869
937
  if (dateScheme.exclusiveMin) {
870
938
  if (!(0, tester_1.exclusiveMinDateTester)(valueAsDate, effectiveMin)) {
871
939
  result = new interfaces_1.EjvError({
872
- type: constants_1.ErrorType.AFTER_DATE,
873
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.AFTER_DATE, {
940
+ type: constants_1.ERROR_TYPE.AFTER_DATE,
941
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.AFTER_DATE, {
874
942
  placeholders: [effectiveMin.toISOString()]
875
943
  }),
876
944
  data,
@@ -884,8 +952,8 @@ const _ejv = (data, schemes, options) => {
884
952
  else {
885
953
  if (!(0, tester_1.minDateTester)(valueAsDate, effectiveMin)) {
886
954
  result = new interfaces_1.EjvError({
887
- type: constants_1.ErrorType.AFTER_OR_SAME_DATE,
888
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.AFTER_OR_SAME_DATE, {
955
+ type: constants_1.ERROR_TYPE.AFTER_OR_SAME_DATE,
956
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.AFTER_OR_SAME_DATE, {
889
957
  placeholders: [effectiveMin.toISOString()]
890
958
  }),
891
959
  data,
@@ -900,8 +968,8 @@ const _ejv = (data, schemes, options) => {
900
968
  else {
901
969
  if (!(0, tester_1.minDateTester)(valueAsDate, effectiveMin)) {
902
970
  result = new interfaces_1.EjvError({
903
- type: constants_1.ErrorType.AFTER_OR_SAME_DATE,
904
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.AFTER_OR_SAME_DATE, {
971
+ type: constants_1.ERROR_TYPE.AFTER_OR_SAME_DATE,
972
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.AFTER_OR_SAME_DATE, {
905
973
  placeholders: [effectiveMin.toISOString()]
906
974
  }),
907
975
  data,
@@ -921,8 +989,8 @@ const _ejv = (data, schemes, options) => {
921
989
  || (0, tester_1.dateTimeFormatTester)(maxDateCandidate)))
922
990
  || (0, tester_1.dateTester)(maxDateCandidate))) {
923
991
  return new interfaces_1.EjvError({
924
- type: constants_1.ErrorType.INVALID_SCHEMES,
925
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.MAX_DATE_SHOULD_BE_DATE_OR_STRING),
992
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
993
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.MAX_DATE_SHOULD_BE_DATE_OR_STRING),
926
994
  data: data,
927
995
  errorScheme: dateScheme,
928
996
  isSchemeError: true
@@ -932,8 +1000,8 @@ const _ejv = (data, schemes, options) => {
932
1000
  if ((0, tester_1.definedTester)(dateScheme.exclusiveMax)) {
933
1001
  if (!(0, tester_1.booleanTester)(dateScheme.exclusiveMax)) {
934
1002
  return new interfaces_1.EjvError({
935
- type: constants_1.ErrorType.INVALID_SCHEMES,
936
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.EXCLUSIVE_MAX_SHOULD_BE_BOOLEAN),
1003
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
1004
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.EXCLUSIVE_MAX_SHOULD_BE_BOOLEAN),
937
1005
  data: data,
938
1006
  errorScheme: dateScheme,
939
1007
  isSchemeError: true
@@ -943,8 +1011,8 @@ const _ejv = (data, schemes, options) => {
943
1011
  if (dateScheme.exclusiveMax) {
944
1012
  if (!(0, tester_1.exclusiveMaxDateTester)(valueAsDate, effectiveMax)) {
945
1013
  result = new interfaces_1.EjvError({
946
- type: constants_1.ErrorType.BEFORE_DATE,
947
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.BEFORE_DATE, {
1014
+ type: constants_1.ERROR_TYPE.BEFORE_DATE,
1015
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.BEFORE_DATE, {
948
1016
  placeholders: [effectiveMax.toISOString()]
949
1017
  }),
950
1018
  data,
@@ -958,8 +1026,8 @@ const _ejv = (data, schemes, options) => {
958
1026
  else {
959
1027
  if (!(0, tester_1.maxDateTester)(valueAsDate, effectiveMax)) {
960
1028
  result = new interfaces_1.EjvError({
961
- type: constants_1.ErrorType.BEFORE_OR_SAME_DATE,
962
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.BEFORE_OR_SAME_DATE, {
1029
+ type: constants_1.ERROR_TYPE.BEFORE_OR_SAME_DATE,
1030
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.BEFORE_OR_SAME_DATE, {
963
1031
  placeholders: [effectiveMax.toISOString()]
964
1032
  }),
965
1033
  data,
@@ -973,15 +1041,15 @@ const _ejv = (data, schemes, options) => {
973
1041
  }
974
1042
  break;
975
1043
  }
976
- case constants_1.DataType.ARRAY: {
1044
+ case constants_1.DATA_TYPE.ARRAY: {
977
1045
  const valueAsArray = value;
978
1046
  const arrayScheme = scheme;
979
1047
  if ((0, tester_1.definedTester)(arrayScheme.length)) {
980
1048
  const length = arrayScheme.length;
981
1049
  if (!((0, tester_1.numberTester)(length) && (0, tester_1.integerTester)(length))) {
982
1050
  return new interfaces_1.EjvError({
983
- type: constants_1.ErrorType.INVALID_SCHEMES,
984
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.LENGTH_SHOULD_BE_INTEGER),
1051
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
1052
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.LENGTH_SHOULD_BE_INTEGER),
985
1053
  data: data,
986
1054
  errorScheme: arrayScheme,
987
1055
  isSchemeError: true
@@ -989,8 +1057,8 @@ const _ejv = (data, schemes, options) => {
989
1057
  }
990
1058
  if (!(0, tester_1.lengthTester)(valueAsArray, length)) {
991
1059
  result = new interfaces_1.EjvError({
992
- type: constants_1.ErrorType.LENGTH,
993
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.LENGTH, {
1060
+ type: constants_1.ERROR_TYPE.LENGTH,
1061
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.LENGTH, {
994
1062
  placeholders: ['' + length]
995
1063
  }),
996
1064
  data,
@@ -1005,8 +1073,8 @@ const _ejv = (data, schemes, options) => {
1005
1073
  const minLength = arrayScheme.minLength;
1006
1074
  if (!((0, tester_1.numberTester)(arrayScheme.minLength) && (0, tester_1.integerTester)(minLength))) {
1007
1075
  return new interfaces_1.EjvError({
1008
- type: constants_1.ErrorType.INVALID_SCHEMES,
1009
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.MIN_LENGTH_SHOULD_BE_INTEGER),
1076
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
1077
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.MIN_LENGTH_SHOULD_BE_INTEGER),
1010
1078
  data: data,
1011
1079
  errorScheme: arrayScheme,
1012
1080
  isSchemeError: true
@@ -1014,8 +1082,8 @@ const _ejv = (data, schemes, options) => {
1014
1082
  }
1015
1083
  if (!(0, tester_1.minLengthTester)(valueAsArray, minLength)) {
1016
1084
  result = new interfaces_1.EjvError({
1017
- type: constants_1.ErrorType.MIN_LENGTH,
1018
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.MIN_LENGTH, {
1085
+ type: constants_1.ERROR_TYPE.MIN_LENGTH,
1086
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.MIN_LENGTH, {
1019
1087
  placeholders: ['' + minLength]
1020
1088
  }),
1021
1089
  data,
@@ -1030,8 +1098,8 @@ const _ejv = (data, schemes, options) => {
1030
1098
  const maxLength = arrayScheme.maxLength;
1031
1099
  if (!((0, tester_1.numberTester)(arrayScheme.maxLength) && (0, tester_1.integerTester)(maxLength))) {
1032
1100
  return new interfaces_1.EjvError({
1033
- type: constants_1.ErrorType.INVALID_SCHEMES,
1034
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.MAX_LENGTH_SHOULD_BE_INTEGER),
1101
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
1102
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.MAX_LENGTH_SHOULD_BE_INTEGER),
1035
1103
  data: data,
1036
1104
  errorScheme: arrayScheme,
1037
1105
  isSchemeError: true
@@ -1039,8 +1107,8 @@ const _ejv = (data, schemes, options) => {
1039
1107
  }
1040
1108
  if (!(0, tester_1.maxLengthTester)(valueAsArray, maxLength)) {
1041
1109
  result = new interfaces_1.EjvError({
1042
- type: constants_1.ErrorType.MAX_LENGTH,
1043
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.MAX_LENGTH, {
1110
+ type: constants_1.ERROR_TYPE.MAX_LENGTH,
1111
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.MAX_LENGTH, {
1044
1112
  placeholders: ['' + maxLength]
1045
1113
  }),
1046
1114
  data,
@@ -1054,8 +1122,8 @@ const _ejv = (data, schemes, options) => {
1054
1122
  if ((0, tester_1.definedTester)(arrayScheme.unique)) {
1055
1123
  if (!(0, tester_1.booleanTester)(arrayScheme.unique)) {
1056
1124
  return new interfaces_1.EjvError({
1057
- type: constants_1.ErrorType.INVALID_SCHEMES,
1058
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.UNIQUE_SHOULD_BE_BOOLEAN),
1125
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
1126
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.UNIQUE_SHOULD_BE_BOOLEAN),
1059
1127
  data: data,
1060
1128
  errorScheme: arrayScheme,
1061
1129
  isSchemeError: true
@@ -1063,8 +1131,8 @@ const _ejv = (data, schemes, options) => {
1063
1131
  }
1064
1132
  if (arrayScheme.unique && !(0, tester_1.uniqueItemsTester)(valueAsArray)) {
1065
1133
  result = new interfaces_1.EjvError({
1066
- type: constants_1.ErrorType.UNIQUE_ITEMS,
1067
- message: constants_1.ErrorMsg.UNIQUE_ITEMS,
1134
+ type: constants_1.ERROR_TYPE.UNIQUE_ITEMS,
1135
+ message: constants_1.ERROR_MESSAGE.UNIQUE_ITEMS,
1068
1136
  data,
1069
1137
  path: _options.path,
1070
1138
  errorScheme: arrayScheme,
@@ -1081,7 +1149,7 @@ const _ejv = (data, schemes, options) => {
1081
1149
  return '' + (+now + i);
1082
1150
  });
1083
1151
  if ((0, tester_1.stringTester)(arrayScheme.items) // by DataType
1084
- || ((0, tester_1.arrayTester)(arrayScheme.items) && (0, tester_1.arrayTypeOfTester)(arrayScheme.items, constants_1.DataType.STRING)) // by DataType[]
1152
+ || ((0, tester_1.arrayTester)(arrayScheme.items) && (0, tester_1.arrayTypeOfTester)(arrayScheme.items, constants_1.DATA_TYPE.STRING)) // by DataType[]
1085
1153
  ) {
1086
1154
  const itemTypes = ((0, tester_1.arrayTester)(arrayScheme.items)
1087
1155
  ? arrayScheme.items
@@ -1093,8 +1161,8 @@ const _ejv = (data, schemes, options) => {
1093
1161
  });
1094
1162
  if (itemTypeError) {
1095
1163
  return new interfaces_1.EjvError({
1096
- type: constants_1.ErrorType.INVALID_SCHEMES,
1097
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.SCHEMES_HAS_INVALID_TYPE, {
1164
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
1165
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.SCHEMES_HAS_INVALID_TYPE, {
1098
1166
  placeholders: [itemTypeError]
1099
1167
  }),
1100
1168
  data: data,
@@ -1118,12 +1186,12 @@ const _ejv = (data, schemes, options) => {
1118
1186
  if (partialResult) {
1119
1187
  let errorMsg;
1120
1188
  if ((0, tester_1.arrayTester)(arrayScheme.items)) {
1121
- errorMsg = (0, util_1.createErrorMsg)(constants_1.ErrorMsg.ITEMS_TYPE, {
1189
+ errorMsg = (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.ITEMS_TYPE, {
1122
1190
  placeholders: [JSON.stringify(itemTypes)]
1123
1191
  });
1124
1192
  }
1125
1193
  else {
1126
- errorMsg = (0, util_1.createErrorMsg)(constants_1.ErrorMsg.ITEMS_TYPE, {
1194
+ errorMsg = (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.ITEMS_TYPE, {
1127
1195
  placeholders: [arrayScheme.items]
1128
1196
  });
1129
1197
  }
@@ -1134,7 +1202,7 @@ const _ejv = (data, schemes, options) => {
1134
1202
  });
1135
1203
  const partialKeyIndex = partialSchemes.indexOf(partialScheme);
1136
1204
  result = new interfaces_1.EjvError({
1137
- type: constants_1.ErrorType.ITEMS_TYPE,
1205
+ type: constants_1.ERROR_TYPE.ITEMS_TYPE,
1138
1206
  message: errorMsg,
1139
1207
  data,
1140
1208
  path: [..._options.path, '' + partialKeyIndex],
@@ -1145,7 +1213,7 @@ const _ejv = (data, schemes, options) => {
1145
1213
  break;
1146
1214
  }
1147
1215
  else if (((0, tester_1.objectTester)(arrayScheme.items) && arrayScheme.items !== null) // by Scheme
1148
- || ((0, tester_1.arrayTester)(arrayScheme.items) && (0, tester_1.arrayTypeOfTester)(arrayScheme.items, constants_1.DataType.OBJECT)) // by Scheme[]
1216
+ || ((0, tester_1.arrayTester)(arrayScheme.items) && (0, tester_1.arrayTypeOfTester)(arrayScheme.items, constants_1.DATA_TYPE.OBJECT)) // by Scheme[]
1149
1217
  ) {
1150
1218
  const itemsAsSchemes = (0, tester_1.arrayTester)(arrayScheme.items)
1151
1219
  ? arrayScheme.items
@@ -1183,18 +1251,18 @@ const _ejv = (data, schemes, options) => {
1183
1251
  let errorType;
1184
1252
  let errorMsg;
1185
1253
  if (!!itemsAsSchemes && itemsAsSchemes.length > 1) {
1186
- errorType = constants_1.ErrorType.ITEMS_SCHEMES;
1187
- errorMsg = (0, util_1.createErrorMsg)(constants_1.ErrorMsg.ITEMS_SCHEMES, {
1254
+ errorType = constants_1.ERROR_TYPE.ITEMS_SCHEMES;
1255
+ errorMsg = (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.ITEMS_SCHEMES, {
1188
1256
  placeholders: [JSON.stringify(itemsAsSchemes)]
1189
1257
  });
1190
1258
  }
1191
1259
  else {
1192
1260
  errorType = partialError.type;
1193
1261
  errorMsg = partialError.message;
1194
- if (errorType === constants_1.ErrorType.REQUIRED) {
1262
+ if (errorType === constants_1.ERROR_TYPE.REQUIRED) {
1195
1263
  // REQUIRED in array is TYPE_MISMATCH except with nullable === true
1196
- errorType = constants_1.ErrorType.TYPE_MISMATCH;
1197
- errorMsg = (0, util_1.createErrorMsg)(constants_1.ErrorMsg.TYPE_MISMATCH, {
1264
+ errorType = constants_1.ERROR_TYPE.TYPE_MISMATCH;
1265
+ errorMsg = (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.TYPE_MISMATCH, {
1198
1266
  placeholders: [JSON.stringify(arrayScheme.items)]
1199
1267
  });
1200
1268
  }
@@ -1204,7 +1272,7 @@ const _ejv = (data, schemes, options) => {
1204
1272
  message: errorMsg,
1205
1273
  data
1206
1274
  });
1207
- if (errorType === constants_1.ErrorType.INVALID_SCHEMES) {
1275
+ if (errorType === constants_1.ERROR_TYPE.INVALID_SCHEMES) {
1208
1276
  result.errorScheme = arrayScheme;
1209
1277
  result.isSchemeError = true;
1210
1278
  result.isDataError = false;
@@ -1218,8 +1286,8 @@ const _ejv = (data, schemes, options) => {
1218
1286
  }
1219
1287
  else {
1220
1288
  return new interfaces_1.EjvError({
1221
- type: constants_1.ErrorType.INVALID_SCHEMES,
1222
- message: (0, util_1.createErrorMsg)(constants_1.ErrorMsg.INVALID_ITEMS_SCHEME, {
1289
+ type: constants_1.ERROR_TYPE.INVALID_SCHEMES,
1290
+ message: (0, util_1.createErrorMsg)(constants_1.ERROR_MESSAGE.INVALID_ITEMS_SCHEME, {
1223
1291
  placeholders: [JSON.stringify(arrayScheme.items)]
1224
1292
  }),
1225
1293
  data: data,
@@ -1250,8 +1318,8 @@ const ejv = (data, schemes, options) => {
1250
1318
  // check data itself
1251
1319
  if (!(0, tester_1.definedTester)(data) || !(0, tester_1.objectTester)(data) || data === null) {
1252
1320
  return new interfaces_1.EjvError({
1253
- type: constants_1.ErrorType.NO_DATA,
1254
- message: constants_1.ErrorMsg.NO_DATA,
1321
+ type: constants_1.ERROR_TYPE.NO_DATA,
1322
+ message: constants_1.ERROR_MESSAGE.NO_DATA,
1255
1323
  data: data,
1256
1324
  path: undefined,
1257
1325
  errorScheme: undefined,