ejv 2.1.1 → 2.1.3
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 +8 -8
- package/CHANGELOG.md +134 -135
- package/LICENSE +21 -21
- package/README-KR.md +604 -597
- package/README.md +608 -603
- package/build/cjs/constants.js +1 -0
- package/build/cjs/constants.js.map +1 -1
- package/build/cjs/ejv.js +3 -0
- package/build/cjs/ejv.js.map +1 -1
- package/build/cjs/package.json +1 -1
- package/build/cjs/tester.js +11 -1
- package/build/cjs/tester.js.map +1 -1
- package/build/constants.d.ts +1 -0
- package/build/esm/constants.js +1 -0
- package/build/esm/constants.js.map +1 -1
- package/build/esm/ejv.js +4 -1
- package/build/esm/ejv.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/tester.js +9 -0
- package/build/esm/tester.js.map +1 -1
- package/build/tester.d.ts +1 -0
- package/eslint.config.mjs +66 -59
- package/package.json +56 -54
- package/scripts/add-js-extensions.ts +59 -59
- package/spec/ArrayScheme.ts +1021 -1021
- package/spec/CommonScheme.ts +251 -251
- package/spec/DateScheme.ts +472 -472
- package/spec/NumberScheme.ts +1160 -1160
- package/spec/ObjectScheme.ts +499 -499
- package/spec/RegExpScheme.ts +112 -112
- package/spec/StringScheme.ts +1407 -1336
- package/spec/common-test-util.ts +63 -63
- package/spec/ejv.spec.ts +235 -235
- package/spec/testers.spec.ts +833 -833
- package/src/constants.ts +164 -162
- package/src/ejv.ts +1751 -1746
- package/src/index.ts +14 -14
- package/src/interfaces.ts +144 -144
- package/src/tester.ts +323 -312
- package/src/util.ts +124 -124
- package/tsconfig.cjs.json +8 -8
- package/tsconfig.esm.json +7 -7
- package/tsconfig.json +19 -19
- package/tsconfig.scripts.json +14 -14
- package/tsconfig.types.json +9 -9
package/spec/RegExpScheme.ts
CHANGED
|
@@ -1,112 +1,112 @@
|
|
|
1
|
-
import { describe, it } from 'mocha';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
|
|
4
|
-
import { ejv } from '../src/ejv';
|
|
5
|
-
|
|
6
|
-
import { EjvError } from '../src/interfaces';
|
|
7
|
-
import { ERROR_MESSAGE, ERROR_TYPE } from '../src/constants';
|
|
8
|
-
import { createErrorMsg } from '../src/util';
|
|
9
|
-
import { TypeTester, typeTesterArr } from './common-test-util';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
describe('RegExpScheme', () => {
|
|
13
|
-
describe('type', () => {
|
|
14
|
-
describe('mismatch', () => {
|
|
15
|
-
typeTesterArr
|
|
16
|
-
.filter((obj: TypeTester): boolean => obj.type !== 'regexp')
|
|
17
|
-
.forEach((obj: TypeTester): void => {
|
|
18
|
-
it(obj.type, () => {
|
|
19
|
-
const testData = {
|
|
20
|
-
a: obj.value
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const error: EjvError | null = ejv(testData, [{
|
|
24
|
-
key: 'a',
|
|
25
|
-
type: 'regexp'
|
|
26
|
-
}]);
|
|
27
|
-
|
|
28
|
-
expect(error).to.be.instanceof(EjvError);
|
|
29
|
-
|
|
30
|
-
if (!error) {
|
|
31
|
-
throw new Error('spec failed');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
expect(error.type).to.be.eql(ERROR_TYPE.TYPE_MISMATCH);
|
|
35
|
-
expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.TYPE_MISMATCH, {
|
|
36
|
-
placeholders: ['regexp']
|
|
37
|
-
}));
|
|
38
|
-
expect(error.path).to.be.eql('a');
|
|
39
|
-
expect(error.data).to.be.deep.equal(testData);
|
|
40
|
-
expect(error.errorData).to.be.eql(obj.value);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('multiple types', () => {
|
|
45
|
-
const value = 'ejv';
|
|
46
|
-
const typeArr: string[] = ['boolean', 'regexp'];
|
|
47
|
-
|
|
48
|
-
const testData = {
|
|
49
|
-
a: value
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const error: EjvError | null = ejv(testData, [{
|
|
53
|
-
key: 'a',
|
|
54
|
-
type: typeArr
|
|
55
|
-
}]);
|
|
56
|
-
|
|
57
|
-
expect(error).to.be.instanceof(EjvError);
|
|
58
|
-
|
|
59
|
-
if (!error) {
|
|
60
|
-
throw new Error('spec failed');
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
expect(error.type).to.be.eql(ERROR_TYPE.TYPE_MISMATCH_ONE_OF);
|
|
64
|
-
expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.TYPE_MISMATCH_ONE_OF, {
|
|
65
|
-
placeholders: [JSON.stringify(typeArr)]
|
|
66
|
-
}));
|
|
67
|
-
expect(error.path).to.be.eql('a');
|
|
68
|
-
expect(error.data).to.be.deep.equal(testData);
|
|
69
|
-
expect(error.errorData).to.be.eql(value);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe('match', () => {
|
|
74
|
-
it('optional', () => {
|
|
75
|
-
expect(ejv({
|
|
76
|
-
a: undefined
|
|
77
|
-
}, [{
|
|
78
|
-
key: 'a',
|
|
79
|
-
type: 'regexp',
|
|
80
|
-
optional: true
|
|
81
|
-
}])).to.be.null;
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('single type', () => {
|
|
85
|
-
expect(ejv({
|
|
86
|
-
a: /./
|
|
87
|
-
}, [{
|
|
88
|
-
key: 'a',
|
|
89
|
-
type: 'regexp'
|
|
90
|
-
}])).to.be.null;
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('multiple types', () => {
|
|
94
|
-
expect(ejv({
|
|
95
|
-
a: /./
|
|
96
|
-
}, [{
|
|
97
|
-
key: 'a',
|
|
98
|
-
type: ['regexp', 'number']
|
|
99
|
-
}])).to.be.null;
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('multiple types', () => {
|
|
103
|
-
expect(ejv({
|
|
104
|
-
a: /./
|
|
105
|
-
}, [{
|
|
106
|
-
key: 'a',
|
|
107
|
-
type: ['number', 'regexp']
|
|
108
|
-
}])).to.be.null;
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
});
|
|
1
|
+
import { describe, it } from 'mocha';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
|
|
4
|
+
import { ejv } from '../src/ejv';
|
|
5
|
+
|
|
6
|
+
import { EjvError } from '../src/interfaces';
|
|
7
|
+
import { ERROR_MESSAGE, ERROR_TYPE } from '../src/constants';
|
|
8
|
+
import { createErrorMsg } from '../src/util';
|
|
9
|
+
import { TypeTester, typeTesterArr } from './common-test-util';
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
describe('RegExpScheme', () => {
|
|
13
|
+
describe('type', () => {
|
|
14
|
+
describe('mismatch', () => {
|
|
15
|
+
typeTesterArr
|
|
16
|
+
.filter((obj: TypeTester): boolean => obj.type !== 'regexp')
|
|
17
|
+
.forEach((obj: TypeTester): void => {
|
|
18
|
+
it(obj.type, () => {
|
|
19
|
+
const testData = {
|
|
20
|
+
a: obj.value
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const error: EjvError | null = ejv(testData, [{
|
|
24
|
+
key: 'a',
|
|
25
|
+
type: 'regexp'
|
|
26
|
+
}]);
|
|
27
|
+
|
|
28
|
+
expect(error).to.be.instanceof(EjvError);
|
|
29
|
+
|
|
30
|
+
if (!error) {
|
|
31
|
+
throw new Error('spec failed');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
expect(error.type).to.be.eql(ERROR_TYPE.TYPE_MISMATCH);
|
|
35
|
+
expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.TYPE_MISMATCH, {
|
|
36
|
+
placeholders: ['regexp']
|
|
37
|
+
}));
|
|
38
|
+
expect(error.path).to.be.eql('a');
|
|
39
|
+
expect(error.data).to.be.deep.equal(testData);
|
|
40
|
+
expect(error.errorData).to.be.eql(obj.value);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('multiple types', () => {
|
|
45
|
+
const value = 'ejv';
|
|
46
|
+
const typeArr: string[] = ['boolean', 'regexp'];
|
|
47
|
+
|
|
48
|
+
const testData = {
|
|
49
|
+
a: value
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const error: EjvError | null = ejv(testData, [{
|
|
53
|
+
key: 'a',
|
|
54
|
+
type: typeArr
|
|
55
|
+
}]);
|
|
56
|
+
|
|
57
|
+
expect(error).to.be.instanceof(EjvError);
|
|
58
|
+
|
|
59
|
+
if (!error) {
|
|
60
|
+
throw new Error('spec failed');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
expect(error.type).to.be.eql(ERROR_TYPE.TYPE_MISMATCH_ONE_OF);
|
|
64
|
+
expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.TYPE_MISMATCH_ONE_OF, {
|
|
65
|
+
placeholders: [JSON.stringify(typeArr)]
|
|
66
|
+
}));
|
|
67
|
+
expect(error.path).to.be.eql('a');
|
|
68
|
+
expect(error.data).to.be.deep.equal(testData);
|
|
69
|
+
expect(error.errorData).to.be.eql(value);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('match', () => {
|
|
74
|
+
it('optional', () => {
|
|
75
|
+
expect(ejv({
|
|
76
|
+
a: undefined
|
|
77
|
+
}, [{
|
|
78
|
+
key: 'a',
|
|
79
|
+
type: 'regexp',
|
|
80
|
+
optional: true
|
|
81
|
+
}])).to.be.null;
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('single type', () => {
|
|
85
|
+
expect(ejv({
|
|
86
|
+
a: /./
|
|
87
|
+
}, [{
|
|
88
|
+
key: 'a',
|
|
89
|
+
type: 'regexp'
|
|
90
|
+
}])).to.be.null;
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('multiple types', () => {
|
|
94
|
+
expect(ejv({
|
|
95
|
+
a: /./
|
|
96
|
+
}, [{
|
|
97
|
+
key: 'a',
|
|
98
|
+
type: ['regexp', 'number']
|
|
99
|
+
}])).to.be.null;
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('multiple types', () => {
|
|
103
|
+
expect(ejv({
|
|
104
|
+
a: /./
|
|
105
|
+
}, [{
|
|
106
|
+
key: 'a',
|
|
107
|
+
type: ['number', 'regexp']
|
|
108
|
+
}])).to.be.null;
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|