ejv 2.1.1 → 2.1.2

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 (42) hide show
  1. package/.mocharc.json +8 -8
  2. package/CHANGELOG.md +134 -135
  3. package/README-KR.md +597 -597
  4. package/README.md +603 -603
  5. package/build/cjs/constants.js +1 -0
  6. package/build/cjs/constants.js.map +1 -1
  7. package/build/cjs/ejv.js +3 -0
  8. package/build/cjs/ejv.js.map +1 -1
  9. package/build/cjs/tester.js +11 -1
  10. package/build/cjs/tester.js.map +1 -1
  11. package/build/constants.d.ts +1 -0
  12. package/build/esm/constants.js +1 -0
  13. package/build/esm/constants.js.map +1 -1
  14. package/build/esm/ejv.js +4 -1
  15. package/build/esm/ejv.js.map +1 -1
  16. package/build/esm/tester.js +9 -0
  17. package/build/esm/tester.js.map +1 -1
  18. package/build/tester.d.ts +1 -0
  19. package/eslint.config.mjs +66 -59
  20. package/package.json +54 -54
  21. package/scripts/add-js-extensions.ts +59 -59
  22. package/spec/ArrayScheme.ts +1021 -1021
  23. package/spec/CommonScheme.ts +251 -251
  24. package/spec/DateScheme.ts +472 -472
  25. package/spec/NumberScheme.ts +1160 -1160
  26. package/spec/ObjectScheme.ts +499 -499
  27. package/spec/RegExpScheme.ts +112 -112
  28. package/spec/StringScheme.ts +1407 -1336
  29. package/spec/common-test-util.ts +63 -63
  30. package/spec/ejv.spec.ts +235 -235
  31. package/spec/testers.spec.ts +833 -833
  32. package/src/constants.ts +164 -162
  33. package/src/ejv.ts +1751 -1746
  34. package/src/index.ts +14 -14
  35. package/src/interfaces.ts +144 -144
  36. package/src/tester.ts +323 -312
  37. package/src/util.ts +124 -124
  38. package/tsconfig.cjs.json +8 -8
  39. package/tsconfig.esm.json +7 -7
  40. package/tsconfig.json +19 -19
  41. package/tsconfig.scripts.json +14 -14
  42. package/tsconfig.types.json +9 -9
@@ -1,251 +1,251 @@
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
-
10
-
11
- describe('CommonScheme', () => {
12
- describe('optional', () => {
13
- describe('default', () => {
14
- it('undefined value', () => {
15
- const data = {
16
- a: undefined
17
- };
18
-
19
- const error: EjvError | null = ejv(data, [{
20
- key: 'a',
21
- type: 'string'
22
- }]);
23
-
24
- expect(error).to.be.instanceof(EjvError);
25
-
26
- if (!error) {
27
- throw new Error('spec failed');
28
- }
29
-
30
- expect(error.type).to.be.eql(ERROR_TYPE.REQUIRED);
31
- expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.REQUIRED));
32
- expect(error.path).to.be.eql('a');
33
- expect(error.data).to.be.deep.equal(data);
34
- expect(error.errorData).to.be.undefined;
35
- });
36
-
37
- it('correct type', () => {
38
- const error: EjvError | null = ejv({
39
- a: 'abc'
40
- }, [{
41
- key: 'a',
42
- type: 'string'
43
- }]);
44
-
45
- expect(error).to.be.null;
46
- });
47
-
48
- it('incorrect type', () => {
49
- const data = {
50
- a: 123
51
- };
52
-
53
- const error: EjvError | null = ejv(data, [{
54
- key: 'a',
55
- type: 'string'
56
- }]);
57
-
58
- expect(error).to.be.instanceof(EjvError);
59
-
60
- if (!error) {
61
- throw new Error('spec failed');
62
- }
63
-
64
- expect(error.type).to.be.eql(ERROR_TYPE.TYPE_MISMATCH);
65
- expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.TYPE_MISMATCH, {
66
- placeholders: ['string']
67
- }));
68
- expect(error.path).to.be.eql('a');
69
- expect(error.data).to.be.deep.equal(data);
70
- expect(error.errorData).to.be.eql(123);
71
- });
72
- });
73
-
74
- describe('optional === false', () => {
75
- it('undefined value', () => {
76
- const data = {
77
- a: undefined
78
- };
79
-
80
- const error: EjvError | null = ejv(data, [{
81
- key: 'a',
82
- type: 'string',
83
- optional: false
84
- }]);
85
-
86
- expect(error).to.be.instanceof(EjvError);
87
-
88
- if (!error) {
89
- throw new Error('spec failed');
90
- }
91
-
92
- expect(error.type).to.be.eql(ERROR_TYPE.REQUIRED);
93
- expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.REQUIRED));
94
- expect(error.path).to.be.eql('a');
95
- expect(error.data).to.be.deep.equal(data);
96
- expect(error.errorData).to.be.undefined;
97
- });
98
-
99
- it('correct type', () => {
100
- const error: EjvError | null = ejv({
101
- a: 'abc'
102
- }, [{
103
- key: 'a',
104
- type: 'string',
105
- optional: false
106
- }]);
107
-
108
- expect(error).to.be.null;
109
- });
110
-
111
- it('incorrect type', () => {
112
- const data = {
113
- a: 123
114
- };
115
-
116
- const error: EjvError | null = ejv(data, [{
117
- key: 'a',
118
- type: 'string',
119
- optional: false
120
- }]);
121
-
122
- expect(error).to.be.instanceof(EjvError);
123
-
124
- if (!error) {
125
- throw new Error('spec failed');
126
- }
127
-
128
- expect(error.type).to.be.eql(ERROR_TYPE.TYPE_MISMATCH);
129
- expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.TYPE_MISMATCH, {
130
- placeholders: ['string']
131
- }));
132
- expect(error.path).to.be.eql('a');
133
- expect(error.data).to.be.deep.equal(data);
134
- expect(error.errorData).to.be.eql(123);
135
- });
136
- });
137
-
138
- describe('optional === true', () => {
139
- it('undefined value', () => {
140
- const error: EjvError | null = ejv({
141
- a: undefined
142
- }, [{
143
- key: 'a',
144
- type: 'string',
145
- optional: true
146
- }]);
147
-
148
- expect(error).to.be.null;
149
- });
150
-
151
- it('correct type', () => {
152
- const error: EjvError | null = ejv({
153
- a: 'abc'
154
- }, [{
155
- key: 'a',
156
- type: 'string',
157
- optional: true
158
- }]);
159
-
160
- expect(error).to.be.null;
161
- });
162
-
163
- it('incorrect type', () => {
164
- const data = {
165
- a: 123
166
- };
167
-
168
- const error: EjvError | null = ejv(data, [{
169
- key: 'a',
170
- type: 'string',
171
- optional: true
172
- }]);
173
-
174
- expect(error).to.be.instanceof(EjvError);
175
-
176
- if (!error) {
177
- throw new Error('spec failed');
178
- }
179
-
180
- expect(error.type).to.be.eql(ERROR_TYPE.TYPE_MISMATCH);
181
- expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.TYPE_MISMATCH, {
182
- placeholders: ['string']
183
- }));
184
- expect(error.path).to.be.eql('a');
185
- expect(error.data).to.be.deep.equal(data);
186
- expect(error.errorData).to.be.eql(123);
187
- });
188
- });
189
- });
190
-
191
- describe('nullable', () => {
192
- it('default', () => {
193
- const data = {
194
- a: null
195
- };
196
-
197
- const error: EjvError | null = ejv(data, [{
198
- key: 'a',
199
- type: 'string'
200
- }]);
201
-
202
- expect(error).to.be.instanceof(EjvError);
203
-
204
- if (!error) {
205
- throw new Error('spec failed');
206
- }
207
-
208
- expect(error.type).to.be.eql(ERROR_TYPE.REQUIRED);
209
- expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.REQUIRED));
210
- expect(error.path).to.be.eql('a');
211
- expect(error.data).to.be.deep.equal(data);
212
- expect(error.errorData).to.be.null;
213
- });
214
-
215
- it('nullable === false', () => {
216
- const data = {
217
- a: null
218
- };
219
-
220
- const error: EjvError | null = ejv(data, [{
221
- key: 'a',
222
- type: 'string',
223
- nullable: false
224
- }]);
225
-
226
- expect(error).to.be.instanceof(EjvError);
227
-
228
- if (!error) {
229
- throw new Error('spec failed');
230
- }
231
-
232
- expect(error.type).to.be.eql(ERROR_TYPE.REQUIRED);
233
- expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.REQUIRED));
234
- expect(error.path).to.be.eql('a');
235
- expect(error.data).to.be.deep.equal(data);
236
- expect(error.errorData).to.be.null;
237
- });
238
-
239
- it('nullable === true', () => {
240
- const error: EjvError | null = ejv({
241
- a: null
242
- }, [{
243
- key: 'a',
244
- type: 'string',
245
- nullable: true
246
- }]);
247
-
248
- expect(error).to.be.null;
249
- });
250
- });
251
- });
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
+
10
+
11
+ describe('CommonScheme', () => {
12
+ describe('optional', () => {
13
+ describe('default', () => {
14
+ it('undefined value', () => {
15
+ const data = {
16
+ a: undefined
17
+ };
18
+
19
+ const error: EjvError | null = ejv(data, [{
20
+ key: 'a',
21
+ type: 'string'
22
+ }]);
23
+
24
+ expect(error).to.be.instanceof(EjvError);
25
+
26
+ if (!error) {
27
+ throw new Error('spec failed');
28
+ }
29
+
30
+ expect(error.type).to.be.eql(ERROR_TYPE.REQUIRED);
31
+ expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.REQUIRED));
32
+ expect(error.path).to.be.eql('a');
33
+ expect(error.data).to.be.deep.equal(data);
34
+ expect(error.errorData).to.be.undefined;
35
+ });
36
+
37
+ it('correct type', () => {
38
+ const error: EjvError | null = ejv({
39
+ a: 'abc'
40
+ }, [{
41
+ key: 'a',
42
+ type: 'string'
43
+ }]);
44
+
45
+ expect(error).to.be.null;
46
+ });
47
+
48
+ it('incorrect type', () => {
49
+ const data = {
50
+ a: 123
51
+ };
52
+
53
+ const error: EjvError | null = ejv(data, [{
54
+ key: 'a',
55
+ type: 'string'
56
+ }]);
57
+
58
+ expect(error).to.be.instanceof(EjvError);
59
+
60
+ if (!error) {
61
+ throw new Error('spec failed');
62
+ }
63
+
64
+ expect(error.type).to.be.eql(ERROR_TYPE.TYPE_MISMATCH);
65
+ expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.TYPE_MISMATCH, {
66
+ placeholders: ['string']
67
+ }));
68
+ expect(error.path).to.be.eql('a');
69
+ expect(error.data).to.be.deep.equal(data);
70
+ expect(error.errorData).to.be.eql(123);
71
+ });
72
+ });
73
+
74
+ describe('optional === false', () => {
75
+ it('undefined value', () => {
76
+ const data = {
77
+ a: undefined
78
+ };
79
+
80
+ const error: EjvError | null = ejv(data, [{
81
+ key: 'a',
82
+ type: 'string',
83
+ optional: false
84
+ }]);
85
+
86
+ expect(error).to.be.instanceof(EjvError);
87
+
88
+ if (!error) {
89
+ throw new Error('spec failed');
90
+ }
91
+
92
+ expect(error.type).to.be.eql(ERROR_TYPE.REQUIRED);
93
+ expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.REQUIRED));
94
+ expect(error.path).to.be.eql('a');
95
+ expect(error.data).to.be.deep.equal(data);
96
+ expect(error.errorData).to.be.undefined;
97
+ });
98
+
99
+ it('correct type', () => {
100
+ const error: EjvError | null = ejv({
101
+ a: 'abc'
102
+ }, [{
103
+ key: 'a',
104
+ type: 'string',
105
+ optional: false
106
+ }]);
107
+
108
+ expect(error).to.be.null;
109
+ });
110
+
111
+ it('incorrect type', () => {
112
+ const data = {
113
+ a: 123
114
+ };
115
+
116
+ const error: EjvError | null = ejv(data, [{
117
+ key: 'a',
118
+ type: 'string',
119
+ optional: false
120
+ }]);
121
+
122
+ expect(error).to.be.instanceof(EjvError);
123
+
124
+ if (!error) {
125
+ throw new Error('spec failed');
126
+ }
127
+
128
+ expect(error.type).to.be.eql(ERROR_TYPE.TYPE_MISMATCH);
129
+ expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.TYPE_MISMATCH, {
130
+ placeholders: ['string']
131
+ }));
132
+ expect(error.path).to.be.eql('a');
133
+ expect(error.data).to.be.deep.equal(data);
134
+ expect(error.errorData).to.be.eql(123);
135
+ });
136
+ });
137
+
138
+ describe('optional === true', () => {
139
+ it('undefined value', () => {
140
+ const error: EjvError | null = ejv({
141
+ a: undefined
142
+ }, [{
143
+ key: 'a',
144
+ type: 'string',
145
+ optional: true
146
+ }]);
147
+
148
+ expect(error).to.be.null;
149
+ });
150
+
151
+ it('correct type', () => {
152
+ const error: EjvError | null = ejv({
153
+ a: 'abc'
154
+ }, [{
155
+ key: 'a',
156
+ type: 'string',
157
+ optional: true
158
+ }]);
159
+
160
+ expect(error).to.be.null;
161
+ });
162
+
163
+ it('incorrect type', () => {
164
+ const data = {
165
+ a: 123
166
+ };
167
+
168
+ const error: EjvError | null = ejv(data, [{
169
+ key: 'a',
170
+ type: 'string',
171
+ optional: true
172
+ }]);
173
+
174
+ expect(error).to.be.instanceof(EjvError);
175
+
176
+ if (!error) {
177
+ throw new Error('spec failed');
178
+ }
179
+
180
+ expect(error.type).to.be.eql(ERROR_TYPE.TYPE_MISMATCH);
181
+ expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.TYPE_MISMATCH, {
182
+ placeholders: ['string']
183
+ }));
184
+ expect(error.path).to.be.eql('a');
185
+ expect(error.data).to.be.deep.equal(data);
186
+ expect(error.errorData).to.be.eql(123);
187
+ });
188
+ });
189
+ });
190
+
191
+ describe('nullable', () => {
192
+ it('default', () => {
193
+ const data = {
194
+ a: null
195
+ };
196
+
197
+ const error: EjvError | null = ejv(data, [{
198
+ key: 'a',
199
+ type: 'string'
200
+ }]);
201
+
202
+ expect(error).to.be.instanceof(EjvError);
203
+
204
+ if (!error) {
205
+ throw new Error('spec failed');
206
+ }
207
+
208
+ expect(error.type).to.be.eql(ERROR_TYPE.REQUIRED);
209
+ expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.REQUIRED));
210
+ expect(error.path).to.be.eql('a');
211
+ expect(error.data).to.be.deep.equal(data);
212
+ expect(error.errorData).to.be.null;
213
+ });
214
+
215
+ it('nullable === false', () => {
216
+ const data = {
217
+ a: null
218
+ };
219
+
220
+ const error: EjvError | null = ejv(data, [{
221
+ key: 'a',
222
+ type: 'string',
223
+ nullable: false
224
+ }]);
225
+
226
+ expect(error).to.be.instanceof(EjvError);
227
+
228
+ if (!error) {
229
+ throw new Error('spec failed');
230
+ }
231
+
232
+ expect(error.type).to.be.eql(ERROR_TYPE.REQUIRED);
233
+ expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.REQUIRED));
234
+ expect(error.path).to.be.eql('a');
235
+ expect(error.data).to.be.deep.equal(data);
236
+ expect(error.errorData).to.be.null;
237
+ });
238
+
239
+ it('nullable === true', () => {
240
+ const error: EjvError | null = ejv({
241
+ a: null
242
+ }, [{
243
+ key: 'a',
244
+ type: 'string',
245
+ nullable: true
246
+ }]);
247
+
248
+ expect(error).to.be.null;
249
+ });
250
+ });
251
+ });