ejv 2.0.4 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mocharc.json +1 -1
- package/CHANGELOG.md +18 -0
- package/README-KR.md +166 -165
- package/README.md +182 -178
- package/eslint.config.mjs +59 -0
- package/package.json +18 -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/.eslintrc.json +0 -88
- package/build/cjs/constants.js +0 -118
- package/build/cjs/constants.js.map +0 -1
- package/build/cjs/ejv.js +0 -1266
- package/build/cjs/ejv.js.map +0 -1
- package/build/cjs/index.js +0 -14
- package/build/cjs/index.js.map +0 -1
- package/build/cjs/interfaces.js +0 -29
- package/build/cjs/interfaces.js.map +0 -1
- package/build/cjs/package.json +0 -1
- package/build/cjs/tester.js +0 -274
- package/build/cjs/tester.js.map +0 -1
- package/build/cjs/util.js +0 -103
- package/build/cjs/util.js.map +0 -1
- package/build/constants.d.ts +0 -101
- package/build/ejv.d.ts +0 -2
- package/build/esm/constants.js +0 -115
- package/build/esm/constants.js.map +0 -1
- package/build/esm/ejv.js +0 -1264
- 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/interfaces.js +0 -33
- package/build/esm/interfaces.js.map +0 -1
- package/build/esm/package.json +0 -1
- package/build/esm/tester.js +0 -240
- package/build/esm/tester.js.map +0 -1
- package/build/esm/util.js +0 -96
- package/build/esm/util.js.map +0 -1
- package/build/index.d.ts +0 -3
- package/build/interfaces.d.ts +0 -76
- package/build/scripts/add-js-extensions.js +0 -46
- package/build/scripts/add-js-extensions.js.map +0 -1
- package/build/tester.d.ts +0 -33
- package/build/util.d.ts +0 -7
package/spec/ejv.spec.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { describe, it } from 'mocha';
|
|
|
2
2
|
import { expect } from 'chai';
|
|
3
3
|
|
|
4
4
|
import { ejv } from '../src/ejv';
|
|
5
|
-
import {
|
|
5
|
+
import { ERROR_MESSAGE, ERROR_TYPE } from '../src/constants';
|
|
6
6
|
import { AnyObject, EjvError, Scheme } from '../src/interfaces';
|
|
7
7
|
import { createErrorMsg } from '../src/util';
|
|
8
8
|
import { checkSchemeError } from './common-test-util';
|
|
@@ -18,8 +18,8 @@ describe('ejv()', () => {
|
|
|
18
18
|
);
|
|
19
19
|
|
|
20
20
|
expect(error).to.be.instanceof(EjvError);
|
|
21
|
-
expect(error).to.have.property('type',
|
|
22
|
-
expect(error).to.have.property('message',
|
|
21
|
+
expect(error).to.have.property('type', ERROR_TYPE.NO_DATA);
|
|
22
|
+
expect(error).to.have.property('message', ERROR_MESSAGE.NO_DATA);
|
|
23
23
|
|
|
24
24
|
expect(error).to.have.property('data', undefined);
|
|
25
25
|
expect(error).to.have.property('path', undefined);
|
|
@@ -38,8 +38,8 @@ describe('ejv()', () => {
|
|
|
38
38
|
);
|
|
39
39
|
|
|
40
40
|
expect(error).to.be.instanceof(EjvError);
|
|
41
|
-
expect(error).to.have.property('type',
|
|
42
|
-
expect(error).to.have.property('message',
|
|
41
|
+
expect(error).to.have.property('type', ERROR_TYPE.NO_DATA);
|
|
42
|
+
expect(error).to.have.property('message', ERROR_MESSAGE.NO_DATA);
|
|
43
43
|
|
|
44
44
|
expect(error).to.have.property('data', null);
|
|
45
45
|
expect(error).to.have.property('path', undefined);
|
|
@@ -63,8 +63,8 @@ describe('ejv()', () => {
|
|
|
63
63
|
|
|
64
64
|
expect(error).to.be.instanceof(EjvError);
|
|
65
65
|
|
|
66
|
-
expect(error).to.have.property('type',
|
|
67
|
-
expect(error).to.have.property('message',
|
|
66
|
+
expect(error).to.have.property('type', ERROR_TYPE.NO_SCHEME);
|
|
67
|
+
expect(error).to.have.property('message', ERROR_MESSAGE.NO_SCHEME);
|
|
68
68
|
|
|
69
69
|
expect(error).to.have.property('data', data);
|
|
70
70
|
expect(error).to.have.property('path', undefined);
|
|
@@ -82,8 +82,8 @@ describe('ejv()', () => {
|
|
|
82
82
|
|
|
83
83
|
expect(error).to.be.instanceof(EjvError);
|
|
84
84
|
|
|
85
|
-
expect(error).to.have.property('type',
|
|
86
|
-
expect(error).to.have.property('message',
|
|
85
|
+
expect(error).to.have.property('type', ERROR_TYPE.NO_SCHEME);
|
|
86
|
+
expect(error).to.have.property('message', ERROR_MESSAGE.NO_SCHEME);
|
|
87
87
|
|
|
88
88
|
expect(error).to.have.property('data', data);
|
|
89
89
|
expect(error).to.have.property('path', undefined);
|
|
@@ -103,8 +103,8 @@ describe('ejv()', () => {
|
|
|
103
103
|
|
|
104
104
|
expect(error).to.be.instanceof(EjvError);
|
|
105
105
|
|
|
106
|
-
expect(error).to.have.property('type',
|
|
107
|
-
expect(error).to.have.property('message',
|
|
106
|
+
expect(error).to.have.property('type', ERROR_TYPE.INVALID_SCHEMES);
|
|
107
|
+
expect(error).to.have.property('message', ERROR_MESSAGE.EMPTY_SCHEME);
|
|
108
108
|
|
|
109
109
|
expect(error).to.have.property('data', data);
|
|
110
110
|
expect(error).to.have.property('path', undefined);
|
|
@@ -124,8 +124,8 @@ describe('ejv()', () => {
|
|
|
124
124
|
|
|
125
125
|
expect(error).to.be.instanceof(EjvError);
|
|
126
126
|
|
|
127
|
-
expect(error).to.have.property('type',
|
|
128
|
-
expect(error).to.have.property('message',
|
|
127
|
+
expect(error).to.have.property('type', ERROR_TYPE.INVALID_SCHEMES);
|
|
128
|
+
expect(error).to.have.property('message', ERROR_MESSAGE.NO_OBJECT_ARRAY_SCHEME);
|
|
129
129
|
|
|
130
130
|
expect(error).to.have.property('data', data);
|
|
131
131
|
expect(error).to.have.property('path', undefined);
|
|
@@ -145,7 +145,7 @@ describe('ejv()', () => {
|
|
|
145
145
|
checkSchemeError({
|
|
146
146
|
data,
|
|
147
147
|
errorScheme,
|
|
148
|
-
message:
|
|
148
|
+
message: ERROR_MESSAGE.SCHEMES_SHOULD_HAVE_TYPE
|
|
149
149
|
});
|
|
150
150
|
});
|
|
151
151
|
|
|
@@ -158,7 +158,7 @@ describe('ejv()', () => {
|
|
|
158
158
|
checkSchemeError({
|
|
159
159
|
data,
|
|
160
160
|
errorScheme,
|
|
161
|
-
message: createErrorMsg(
|
|
161
|
+
message: createErrorMsg(ERROR_MESSAGE.SCHEMES_HAS_INVALID_TYPE, {
|
|
162
162
|
placeholders: ['invalidType']
|
|
163
163
|
})
|
|
164
164
|
});
|
|
@@ -173,7 +173,7 @@ describe('ejv()', () => {
|
|
|
173
173
|
checkSchemeError({
|
|
174
174
|
data,
|
|
175
175
|
errorScheme,
|
|
176
|
-
message: createErrorMsg(
|
|
176
|
+
message: createErrorMsg(ERROR_MESSAGE.SCHEMES_HAS_DUPLICATED_TYPE, {
|
|
177
177
|
placeholders: ['string']
|
|
178
178
|
})
|
|
179
179
|
});
|
|
@@ -192,7 +192,7 @@ describe('ejv()', () => {
|
|
|
192
192
|
type: 'number'
|
|
193
193
|
}], {
|
|
194
194
|
customErrorMsg: {
|
|
195
|
-
[
|
|
195
|
+
[ERROR_TYPE.REQUIRED]: customErrorMsg
|
|
196
196
|
}
|
|
197
197
|
});
|
|
198
198
|
|
|
@@ -202,7 +202,7 @@ describe('ejv()', () => {
|
|
|
202
202
|
throw new Error('spec failed');
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
expect(error.type).to.be.eql(
|
|
205
|
+
expect(error.type).to.be.eql(ERROR_TYPE.REQUIRED);
|
|
206
206
|
expect(error.message).to.be.eql(customErrorMsg);
|
|
207
207
|
});
|
|
208
208
|
|
|
@@ -216,7 +216,7 @@ describe('ejv()', () => {
|
|
|
216
216
|
type: 'number'
|
|
217
217
|
}], {
|
|
218
218
|
customErrorMsg: {
|
|
219
|
-
[
|
|
219
|
+
[ERROR_TYPE.TYPE_MISMATCH]: customErrorMsg
|
|
220
220
|
}
|
|
221
221
|
});
|
|
222
222
|
|
|
@@ -226,7 +226,7 @@ describe('ejv()', () => {
|
|
|
226
226
|
throw new Error('spec failed');
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
expect(error.type).to.be.eql(
|
|
229
|
+
expect(error.type).to.be.eql(ERROR_TYPE.TYPE_MISMATCH);
|
|
230
230
|
expect(error.message).to.be.eql(customErrorMsg);
|
|
231
231
|
});
|
|
232
232
|
});
|
package/spec/testers.spec.ts
CHANGED
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
timeFormatTester,
|
|
36
36
|
uniqueItemsTester
|
|
37
37
|
} from '../src/tester';
|
|
38
|
-
import {
|
|
38
|
+
import { DATA_TYPE } from '../src/constants';
|
|
39
39
|
|
|
40
40
|
describe('testers', function () {
|
|
41
41
|
describe('common', () => {
|
|
@@ -790,11 +790,11 @@ describe('testers', function () {
|
|
|
790
790
|
|
|
791
791
|
describe('arrayTypeOfTester()', () => {
|
|
792
792
|
it('logic test', () => {
|
|
793
|
-
expect(arrayTypeOfTester([],
|
|
794
|
-
expect(arrayTypeOfTester([1, 2],
|
|
795
|
-
expect(arrayTypeOfTester([1, 2, '3'],
|
|
793
|
+
expect(arrayTypeOfTester([], DATA_TYPE.NUMBER)).to.be.true;
|
|
794
|
+
expect(arrayTypeOfTester([1, 2], DATA_TYPE.NUMBER)).to.be.true;
|
|
795
|
+
expect(arrayTypeOfTester([1, 2, '3'], DATA_TYPE.NUMBER)).to.be.false;
|
|
796
796
|
|
|
797
|
-
expect(arrayTypeOfTester([new Date(), new Date(), new Date()],
|
|
797
|
+
expect(arrayTypeOfTester([new Date(), new Date(), new Date()], DATA_TYPE.DATE)).to.be.true;
|
|
798
798
|
});
|
|
799
799
|
});
|
|
800
800
|
|
package/src/constants.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export enum
|
|
1
|
+
export enum DATA_TYPE {
|
|
2
2
|
BOOLEAN = 'boolean',
|
|
3
3
|
NUMBER = 'number',
|
|
4
4
|
STRING = 'string',
|
|
@@ -8,12 +8,12 @@ export enum DataType {
|
|
|
8
8
|
ARRAY = 'array'
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export enum
|
|
11
|
+
export enum NUMBER_FORMAT {
|
|
12
12
|
INTEGER = 'integer',
|
|
13
13
|
INDEX = 'index'
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export enum
|
|
16
|
+
export enum STRING_FORMAT {
|
|
17
17
|
EMAIL = 'email',
|
|
18
18
|
|
|
19
19
|
DATE = 'date',
|
|
@@ -27,7 +27,7 @@ export enum StringFormat {
|
|
|
27
27
|
// IPV6 = 'ipv6'
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
export enum
|
|
30
|
+
export enum ERROR_TYPE {
|
|
31
31
|
// about ejv() running
|
|
32
32
|
NO_DATA = 'NO_DATA',
|
|
33
33
|
|
|
@@ -41,6 +41,7 @@ export enum ErrorType {
|
|
|
41
41
|
TYPE_MISMATCH_ONE_OF = 'TYPE_MISMATCH_ONE_OF',
|
|
42
42
|
|
|
43
43
|
ONE_VALUE_OF = 'ONE_VALUE_OF',
|
|
44
|
+
NOT_ONE_VALUE_OF = 'NOT_ONE_VALUE_OF',
|
|
44
45
|
|
|
45
46
|
FORMAT = 'FORMAT',
|
|
46
47
|
FORMAT_ONE_OF = 'FORMAT_ONE_OF',
|
|
@@ -72,7 +73,7 @@ export enum ErrorType {
|
|
|
72
73
|
ITEMS_SCHEMES = 'ITEMS_SCHEMES'
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
export enum
|
|
76
|
+
export enum ERROR_MESSAGE {
|
|
76
77
|
// about Error
|
|
77
78
|
NO_DATA = 'no data to validate',
|
|
78
79
|
|
|
@@ -89,6 +90,10 @@ export enum ErrorMsg {
|
|
|
89
90
|
ENUM_SHOULD_BE_NUMBERS = 'enum values should be numbers',
|
|
90
91
|
ENUM_SHOULD_BE_STRINGS = 'enum values should be strings',
|
|
91
92
|
|
|
93
|
+
NOT_ENUM_SHOULD_BE_ARRAY = 'notEnum should be array',
|
|
94
|
+
NOT_ENUM_SHOULD_BE_NUMBERS = 'notEnum values should be numbers',
|
|
95
|
+
NOT_ENUM_SHOULD_BE_STRINGS = 'notEnum values should be strings',
|
|
96
|
+
|
|
92
97
|
MIN_SHOULD_BE_NUMBER = 'min should be number',
|
|
93
98
|
EXCLUSIVE_MIN_SHOULD_BE_BOOLEAN = 'exclusiveMin should be a boolean',
|
|
94
99
|
|
|
@@ -123,6 +128,7 @@ export enum ErrorMsg {
|
|
|
123
128
|
TYPE_MISMATCH_ONE_OF = 'the value should be type of <<1>>',
|
|
124
129
|
|
|
125
130
|
ONE_VALUE_OF = 'the value should be one of <<1>>', // enum
|
|
131
|
+
NOT_ONE_VALUE_OF = 'the value should not be one of <<1>>', // enum
|
|
126
132
|
|
|
127
133
|
FORMAT = 'the value should be a form of <<1>>', // format
|
|
128
134
|
FORMAT_ONE_OF = 'the value should be form of one of <<1>>',
|
|
@@ -153,3 +159,4 @@ export enum ErrorMsg {
|
|
|
153
159
|
ITEMS_TYPE = 'the array should have items in type of <<1>>',
|
|
154
160
|
ITEMS_SCHEMES = 'the array should have items matched with schemes of <<1>>'
|
|
155
161
|
}
|
|
162
|
+
|