ejv 2.1.5 → 2.1.6
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/LICENSE +21 -21
- package/README-KR.md +604 -650
- package/README.md +608 -655
- package/build/cjs/{constants.js → src/constants.js} +0 -10
- package/build/cjs/src/constants.js.map +1 -0
- package/build/cjs/{ejv.js → src/ejv.js} +8 -87
- package/build/cjs/src/ejv.js.map +1 -0
- package/build/cjs/{index.js → src/index.js} +3 -3
- package/build/cjs/src/index.js.map +1 -0
- package/build/{esm → cjs/src}/interfaces.js.map +1 -1
- package/build/cjs/{tester.js → src/tester.js} +126 -146
- package/build/cjs/src/tester.js.map +1 -0
- package/build/cjs/{util.js → src/util.js} +16 -15
- package/build/cjs/src/util.js.map +1 -0
- package/build/esm/{constants.js → src/constants.js} +0 -10
- package/build/esm/src/constants.js.map +1 -0
- package/build/esm/{ejv.js → src/ejv.js} +6 -86
- package/build/esm/src/ejv.js.map +1 -0
- package/build/esm/src/index.js +4 -0
- package/build/esm/src/index.js.map +1 -0
- package/build/esm/src/interfaces.js.map +1 -0
- package/build/esm/{tester.js → src/tester.js} +77 -94
- package/build/esm/src/tester.js.map +1 -0
- package/build/esm/{util.js → src/util.js} +8 -8
- package/build/esm/src/util.js.map +1 -0
- package/build/{constants.d.ts → src/constants.d.ts} +1 -11
- package/build/src/ejv.d.ts +2 -0
- package/build/{interfaces.d.ts → src/interfaces.d.ts} +1 -7
- package/build/src/tester.d.ts +35 -0
- package/build/src/util.d.ts +7 -0
- package/eslint.config.mjs +0 -1
- package/package.json +55 -55
- package/spec/ArrayScheme.ts +12 -113
- package/spec/DateScheme.ts +8 -12
- package/spec/NumberScheme.ts +14 -23
- package/spec/ObjectScheme.ts +9 -12
- package/spec/RegExpScheme.ts +2 -2
- package/spec/StringScheme.ts +18 -34
- package/spec/common-test-util.ts +10 -13
- package/spec/testers.spec.ts +1 -35
- package/src/constants.ts +1 -14
- package/src/ejv.ts +2 -109
- package/src/interfaces.ts +1 -13
- package/src/tester.ts +77 -99
- package/src/util.ts +9 -9
- package/tsconfig.json +8 -2
- package/tsconfig.scripts.json +1 -1
- package/build/cjs/constants.js.map +0 -1
- package/build/cjs/ejv.js.map +0 -1
- package/build/cjs/index.js.map +0 -1
- package/build/cjs/interfaces.js.map +0 -1
- package/build/cjs/tester.js.map +0 -1
- package/build/cjs/util.js.map +0 -1
- package/build/ejv.d.ts +0 -2
- package/build/esm/constants.js.map +0 -1
- package/build/esm/ejv.js.map +0 -1
- package/build/esm/index.js +0 -4
- package/build/esm/index.js.map +0 -1
- package/build/esm/tester.js.map +0 -1
- package/build/esm/util.js.map +0 -1
- package/build/tester.d.ts +0 -39
- package/build/util.d.ts +0 -7
- package/spec/BufferScheme.ts +0 -406
- /package/build/cjs/{interfaces.js → src/interfaces.js} +0 -0
- /package/build/esm/{interfaces.js → src/interfaces.js} +0 -0
- /package/build/{index.d.ts → src/index.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "ejv",
|
|
3
|
-
"version": "2.1.
|
|
4
|
-
"description": "Easy JSON Validator",
|
|
5
|
-
"exports": {
|
|
6
|
-
"require": "./build/cjs/index.js",
|
|
7
|
-
"import": "./build/esm/index.js",
|
|
8
|
-
"types": "./build/index.d.ts"
|
|
9
|
-
},
|
|
10
|
-
"types": "build/index.d.ts",
|
|
11
|
-
"main": "build/cjs/index.js",
|
|
12
|
-
"scripts": {
|
|
13
|
-
"clean": "rimraf ./build",
|
|
14
|
-
"prebuild": "yarn clean",
|
|
15
|
-
"build:types": "tsc -p tsconfig.types.json",
|
|
16
|
-
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
17
|
-
"build:esm": "tsc -p tsconfig.esm.json",
|
|
18
|
-
"build": "yarn build:types&&yarn build:cjs&&yarn build:esm",
|
|
19
|
-
"postbuild": "tsc -p tsconfig.scripts.json&&node build/scripts/add-js-extensions&&node build/scripts/create-package-json",
|
|
20
|
-
"test": "mocha",
|
|
21
|
-
"lint": "eslint"
|
|
22
|
-
},
|
|
23
|
-
"repository": {
|
|
24
|
-
"type": "git",
|
|
25
|
-
"url": "git+https://github.com/han41858/ejv.git"
|
|
26
|
-
},
|
|
27
|
-
"keywords": [
|
|
28
|
-
"json",
|
|
29
|
-
"validator",
|
|
30
|
-
"validation"
|
|
31
|
-
],
|
|
32
|
-
"author": "Janghyun Han <han41858@gmail.com>",
|
|
33
|
-
"license": "MIT",
|
|
34
|
-
"bugs": {
|
|
35
|
-
"url": "https://github.com/han41858/ejv/issues"
|
|
36
|
-
},
|
|
37
|
-
"homepage": "https://github.com/han41858/ejv#readme",
|
|
38
|
-
"devDependencies": {
|
|
39
|
-
"@eslint/js": "^10.0.1",
|
|
40
|
-
"@types/chai": "^5.2.3",
|
|
41
|
-
"@types/mocha": "^10.0.10",
|
|
42
|
-
"@types/node": "
|
|
43
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
44
|
-
"@typescript-eslint/parser": "^8.
|
|
45
|
-
"chai": "^6.2.2",
|
|
46
|
-
"eslint": "^10.
|
|
47
|
-
"eslint-plugin-chai-friendly": "^1.1
|
|
48
|
-
"globals": "^17.
|
|
49
|
-
"mocha": "^11.7.
|
|
50
|
-
"rimraf": "^6.1.
|
|
51
|
-
"tsx": "^4.
|
|
52
|
-
"typescript": "^
|
|
53
|
-
"typescript-eslint": "^8.
|
|
54
|
-
}
|
|
55
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "ejv",
|
|
3
|
+
"version": "2.1.6",
|
|
4
|
+
"description": "Easy JSON Validator",
|
|
5
|
+
"exports": {
|
|
6
|
+
"require": "./build/cjs/index.js",
|
|
7
|
+
"import": "./build/esm/index.js",
|
|
8
|
+
"types": "./build/index.d.ts"
|
|
9
|
+
},
|
|
10
|
+
"types": "build/index.d.ts",
|
|
11
|
+
"main": "build/cjs/index.js",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"clean": "rimraf ./build",
|
|
14
|
+
"prebuild": "yarn clean",
|
|
15
|
+
"build:types": "tsc -p tsconfig.types.json",
|
|
16
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
17
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
18
|
+
"build": "yarn build:types&&yarn build:cjs&&yarn build:esm",
|
|
19
|
+
"postbuild": "tsc -p tsconfig.scripts.json&&node build/scripts/add-js-extensions&&node build/scripts/create-package-json",
|
|
20
|
+
"test": "mocha",
|
|
21
|
+
"lint": "eslint"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/han41858/ejv.git"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"json",
|
|
29
|
+
"validator",
|
|
30
|
+
"validation"
|
|
31
|
+
],
|
|
32
|
+
"author": "Janghyun Han <han41858@gmail.com>",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/han41858/ejv/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/han41858/ejv#readme",
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@eslint/js": "^10.0.1",
|
|
40
|
+
"@types/chai": "^5.2.3",
|
|
41
|
+
"@types/mocha": "^10.0.10",
|
|
42
|
+
"@types/node": "26.1.0",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "^8.62.1",
|
|
44
|
+
"@typescript-eslint/parser": "^8.62.1",
|
|
45
|
+
"chai": "^6.2.2",
|
|
46
|
+
"eslint": "^10.6.0",
|
|
47
|
+
"eslint-plugin-chai-friendly": "^1.2.1",
|
|
48
|
+
"globals": "^17.7.0",
|
|
49
|
+
"mocha": "^11.7.6",
|
|
50
|
+
"rimraf": "^6.1.3",
|
|
51
|
+
"tsx": "^4.23.0",
|
|
52
|
+
"typescript": "^6.0.3",
|
|
53
|
+
"typescript-eslint": "^8.62.1"
|
|
54
|
+
}
|
|
55
|
+
}
|
package/spec/ArrayScheme.ts
CHANGED
|
@@ -6,13 +6,13 @@ import { ejv } from '../src/ejv';
|
|
|
6
6
|
import { EjvError, Scheme } from '../src/interfaces';
|
|
7
7
|
import { ERROR_MESSAGE, ERROR_TYPE } from '../src/constants';
|
|
8
8
|
import { createErrorMsg } from '../src/util';
|
|
9
|
-
import { checkSchemeError,
|
|
9
|
+
import { checkSchemeError, TypeTester, typeTesterArr } from './common-test-util';
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
describe('ArrayScheme', () => {
|
|
13
13
|
describe('type', () => {
|
|
14
14
|
describe('mismatch', () => {
|
|
15
|
-
|
|
15
|
+
typeTesterArr
|
|
16
16
|
.filter((obj: TypeTester): boolean => obj.type !== 'array')
|
|
17
17
|
.forEach((obj: TypeTester): void => {
|
|
18
18
|
it(obj.type, () => {
|
|
@@ -191,100 +191,6 @@ describe('ArrayScheme', () => {
|
|
|
191
191
|
});
|
|
192
192
|
});
|
|
193
193
|
|
|
194
|
-
describe('length', () => {
|
|
195
|
-
describe('check parameter', () => {
|
|
196
|
-
const data = {
|
|
197
|
-
a: [1, 2, 3]
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
it('undefined is ok', () => {
|
|
201
|
-
expect(ejv(data, [{
|
|
202
|
-
key: 'a',
|
|
203
|
-
type: 'array',
|
|
204
|
-
length: undefined
|
|
205
|
-
}])).to.be.null;
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it('null', () => {
|
|
209
|
-
checkSchemeError({
|
|
210
|
-
data: data,
|
|
211
|
-
errorScheme: {
|
|
212
|
-
key: 'a',
|
|
213
|
-
type: 'array',
|
|
214
|
-
// @ts-expect-error: null
|
|
215
|
-
length: null
|
|
216
|
-
},
|
|
217
|
-
|
|
218
|
-
message: createErrorMsg(ERROR_MESSAGE.LENGTH_SHOULD_BE_INTEGER)
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
it('float number', () => {
|
|
223
|
-
checkSchemeError({
|
|
224
|
-
data: data,
|
|
225
|
-
errorScheme: {
|
|
226
|
-
key: 'a',
|
|
227
|
-
type: 'array',
|
|
228
|
-
length: 1.5
|
|
229
|
-
},
|
|
230
|
-
|
|
231
|
-
message: createErrorMsg(ERROR_MESSAGE.LENGTH_SHOULD_BE_INTEGER)
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
it('string', () => {
|
|
236
|
-
checkSchemeError({
|
|
237
|
-
data: data,
|
|
238
|
-
errorScheme: {
|
|
239
|
-
key: 'a',
|
|
240
|
-
type: 'array',
|
|
241
|
-
// @ts-expect-error: type mismatch
|
|
242
|
-
length: '1'
|
|
243
|
-
},
|
|
244
|
-
|
|
245
|
-
message: createErrorMsg(ERROR_MESSAGE.LENGTH_SHOULD_BE_INTEGER)
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
it('fail', () => {
|
|
251
|
-
const value = [1, 2, 3];
|
|
252
|
-
const testData = {
|
|
253
|
-
a: value
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
const error: EjvError | null = ejv(testData, [{
|
|
257
|
-
key: 'a',
|
|
258
|
-
type: 'array',
|
|
259
|
-
length: 2
|
|
260
|
-
}]);
|
|
261
|
-
|
|
262
|
-
expect(error).to.be.instanceof(EjvError);
|
|
263
|
-
|
|
264
|
-
if (!error) {
|
|
265
|
-
throw new Error('spec failed');
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
expect(error.type).to.be.eql(ERROR_TYPE.LENGTH);
|
|
269
|
-
expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.LENGTH, {
|
|
270
|
-
placeholders: [2]
|
|
271
|
-
}));
|
|
272
|
-
expect(error.path).to.be.eql('a');
|
|
273
|
-
expect(error.data).to.be.deep.equal(testData);
|
|
274
|
-
expect(error.errorData).to.be.ordered.members(value);
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
it('ok', () => {
|
|
278
|
-
expect(ejv({
|
|
279
|
-
a: [1, 2, 3]
|
|
280
|
-
}, [{
|
|
281
|
-
key: 'a',
|
|
282
|
-
type: 'array',
|
|
283
|
-
length: 3
|
|
284
|
-
}])).to.be.null;
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
|
|
288
194
|
describe('minLength', () => {
|
|
289
195
|
describe('check parameter', () => {
|
|
290
196
|
const data = {
|
|
@@ -305,8 +211,7 @@ describe('ArrayScheme', () => {
|
|
|
305
211
|
errorScheme: {
|
|
306
212
|
key: 'a',
|
|
307
213
|
type: 'array',
|
|
308
|
-
|
|
309
|
-
minLength: null
|
|
214
|
+
minLength: null as unknown as number
|
|
310
215
|
},
|
|
311
216
|
|
|
312
217
|
message: createErrorMsg(ERROR_MESSAGE.MIN_LENGTH_SHOULD_BE_INTEGER)
|
|
@@ -332,8 +237,7 @@ describe('ArrayScheme', () => {
|
|
|
332
237
|
errorScheme: {
|
|
333
238
|
key: 'a',
|
|
334
239
|
type: 'array',
|
|
335
|
-
|
|
336
|
-
minLength: '1'
|
|
240
|
+
minLength: '1' as unknown as number
|
|
337
241
|
},
|
|
338
242
|
|
|
339
243
|
message: createErrorMsg(ERROR_MESSAGE.MIN_LENGTH_SHOULD_BE_INTEGER)
|
|
@@ -407,8 +311,7 @@ describe('ArrayScheme', () => {
|
|
|
407
311
|
errorScheme: {
|
|
408
312
|
key: 'a',
|
|
409
313
|
type: 'array',
|
|
410
|
-
|
|
411
|
-
maxLength: null
|
|
314
|
+
maxLength: null as unknown as number
|
|
412
315
|
},
|
|
413
316
|
|
|
414
317
|
message: createErrorMsg(ERROR_MESSAGE.MAX_LENGTH_SHOULD_BE_INTEGER)
|
|
@@ -434,8 +337,7 @@ describe('ArrayScheme', () => {
|
|
|
434
337
|
errorScheme: {
|
|
435
338
|
key: 'a',
|
|
436
339
|
type: 'array',
|
|
437
|
-
|
|
438
|
-
maxLength: '1'
|
|
340
|
+
maxLength: '1' as unknown as number
|
|
439
341
|
},
|
|
440
342
|
|
|
441
343
|
message: createErrorMsg(ERROR_MESSAGE.MAX_LENGTH_SHOULD_BE_INTEGER)
|
|
@@ -509,8 +411,7 @@ describe('ArrayScheme', () => {
|
|
|
509
411
|
errorScheme: {
|
|
510
412
|
key: 'a',
|
|
511
413
|
type: 'array',
|
|
512
|
-
|
|
513
|
-
unique: null
|
|
414
|
+
unique: null as unknown as boolean
|
|
514
415
|
},
|
|
515
416
|
|
|
516
417
|
message: createErrorMsg(ERROR_MESSAGE.UNIQUE_SHOULD_BE_BOOLEAN)
|
|
@@ -523,8 +424,7 @@ describe('ArrayScheme', () => {
|
|
|
523
424
|
errorScheme: {
|
|
524
425
|
key: 'a',
|
|
525
426
|
type: 'array',
|
|
526
|
-
|
|
527
|
-
unique: 'hello'
|
|
427
|
+
unique: 'hello' as unknown as boolean
|
|
528
428
|
},
|
|
529
429
|
|
|
530
430
|
message: createErrorMsg(ERROR_MESSAGE.UNIQUE_SHOULD_BE_BOOLEAN)
|
|
@@ -659,8 +559,7 @@ describe('ArrayScheme', () => {
|
|
|
659
559
|
errorScheme: {
|
|
660
560
|
key: 'a',
|
|
661
561
|
type: 'array',
|
|
662
|
-
|
|
663
|
-
items: null
|
|
562
|
+
items: null as unknown as string[]
|
|
664
563
|
},
|
|
665
564
|
|
|
666
565
|
message: createErrorMsg(ERROR_MESSAGE.INVALID_ITEMS_SCHEME, {
|
|
@@ -829,7 +728,7 @@ describe('ArrayScheme', () => {
|
|
|
829
728
|
type: 'array',
|
|
830
729
|
items: {
|
|
831
730
|
type: invalidDataType
|
|
832
|
-
}
|
|
731
|
+
} as unknown as Scheme
|
|
833
732
|
},
|
|
834
733
|
|
|
835
734
|
message: createErrorMsg(ERROR_MESSAGE.SCHEMES_HAS_INVALID_TYPE, {
|
|
@@ -1051,7 +950,7 @@ describe('ArrayScheme', () => {
|
|
|
1051
950
|
});
|
|
1052
951
|
|
|
1053
952
|
it('nested array - single scheme', () => {
|
|
1054
|
-
const arr = ['ok', null];
|
|
953
|
+
const arr: string[] = ['ok', null as unknown as string];
|
|
1055
954
|
const testObj = {
|
|
1056
955
|
a: [{
|
|
1057
956
|
b: arr
|
|
@@ -1085,7 +984,7 @@ describe('ArrayScheme', () => {
|
|
|
1085
984
|
});
|
|
1086
985
|
|
|
1087
986
|
it('nested array - multiple chemes', () => {
|
|
1088
|
-
const arr = ['ok', null];
|
|
987
|
+
const arr: string[] = ['ok', null as unknown as string];
|
|
1089
988
|
const testObj = {
|
|
1090
989
|
a: [{
|
|
1091
990
|
b: arr
|
package/spec/DateScheme.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { ejv } from '../src/ejv';
|
|
|
6
6
|
import { DateScheme, EjvError, Scheme } from '../src/interfaces';
|
|
7
7
|
import { ERROR_MESSAGE, ERROR_TYPE } from '../src/constants';
|
|
8
8
|
import { createErrorMsg } from '../src/util';
|
|
9
|
-
import { checkSchemeError, TypeTester,
|
|
9
|
+
import { checkSchemeError, TypeTester, typeTesterArr } from './common-test-util';
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
describe('DateScheme', () => {
|
|
@@ -86,7 +86,7 @@ describe('DateScheme', () => {
|
|
|
86
86
|
|
|
87
87
|
describe('type', () => {
|
|
88
88
|
describe('mismatch', () => {
|
|
89
|
-
|
|
89
|
+
typeTesterArr
|
|
90
90
|
.filter((obj: TypeTester): boolean => obj.type !== 'date')
|
|
91
91
|
.forEach((obj: TypeTester): void => {
|
|
92
92
|
const data = {
|
|
@@ -203,8 +203,7 @@ describe('DateScheme', () => {
|
|
|
203
203
|
const errorScheme: Scheme = {
|
|
204
204
|
key: 'date',
|
|
205
205
|
type: 'date',
|
|
206
|
-
|
|
207
|
-
min: null
|
|
206
|
+
min: null as unknown as string
|
|
208
207
|
};
|
|
209
208
|
|
|
210
209
|
checkSchemeError({
|
|
@@ -218,7 +217,7 @@ describe('DateScheme', () => {
|
|
|
218
217
|
const errorScheme: Scheme = {
|
|
219
218
|
key: 'date',
|
|
220
219
|
type: 'date',
|
|
221
|
-
min: 123
|
|
220
|
+
min: 123 as unknown as string
|
|
222
221
|
};
|
|
223
222
|
|
|
224
223
|
checkSchemeError({
|
|
@@ -277,8 +276,7 @@ describe('DateScheme', () => {
|
|
|
277
276
|
key: 'date',
|
|
278
277
|
type: 'date',
|
|
279
278
|
min: now,
|
|
280
|
-
|
|
281
|
-
exclusiveMin: now.toISOString()
|
|
279
|
+
exclusiveMin: now.toISOString() as unknown as boolean
|
|
282
280
|
};
|
|
283
281
|
|
|
284
282
|
checkSchemeError({
|
|
@@ -347,8 +345,7 @@ describe('DateScheme', () => {
|
|
|
347
345
|
const errorScheme: Scheme = {
|
|
348
346
|
key: 'date',
|
|
349
347
|
type: 'date',
|
|
350
|
-
|
|
351
|
-
max: null
|
|
348
|
+
max: null as unknown as string
|
|
352
349
|
};
|
|
353
350
|
|
|
354
351
|
checkSchemeError({
|
|
@@ -362,7 +359,7 @@ describe('DateScheme', () => {
|
|
|
362
359
|
const errorScheme: Scheme = {
|
|
363
360
|
key: 'date',
|
|
364
361
|
type: 'date',
|
|
365
|
-
max: 123
|
|
362
|
+
max: 123 as unknown as string
|
|
366
363
|
};
|
|
367
364
|
|
|
368
365
|
checkSchemeError({
|
|
@@ -421,8 +418,7 @@ describe('DateScheme', () => {
|
|
|
421
418
|
key: 'date',
|
|
422
419
|
type: 'date',
|
|
423
420
|
max: now,
|
|
424
|
-
|
|
425
|
-
exclusiveMax: now.toISOString()
|
|
421
|
+
exclusiveMax: now.toISOString() as unknown as boolean
|
|
426
422
|
};
|
|
427
423
|
|
|
428
424
|
checkSchemeError({
|
package/spec/NumberScheme.ts
CHANGED
|
@@ -3,16 +3,16 @@ import { expect } from 'chai';
|
|
|
3
3
|
|
|
4
4
|
import { ejv } from '../src/ejv';
|
|
5
5
|
|
|
6
|
-
import { EjvError,
|
|
6
|
+
import { EjvError, Scheme } from '../src/interfaces';
|
|
7
7
|
import { ERROR_MESSAGE, ERROR_TYPE } from '../src/constants';
|
|
8
8
|
import { createErrorMsg } from '../src/util';
|
|
9
|
-
import { checkSchemeError,
|
|
9
|
+
import { checkSchemeError, TypeTester, typeTesterArr } from './common-test-util';
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
describe('NumberScheme', () => {
|
|
13
13
|
describe('type', () => {
|
|
14
14
|
describe('mismatch', () => {
|
|
15
|
-
|
|
15
|
+
typeTesterArr
|
|
16
16
|
.filter((obj: TypeTester): boolean => obj.type !== 'number')
|
|
17
17
|
.forEach((obj: TypeTester): void => {
|
|
18
18
|
const data = {
|
|
@@ -131,8 +131,7 @@ describe('NumberScheme', () => {
|
|
|
131
131
|
const errorScheme: Scheme = {
|
|
132
132
|
key: 'a',
|
|
133
133
|
type: 'number',
|
|
134
|
-
|
|
135
|
-
enum: null
|
|
134
|
+
enum: null as unknown as number[]
|
|
136
135
|
};
|
|
137
136
|
|
|
138
137
|
checkSchemeError({
|
|
@@ -150,8 +149,7 @@ describe('NumberScheme', () => {
|
|
|
150
149
|
const errorScheme: Scheme = {
|
|
151
150
|
key: 'a',
|
|
152
151
|
type: 'number',
|
|
153
|
-
|
|
154
|
-
enum: 1
|
|
152
|
+
enum: 1 as unknown as number[]
|
|
155
153
|
};
|
|
156
154
|
|
|
157
155
|
checkSchemeError({
|
|
@@ -239,8 +237,7 @@ describe('NumberScheme', () => {
|
|
|
239
237
|
const errorScheme: Scheme = {
|
|
240
238
|
key: 'a',
|
|
241
239
|
type: 'number',
|
|
242
|
-
|
|
243
|
-
notEnum: null
|
|
240
|
+
notEnum: null as unknown as number[]
|
|
244
241
|
};
|
|
245
242
|
|
|
246
243
|
checkSchemeError({
|
|
@@ -258,8 +255,7 @@ describe('NumberScheme', () => {
|
|
|
258
255
|
const errorScheme: Scheme = {
|
|
259
256
|
key: 'a',
|
|
260
257
|
type: 'number',
|
|
261
|
-
|
|
262
|
-
notEnum: 1
|
|
258
|
+
notEnum: 1 as unknown as number[]
|
|
263
259
|
};
|
|
264
260
|
|
|
265
261
|
checkSchemeError({
|
|
@@ -349,8 +345,7 @@ describe('NumberScheme', () => {
|
|
|
349
345
|
const errorScheme: Scheme = {
|
|
350
346
|
key: 'a',
|
|
351
347
|
type: 'number',
|
|
352
|
-
|
|
353
|
-
min: null
|
|
348
|
+
min: null as unknown as number
|
|
354
349
|
};
|
|
355
350
|
|
|
356
351
|
checkSchemeError({
|
|
@@ -434,12 +429,11 @@ describe('NumberScheme', () => {
|
|
|
434
429
|
a: 3
|
|
435
430
|
};
|
|
436
431
|
|
|
437
|
-
const errorScheme:
|
|
432
|
+
const errorScheme: Scheme = {
|
|
438
433
|
key: 'a',
|
|
439
434
|
type: 'number',
|
|
440
435
|
min: 3,
|
|
441
|
-
|
|
442
|
-
exclusiveMin: '3'
|
|
436
|
+
exclusiveMin: '3' as unknown as boolean
|
|
443
437
|
};
|
|
444
438
|
|
|
445
439
|
checkSchemeError({
|
|
@@ -564,8 +558,7 @@ describe('NumberScheme', () => {
|
|
|
564
558
|
const errorScheme: Scheme = {
|
|
565
559
|
key: 'a',
|
|
566
560
|
type: 'number',
|
|
567
|
-
|
|
568
|
-
max: null
|
|
561
|
+
max: null as unknown as number
|
|
569
562
|
};
|
|
570
563
|
|
|
571
564
|
checkSchemeError({
|
|
@@ -649,12 +642,11 @@ describe('NumberScheme', () => {
|
|
|
649
642
|
a: 3
|
|
650
643
|
};
|
|
651
644
|
|
|
652
|
-
const errorScheme:
|
|
645
|
+
const errorScheme: Scheme = {
|
|
653
646
|
key: 'a',
|
|
654
647
|
type: 'number',
|
|
655
648
|
max: 3,
|
|
656
|
-
|
|
657
|
-
exclusiveMax: '3'
|
|
649
|
+
exclusiveMax: '3' as unknown as boolean
|
|
658
650
|
};
|
|
659
651
|
|
|
660
652
|
checkSchemeError({
|
|
@@ -778,8 +770,7 @@ describe('NumberScheme', () => {
|
|
|
778
770
|
const errorScheme: Scheme = {
|
|
779
771
|
key: 'a',
|
|
780
772
|
type: 'number',
|
|
781
|
-
|
|
782
|
-
format: null
|
|
773
|
+
format: null as unknown as string
|
|
783
774
|
};
|
|
784
775
|
|
|
785
776
|
checkSchemeError({
|
package/spec/ObjectScheme.ts
CHANGED
|
@@ -6,15 +6,15 @@ import { ejv } from '../src/ejv';
|
|
|
6
6
|
import { EjvError, Scheme } from '../src/interfaces';
|
|
7
7
|
import { ERROR_MESSAGE, ERROR_TYPE } from '../src/constants';
|
|
8
8
|
import { createErrorMsg } from '../src/util';
|
|
9
|
-
import { checkSchemeError, TypeTester,
|
|
9
|
+
import { checkSchemeError, TypeTester, typeTesterArr } from './common-test-util';
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
describe('ObjectScheme', () => {
|
|
13
13
|
describe('type', () => {
|
|
14
14
|
describe('mismatch', () => {
|
|
15
|
-
|
|
15
|
+
typeTesterArr
|
|
16
16
|
.filter((obj: TypeTester): boolean => {
|
|
17
|
-
return !['null', 'date', 'regexp', 'array', 'object'
|
|
17
|
+
return !['null', 'date', 'regexp', 'array', 'object'].includes(obj.type);
|
|
18
18
|
})
|
|
19
19
|
.forEach((obj: TypeTester): void => {
|
|
20
20
|
const data = {
|
|
@@ -83,9 +83,9 @@ describe('ObjectScheme', () => {
|
|
|
83
83
|
}])).to.be.null;
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
typeTesterArr
|
|
87
87
|
.filter((obj: TypeTester): boolean => {
|
|
88
|
-
return ['null', 'date', 'regexp', 'array', 'object'
|
|
88
|
+
return ['null', 'date', 'regexp', 'array', 'object'].includes(obj.type);
|
|
89
89
|
})
|
|
90
90
|
.forEach((obj: TypeTester): void => {
|
|
91
91
|
it(obj.type, () => {
|
|
@@ -153,8 +153,7 @@ describe('ObjectScheme', () => {
|
|
|
153
153
|
const errorScheme: Scheme = {
|
|
154
154
|
key: 'a',
|
|
155
155
|
type: 'object',
|
|
156
|
-
|
|
157
|
-
properties: null
|
|
156
|
+
properties: null as unknown as Scheme[]
|
|
158
157
|
};
|
|
159
158
|
|
|
160
159
|
checkSchemeError({
|
|
@@ -168,8 +167,7 @@ describe('ObjectScheme', () => {
|
|
|
168
167
|
const errorScheme: Scheme = {
|
|
169
168
|
key: 'a',
|
|
170
169
|
type: 'object',
|
|
171
|
-
|
|
172
|
-
properties: 'b'
|
|
170
|
+
properties: 'b' as unknown as Scheme[]
|
|
173
171
|
};
|
|
174
172
|
|
|
175
173
|
checkSchemeError({
|
|
@@ -197,7 +195,7 @@ describe('ObjectScheme', () => {
|
|
|
197
195
|
const errorScheme: Scheme = {
|
|
198
196
|
key: 'a',
|
|
199
197
|
type: 'object',
|
|
200
|
-
properties: ['b']
|
|
198
|
+
properties: ['b'] as unknown as Scheme[]
|
|
201
199
|
};
|
|
202
200
|
|
|
203
201
|
checkSchemeError({
|
|
@@ -398,8 +396,7 @@ describe('ObjectScheme', () => {
|
|
|
398
396
|
const errorScheme: Scheme = {
|
|
399
397
|
key: 'a',
|
|
400
398
|
type: 'object',
|
|
401
|
-
|
|
402
|
-
allowNoProperty: null
|
|
399
|
+
allowNoProperty: null as unknown as boolean
|
|
403
400
|
};
|
|
404
401
|
|
|
405
402
|
checkSchemeError({
|
package/spec/RegExpScheme.ts
CHANGED
|
@@ -6,13 +6,13 @@ import { ejv } from '../src/ejv';
|
|
|
6
6
|
import { EjvError } from '../src/interfaces';
|
|
7
7
|
import { ERROR_MESSAGE, ERROR_TYPE } from '../src/constants';
|
|
8
8
|
import { createErrorMsg } from '../src/util';
|
|
9
|
-
import { TypeTester,
|
|
9
|
+
import { TypeTester, typeTesterArr } from './common-test-util';
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
describe('RegExpScheme', () => {
|
|
13
13
|
describe('type', () => {
|
|
14
14
|
describe('mismatch', () => {
|
|
15
|
-
|
|
15
|
+
typeTesterArr
|
|
16
16
|
.filter((obj: TypeTester): boolean => obj.type !== 'regexp')
|
|
17
17
|
.forEach((obj: TypeTester): void => {
|
|
18
18
|
it(obj.type, () => {
|