ejv 1.1.10 → 2.0.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/.eslintrc.json +88 -0
- package/.mocharc.json +8 -0
- package/CHANGELOG.md +70 -29
- package/README-KR.md +6 -2
- package/README.md +6 -2
- package/build/{constants.js → cjs/constants.js} +117 -118
- package/build/cjs/constants.js.map +1 -0
- package/build/cjs/ejv.js +1263 -0
- package/build/cjs/ejv.js.map +1 -0
- package/build/{public_api.js → cjs/index.js} +14 -14
- package/build/cjs/index.js.map +1 -0
- package/build/cjs/interfaces.js +29 -0
- package/build/cjs/interfaces.js.map +1 -0
- package/build/cjs/package.json +1 -0
- package/build/{tester.js → cjs/tester.js} +273 -268
- package/build/cjs/tester.js.map +1 -0
- package/build/cjs/util.js +103 -0
- package/build/cjs/util.js.map +1 -0
- package/build/constants.d.ts +101 -104
- package/build/ejv.d.ts +2 -2
- package/build/esm/constants.js +115 -0
- package/build/esm/constants.js.map +1 -0
- package/build/esm/ejv.js +1261 -0
- package/build/esm/ejv.js.map +1 -0
- package/build/esm/index.js +4 -0
- package/build/esm/index.js.map +1 -0
- package/build/esm/interfaces.js +33 -0
- package/build/esm/interfaces.js.map +1 -0
- package/build/esm/package.json +1 -0
- package/build/esm/tester.js +240 -0
- package/build/esm/tester.js.map +1 -0
- package/build/esm/util.js +96 -0
- package/build/esm/util.js.map +1 -0
- package/build/index.d.ts +3 -0
- package/build/interfaces.d.ts +78 -38
- package/build/scripts/add-js-extensions.js +46 -0
- package/build/scripts/add-js-extensions.js.map +1 -0
- package/build/tester.d.ts +33 -34
- package/build/util.d.ts +7 -1
- package/package.json +48 -37
- package/scripts/add-js-extensions.ts +59 -0
- package/spec/ArrayScheme.ts +1021 -0
- package/spec/CommonScheme.ts +251 -0
- package/spec/DateScheme.ts +472 -0
- package/spec/NumberScheme.ts +1032 -0
- package/spec/ObjectScheme.ts +499 -0
- package/spec/RegExpScheme.ts +112 -0
- package/spec/StringScheme.ts +1239 -0
- package/spec/common-test-util.ts +63 -0
- package/spec/ejv.spec.ts +133 -4558
- package/spec/testers.spec.ts +17 -16
- package/src/constants.ts +41 -42
- package/src/ejv.ts +1141 -564
- package/src/index.ts +14 -0
- package/src/interfaces.ts +127 -41
- package/src/tester.ts +75 -69
- package/src/util.ts +106 -41
- package/tsconfig.cjs.json +8 -0
- package/tsconfig.esm.json +7 -0
- package/tsconfig.json +21 -18
- package/tsconfig.scripts.json +14 -0
- package/tsconfig.types.json +9 -0
- package/build/constants.js.map +0 -1
- package/build/ejv.js +0 -685
- package/build/ejv.js.map +0 -1
- package/build/interfaces.js +0 -15
- package/build/interfaces.js.map +0 -1
- package/build/public_api.d.ts +0 -3
- package/build/public_api.js.map +0 -1
- package/build/tester.js.map +0 -1
- package/build/util.js +0 -66
- package/build/util.js.map +0 -1
- package/spec/common-test-runner.ts +0 -17
- package/src/public_api.ts +0 -3
- package/tsconfig.spec.json +0 -19
package/spec/testers.spec.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { describe, it } from 'mocha';
|
|
1
2
|
import { expect } from 'chai';
|
|
2
3
|
|
|
3
|
-
import { commonTestRunner } from './common-test-
|
|
4
|
+
import { commonTestRunner } from './common-test-util';
|
|
4
5
|
|
|
5
6
|
import {
|
|
6
7
|
arrayTester,
|
|
@@ -313,8 +314,8 @@ describe('testers', function () {
|
|
|
313
314
|
|
|
314
315
|
expect(emailTester('a"b(c)d,e:f;g<h>i[j\\k]l@example.com')).to.be.false;
|
|
315
316
|
expect(emailTester('just"not"right@example.com')).to.be.false;
|
|
316
|
-
expect(emailTester('this is"
|
|
317
|
-
expect(emailTester('this
|
|
317
|
+
expect(emailTester('this is"notallowed@example.com')).to.be.false;
|
|
318
|
+
expect(emailTester('this still"not\\allowed@example.com')).to.be.false;
|
|
318
319
|
expect(emailTester('1234567890123456789012345678901234567890123456789012345678901234+x@example.com')).to.be.false;
|
|
319
320
|
expect(emailTester('john..doe@example.com')).to.be.false;
|
|
320
321
|
expect(emailTester('john.doe@example..com')).to.be.false;
|
|
@@ -609,29 +610,29 @@ describe('testers', function () {
|
|
|
609
610
|
it('logic test', () => {
|
|
610
611
|
expect(objectTester(null)).to.be.true;
|
|
611
612
|
expect(objectTester({})).to.be.true;
|
|
612
|
-
expect(objectTester({ a
|
|
613
|
+
expect(objectTester({ a: 1 })).to.be.true;
|
|
613
614
|
});
|
|
614
615
|
});
|
|
615
616
|
|
|
616
617
|
describe('hasPropertyTester()', () => {
|
|
617
618
|
it('logic test', () => {
|
|
618
619
|
expect(hasPropertyTester({})).to.be.false;
|
|
619
|
-
expect(hasPropertyTester({ a
|
|
620
|
+
expect(hasPropertyTester({ a: 1 })).to.be.true;
|
|
620
621
|
});
|
|
621
622
|
});
|
|
622
623
|
});
|
|
623
624
|
|
|
624
625
|
describe('date', () => {
|
|
625
|
-
const now
|
|
626
|
+
const now: Date = new Date();
|
|
626
627
|
|
|
627
|
-
const year
|
|
628
|
-
const month
|
|
629
|
-
const date
|
|
628
|
+
const year: number = now.getFullYear();
|
|
629
|
+
const month: number = now.getMonth();
|
|
630
|
+
const date: number = now.getDate();
|
|
630
631
|
|
|
631
|
-
const hours
|
|
632
|
-
const minutes
|
|
633
|
-
const seconds
|
|
634
|
-
const ms
|
|
632
|
+
const hours: number = now.getHours();
|
|
633
|
+
const minutes: number = now.getMinutes();
|
|
634
|
+
const seconds: number = now.getSeconds();
|
|
635
|
+
const ms: number = now.getMilliseconds();
|
|
635
636
|
|
|
636
637
|
describe('dateTester()', () => {
|
|
637
638
|
it('common test', () => {
|
|
@@ -793,7 +794,7 @@ describe('testers', function () {
|
|
|
793
794
|
expect(arrayTypeOfTester([1, 2], DataType.NUMBER)).to.be.true;
|
|
794
795
|
expect(arrayTypeOfTester([1, 2, '3'], DataType.NUMBER)).to.be.false;
|
|
795
796
|
|
|
796
|
-
expect(arrayTypeOfTester([new Date, new Date, new Date], DataType.DATE)).to.be.true;
|
|
797
|
+
expect(arrayTypeOfTester([new Date(), new Date(), new Date()], DataType.DATE)).to.be.true;
|
|
797
798
|
});
|
|
798
799
|
});
|
|
799
800
|
|
|
@@ -823,9 +824,9 @@ describe('testers', function () {
|
|
|
823
824
|
|
|
824
825
|
it('logic test', () => {
|
|
825
826
|
expect(regExpTester(/\d/)).to.be.true;
|
|
826
|
-
expect(regExpTester(new RegExp('
|
|
827
|
+
expect(regExpTester(new RegExp('d'))).to.be.true;
|
|
827
828
|
|
|
828
|
-
expect(regExpTester('
|
|
829
|
+
expect(regExpTester('d')).to.be.false;
|
|
829
830
|
});
|
|
830
831
|
});
|
|
831
832
|
});
|
package/src/constants.ts
CHANGED
|
@@ -27,22 +27,26 @@ export enum StringFormat {
|
|
|
27
27
|
// IPV6 = 'ipv6'
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
export const ErrorMsgCursorA : string = '<<A>>';
|
|
31
|
-
|
|
32
30
|
export enum ErrorType {
|
|
31
|
+
// about ejv() running
|
|
32
|
+
NO_DATA = 'NO_DATA',
|
|
33
|
+
|
|
34
|
+
NO_SCHEME = 'NO_SCHEME',
|
|
35
|
+
INVALID_SCHEMES = 'INVALID_SCHEMES',
|
|
36
|
+
|
|
37
|
+
// not match with scheme
|
|
33
38
|
REQUIRED = 'REQUIRED',
|
|
34
39
|
|
|
35
40
|
TYPE_MISMATCH = 'TYPE_MISMATCH',
|
|
36
41
|
TYPE_MISMATCH_ONE_OF = 'TYPE_MISMATCH_ONE_OF',
|
|
37
42
|
|
|
38
43
|
ONE_OF = 'ONE_OF',
|
|
39
|
-
NOT_ONE_OF = 'NOT_ONE_OF',
|
|
40
44
|
|
|
41
45
|
FORMAT = 'FORMAT',
|
|
42
46
|
FORMAT_ONE_OF = 'FORMAT_ONE_OF',
|
|
43
47
|
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
BIGGER_THAN_OR_EQUAL = 'BIGGER_THAN_OR_EQUAL',
|
|
49
|
+
BIGGER_THAN = 'BIGGER_THAN',
|
|
46
50
|
|
|
47
51
|
SMALLER_THAN_OR_EQUAL = 'SMALLER_THAN_OR_EQUAL',
|
|
48
52
|
SMALLER_THAN = 'SMALLER_THAN',
|
|
@@ -54,7 +58,7 @@ export enum ErrorType {
|
|
|
54
58
|
PATTERN = 'PATTERN',
|
|
55
59
|
PATTERN_ONE_OF = 'PATTERN_ONE_OF',
|
|
56
60
|
|
|
57
|
-
|
|
61
|
+
PROPERTY = 'PROPERTY',
|
|
58
62
|
|
|
59
63
|
AFTER_OR_SAME_DATE = 'AFTER_OR_SAME_DATE',
|
|
60
64
|
AFTER_DATE = 'AFTER_DATE',
|
|
@@ -76,28 +80,24 @@ export enum ErrorMsg {
|
|
|
76
80
|
NO_ARRAY_SCHEME = 'schemes should be array',
|
|
77
81
|
NO_OBJECT_ARRAY_SCHEME = 'schemes should be array of object',
|
|
78
82
|
|
|
79
|
-
EMPTY_SCHEME = '
|
|
80
|
-
SCHEMES_SHOULD_HAVE_TYPE = '
|
|
81
|
-
SCHEMES_HAS_INVALID_TYPE = 'schemes has invalid type
|
|
82
|
-
SCHEMES_HAS_DUPLICATED_TYPE = 'schemes has duplicated type
|
|
83
|
+
EMPTY_SCHEME = 'schemes should not be empty',
|
|
84
|
+
SCHEMES_SHOULD_HAVE_TYPE = 'schemes should have type',
|
|
85
|
+
SCHEMES_HAS_INVALID_TYPE = 'schemes has invalid type: <<1>>',
|
|
86
|
+
SCHEMES_HAS_DUPLICATED_TYPE = 'schemes has duplicated type: <<1>>',
|
|
83
87
|
|
|
84
88
|
ENUM_SHOULD_BE_ARRAY = 'enum should be array',
|
|
85
89
|
ENUM_SHOULD_BE_NUMBERS = 'enum values should be numbers',
|
|
86
90
|
ENUM_SHOULD_BE_STRINGS = 'enum values should be strings',
|
|
87
91
|
|
|
88
|
-
ENUM_REVERSE_SHOULD_BE_ARRAY = 'enumReverse should be array',
|
|
89
|
-
ENUM_REVERSE_SHOULD_BE_NUMBERS = 'enumReverse values should be numbers',
|
|
90
|
-
ENUM_REVERSE_SHOULD_BE_STRINGS = 'enumReverse values should be strings',
|
|
91
|
-
|
|
92
92
|
MIN_SHOULD_BE_NUMBER = 'min should be number',
|
|
93
93
|
EXCLUSIVE_MIN_SHOULD_BE_BOOLEAN = 'exclusiveMin should be a boolean',
|
|
94
94
|
|
|
95
95
|
MAX_SHOULD_BE_NUMBER = 'max should be number',
|
|
96
96
|
EXCLUSIVE_MAX_SHOULD_BE_BOOLEAN = 'exclusiveMax should be a boolean',
|
|
97
97
|
|
|
98
|
-
INVALID_NUMBER_FORMAT = 'invalid number format
|
|
99
|
-
INVALID_STRING_FORMAT = 'invalid string format
|
|
100
|
-
INVALID_STRING_PATTERN = 'invalid string pattern
|
|
98
|
+
INVALID_NUMBER_FORMAT = 'invalid number format: <<1>>',
|
|
99
|
+
INVALID_STRING_FORMAT = 'invalid string format: <<1>>',
|
|
100
|
+
INVALID_STRING_PATTERN = 'invalid string pattern: <<1>>',
|
|
101
101
|
|
|
102
102
|
LENGTH_SHOULD_BE_INTEGER = 'length should be a integer',
|
|
103
103
|
MIN_LENGTH_SHOULD_BE_INTEGER = 'minLength should be a integer',
|
|
@@ -114,43 +114,42 @@ export enum ErrorMsg {
|
|
|
114
114
|
|
|
115
115
|
UNIQUE_SHOULD_BE_BOOLEAN = 'unique should be a boolean',
|
|
116
116
|
|
|
117
|
-
INVALID_ITEMS_SCHEME = 'invalid schemes of array items
|
|
117
|
+
INVALID_ITEMS_SCHEME = 'invalid schemes of array items: <<1>>',
|
|
118
118
|
|
|
119
119
|
// about EjvError
|
|
120
|
-
REQUIRED = 'required',
|
|
120
|
+
REQUIRED = 'value is required',
|
|
121
121
|
|
|
122
|
-
TYPE_MISMATCH = 'the value should be a <<
|
|
123
|
-
TYPE_MISMATCH_ONE_OF = 'the value should be
|
|
122
|
+
TYPE_MISMATCH = 'the value should be a <<1>>',
|
|
123
|
+
TYPE_MISMATCH_ONE_OF = 'the value should be type of <<1>>',
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
NOT_ONE_OF = 'the value should be not one of <<A>>', // enumReverse
|
|
125
|
+
ONE_VALUE_OF = 'the value should be one of <<1>>', // enum
|
|
127
126
|
|
|
128
|
-
FORMAT = 'the value should be a form of <<
|
|
129
|
-
FORMAT_ONE_OF = 'the value should be form of one of <<
|
|
127
|
+
FORMAT = 'the value should be a form of <<1>>', // format
|
|
128
|
+
FORMAT_ONE_OF = 'the value should be form of one of <<1>>',
|
|
130
129
|
|
|
131
|
-
|
|
132
|
-
|
|
130
|
+
BIGGER_THAN_OR_EQUAL = 'the value should be bigger or equal than <<1>>', // min
|
|
131
|
+
BIGGER_THAN = 'the value should be bigger than <<1>>', // min
|
|
133
132
|
|
|
134
|
-
SMALLER_THAN_OR_EQUAL = 'the value should be smaller or equal than <<
|
|
135
|
-
SMALLER_THAN = 'the value should be smaller than <<
|
|
133
|
+
SMALLER_THAN_OR_EQUAL = 'the value should be smaller or equal than <<1>>', // max
|
|
134
|
+
SMALLER_THAN = 'the value should be smaller than <<1>>', // max
|
|
136
135
|
|
|
137
|
-
LENGTH = 'the value should be length of <<
|
|
138
|
-
MIN_LENGTH = 'the value should be longer than <<
|
|
139
|
-
MAX_LENGTH = 'the value should be shorter than <<
|
|
136
|
+
LENGTH = 'the value should be length of <<1>>', // length
|
|
137
|
+
MIN_LENGTH = 'the value should be longer than <<1>>', // minLength
|
|
138
|
+
MAX_LENGTH = 'the value should be shorter than <<1>>', // maxLength
|
|
140
139
|
|
|
141
|
-
PATTERN = 'the value should be pattern of <<
|
|
142
|
-
PATTERN_ONE_OF = 'the value should be one of pattern of <<
|
|
140
|
+
PATTERN = 'the value should be pattern of <<1>>', // pattern
|
|
141
|
+
PATTERN_ONE_OF = 'the value should be one of pattern of <<1>>', // pattern
|
|
143
142
|
|
|
144
|
-
|
|
143
|
+
PROPERTY = 'the value should have property',
|
|
145
144
|
|
|
146
|
-
AFTER_OR_SAME_DATE = 'the value should be after or same date than <<
|
|
147
|
-
AFTER_DATE = 'the value should be after date than <<
|
|
145
|
+
AFTER_OR_SAME_DATE = 'the value should be after or same date than <<1>>', // date
|
|
146
|
+
AFTER_DATE = 'the value should be after date than <<1>>', // date
|
|
148
147
|
|
|
149
|
-
BEFORE_OR_SAME_DATE = 'the value should be before or same date than <<
|
|
150
|
-
BEFORE_DATE = 'the value should be before date than <<
|
|
148
|
+
BEFORE_OR_SAME_DATE = 'the value should be before or same date than <<1>>', // date
|
|
149
|
+
BEFORE_DATE = 'the value should be before date than <<1>>', // date
|
|
151
150
|
|
|
152
151
|
UNIQUE_ITEMS = 'the array should be unique items',
|
|
153
152
|
|
|
154
|
-
ITEMS_TYPE = 'the array should have items in type of <<
|
|
155
|
-
ITEMS_SCHEMES = 'the array should have items matched with schemes of <<
|
|
156
|
-
}
|
|
153
|
+
ITEMS_TYPE = 'the array should have items in type of <<1>>',
|
|
154
|
+
ITEMS_SCHEMES = 'the array should have items matched with schemes of <<1>>'
|
|
155
|
+
}
|