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.
Files changed (75) hide show
  1. package/.eslintrc.json +88 -0
  2. package/.mocharc.json +8 -0
  3. package/CHANGELOG.md +70 -29
  4. package/README-KR.md +6 -2
  5. package/README.md +6 -2
  6. package/build/{constants.js → cjs/constants.js} +117 -118
  7. package/build/cjs/constants.js.map +1 -0
  8. package/build/cjs/ejv.js +1263 -0
  9. package/build/cjs/ejv.js.map +1 -0
  10. package/build/{public_api.js → cjs/index.js} +14 -14
  11. package/build/cjs/index.js.map +1 -0
  12. package/build/cjs/interfaces.js +29 -0
  13. package/build/cjs/interfaces.js.map +1 -0
  14. package/build/cjs/package.json +1 -0
  15. package/build/{tester.js → cjs/tester.js} +273 -268
  16. package/build/cjs/tester.js.map +1 -0
  17. package/build/cjs/util.js +103 -0
  18. package/build/cjs/util.js.map +1 -0
  19. package/build/constants.d.ts +101 -104
  20. package/build/ejv.d.ts +2 -2
  21. package/build/esm/constants.js +115 -0
  22. package/build/esm/constants.js.map +1 -0
  23. package/build/esm/ejv.js +1261 -0
  24. package/build/esm/ejv.js.map +1 -0
  25. package/build/esm/index.js +4 -0
  26. package/build/esm/index.js.map +1 -0
  27. package/build/esm/interfaces.js +33 -0
  28. package/build/esm/interfaces.js.map +1 -0
  29. package/build/esm/package.json +1 -0
  30. package/build/esm/tester.js +240 -0
  31. package/build/esm/tester.js.map +1 -0
  32. package/build/esm/util.js +96 -0
  33. package/build/esm/util.js.map +1 -0
  34. package/build/index.d.ts +3 -0
  35. package/build/interfaces.d.ts +78 -38
  36. package/build/scripts/add-js-extensions.js +46 -0
  37. package/build/scripts/add-js-extensions.js.map +1 -0
  38. package/build/tester.d.ts +33 -34
  39. package/build/util.d.ts +7 -1
  40. package/package.json +48 -37
  41. package/scripts/add-js-extensions.ts +59 -0
  42. package/spec/ArrayScheme.ts +1021 -0
  43. package/spec/CommonScheme.ts +251 -0
  44. package/spec/DateScheme.ts +472 -0
  45. package/spec/NumberScheme.ts +1032 -0
  46. package/spec/ObjectScheme.ts +499 -0
  47. package/spec/RegExpScheme.ts +112 -0
  48. package/spec/StringScheme.ts +1239 -0
  49. package/spec/common-test-util.ts +63 -0
  50. package/spec/ejv.spec.ts +133 -4558
  51. package/spec/testers.spec.ts +17 -16
  52. package/src/constants.ts +41 -42
  53. package/src/ejv.ts +1141 -564
  54. package/src/index.ts +14 -0
  55. package/src/interfaces.ts +127 -41
  56. package/src/tester.ts +75 -69
  57. package/src/util.ts +106 -41
  58. package/tsconfig.cjs.json +8 -0
  59. package/tsconfig.esm.json +7 -0
  60. package/tsconfig.json +21 -18
  61. package/tsconfig.scripts.json +14 -0
  62. package/tsconfig.types.json +9 -0
  63. package/build/constants.js.map +0 -1
  64. package/build/ejv.js +0 -685
  65. package/build/ejv.js.map +0 -1
  66. package/build/interfaces.js +0 -15
  67. package/build/interfaces.js.map +0 -1
  68. package/build/public_api.d.ts +0 -3
  69. package/build/public_api.js.map +0 -1
  70. package/build/tester.js.map +0 -1
  71. package/build/util.js +0 -66
  72. package/build/util.js.map +0 -1
  73. package/spec/common-test-runner.ts +0 -17
  74. package/src/public_api.ts +0 -3
  75. package/tsconfig.spec.json +0 -19
@@ -1,6 +1,7 @@
1
+ import { describe, it } from 'mocha';
1
2
  import { expect } from 'chai';
2
3
 
3
- import { commonTestRunner } from './common-test-runner';
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"not\allowed@example.com')).to.be.false;
317
- expect(emailTester('this\ still\"not\\allowed@example.com')).to.be.false;
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 : 1 })).to.be.true;
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 : 1 })).to.be.true;
620
+ expect(hasPropertyTester({ a: 1 })).to.be.true;
620
621
  });
621
622
  });
622
623
  });
623
624
 
624
625
  describe('date', () => {
625
- const now : Date = new Date();
626
+ const now: Date = new Date();
626
627
 
627
- const year : number = now.getFullYear();
628
- const month : number = now.getMonth();
629
- const date : number = now.getDate();
628
+ const year: number = now.getFullYear();
629
+ const month: number = now.getMonth();
630
+ const date: number = now.getDate();
630
631
 
631
- const hours : number = now.getHours();
632
- const minutes : number = now.getMinutes();
633
- const seconds : number = now.getSeconds();
634
- const ms : number = now.getMilliseconds();
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('\d'))).to.be.true;
827
+ expect(regExpTester(new RegExp('d'))).to.be.true;
827
828
 
828
- expect(regExpTester('\d')).to.be.false;
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
- GREATER_THAN_OR_EQUAL = 'GREATER_THAN_OR_EQUAL',
45
- GREATER_THAN = 'GREATER_THAN',
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
- NO_PROPERTY = 'NO_PROPERTY',
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 = 'scheme should not be empty',
80
- SCHEMES_SHOULD_HAVE_TYPE = 'scheme should have type',
81
- SCHEMES_HAS_INVALID_TYPE = 'schemes has invalid type : <<A>>',
82
- SCHEMES_HAS_DUPLICATED_TYPE = 'schemes has duplicated type : <<A>>',
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 : <<A>>',
99
- INVALID_STRING_FORMAT = 'invalid string format : <<A>>',
100
- INVALID_STRING_PATTERN = 'invalid string pattern : <<A>>',
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 : <<A>>',
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 <<A>>',
123
- TYPE_MISMATCH_ONE_OF = 'the value should be one of <<A>>',
122
+ TYPE_MISMATCH = 'the value should be a <<1>>',
123
+ TYPE_MISMATCH_ONE_OF = 'the value should be type of <<1>>',
124
124
 
125
- ONE_OF = 'the value should be one of <<A>>', // enum
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 <<A>>', // format
129
- FORMAT_ONE_OF = 'the value should be form of one of <<A>>',
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
- GREATER_THAN_OR_EQUAL = 'the value should be greater or equal than <<A>>', // min
132
- GREATER_THAN = 'the value should be greater than <<A>>', // min
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 <<A>>', // max
135
- SMALLER_THAN = 'the value should be smaller than <<A>>', // max
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 <<A>>', // length
138
- MIN_LENGTH = 'the value should be longer than <<A>>', // minLength
139
- MAX_LENGTH = 'the value should be shorter than <<A>>', // maxLength
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 <<A>>', // pattern
142
- PATTERN_ONE_OF = 'the value should be one of pattern of <<A>>', // pattern
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
- NO_PROPERTY = 'the value should have property',
143
+ PROPERTY = 'the value should have property',
145
144
 
146
- AFTER_OR_SAME_DATE = 'the value should be after or same date than <<A>>', // date
147
- AFTER_DATE = 'the value should be after date than <<A>>', // date
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 <<A>>', // date
150
- BEFORE_DATE = 'the value should be before date than <<A>>', // date
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 <<A>>',
155
- ITEMS_SCHEMES = 'the array should have items matched with schemes of <<A>>'
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
+ }