ejv 1.1.11 → 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 +109 -68
  4. package/LICENSE +21 -21
  5. package/README-KR.md +596 -592
  6. package/README.md +599 -595
  7. package/build/{constants.js → cjs/constants.js} +44 -45
  8. package/build/cjs/constants.js.map +1 -0
  9. package/build/cjs/ejv.js +1263 -0
  10. package/build/cjs/ejv.js.map +1 -0
  11. package/build/{public_api.js → cjs/index.js} +4 -4
  12. package/build/cjs/index.js.map +1 -0
  13. package/build/cjs/interfaces.js +29 -0
  14. package/build/cjs/interfaces.js.map +1 -0
  15. package/build/cjs/package.json +1 -0
  16. package/build/{tester.js → cjs/tester.js} +87 -82
  17. package/build/cjs/tester.js.map +1 -0
  18. package/build/cjs/util.js +103 -0
  19. package/build/cjs/util.js.map +1 -0
  20. package/build/constants.d.ts +36 -39
  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 +53 -13
  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 +16 -17
  39. package/build/util.d.ts +7 -1
  40. package/package.json +50 -39
  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 +209 -4634
  51. package/spec/testers.spec.ts +833 -832
  52. package/src/constants.ts +155 -156
  53. package/src/ejv.ts +1648 -1071
  54. package/src/index.ts +14 -0
  55. package/src/interfaces.ts +149 -63
  56. package/src/tester.ts +308 -302
  57. package/src/util.ts +124 -59
  58. package/tsconfig.cjs.json +8 -0
  59. package/tsconfig.esm.json +7 -0
  60. package/tsconfig.json +22 -19
  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 -687
  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 -68
  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
package/src/index.ts ADDED
@@ -0,0 +1,14 @@
1
+ export { ejv } from './ejv';
2
+ export { DataType, NumberFormat, StringFormat, ErrorMsg, ErrorType } from './constants';
3
+ export {
4
+ BooleanScheme,
5
+ NumberScheme,
6
+ StringScheme,
7
+ ObjectScheme,
8
+ ArrayScheme,
9
+ RegExpScheme,
10
+ DateScheme,
11
+ EjvError,
12
+ Scheme,
13
+ Options
14
+ } from './interfaces';
package/src/interfaces.ts CHANGED
@@ -1,63 +1,149 @@
1
- import { DataType, ErrorType, NumberFormat, StringFormat } from './constants';
2
-
3
- // use common Scheme for multiple types
4
- export interface Scheme {
5
- // common
6
- key? : string; // can be omitted in array items
7
- type : string | string[] | DataType | DataType[];
8
- optional? : boolean; // false
9
- nullable? : boolean; // false
10
- // reverse? not?
11
-
12
- // common - number & Date (date string, Date)
13
- min? : number | string | Date;
14
- exclusiveMin? : boolean; // false
15
-
16
- max? : number | string | Date;
17
- exclusiveMax? : boolean; // false
18
-
19
- // common - number & string
20
- enum? : number[] | string[];
21
- enumReverse? : number[] | string[];
22
-
23
- // common - number & string
24
- format? : string | string[] | NumberFormat | NumberFormat[] | StringFormat | StringFormat[];
25
-
26
- // common - string & array
27
- length? : number;
28
- minLength? : number;
29
- maxLength? : number;
30
-
31
- // string
32
- pattern? : string | string[] | RegExp | RegExp[];
33
-
34
- // object
35
- properties? : Scheme[];
36
- allowNoProperty? : boolean; // true
37
-
38
- // array
39
- unique? : boolean; // false
40
- items? : string | string[] | DataType | DataType[] | Scheme | Scheme[];
41
- }
42
-
43
- export interface Options {
44
- customErrorMsg? : {
45
- [key in ErrorType]? : string;
46
- };
47
- }
48
-
49
- export interface InternalOptions extends Options {
50
- path : string[];
51
- }
52
-
53
- export class EjvError {
54
- public path : string;
55
-
56
- constructor (public type : ErrorType,
57
- public message : string,
58
- path : string[],
59
- public data : any,
60
- public errorData : any) {
61
- this.path = path.join('/');
62
- }
63
- }
1
+ import { DataType, ErrorType, NumberFormat, StringFormat } from './constants';
2
+
3
+ export type AllDataType = string | string[] | DataType | DataType[];
4
+
5
+
6
+ interface CommonScheme {
7
+ parent?: Scheme;
8
+
9
+ key?: string; // can be omitted in array items
10
+ type?: AllDataType; // optional for not
11
+
12
+ optional?: boolean; // false
13
+ nullable?: boolean; // false
14
+ }
15
+
16
+ // no additional rule
17
+ export type BooleanScheme = CommonScheme;
18
+
19
+ export interface MinMax<T> {
20
+ min?: T;
21
+ exclusiveMin?: boolean; // default false
22
+
23
+ max?: T;
24
+ exclusiveMax?: boolean; // default false
25
+ }
26
+
27
+ export interface MinMaxScheme<T> extends CommonScheme, MinMax<T> {
28
+ }
29
+
30
+ export interface NumberScheme extends MinMaxScheme<number> {
31
+ value?: number; // TODO: need to add
32
+
33
+ enum?: number[];
34
+
35
+ format?: string | string[] | NumberFormat | NumberFormat[];
36
+ }
37
+
38
+ export interface StringScheme extends CommonScheme {
39
+ value?: string; // TODO: need to add
40
+
41
+ enum?: string[];
42
+
43
+ format?: string | string[] | StringFormat | StringFormat[];
44
+ pattern?: string | string[] | RegExp | RegExp[];
45
+
46
+ length?: number;
47
+ minLength?: number;
48
+ maxLength?: number;
49
+ }
50
+
51
+ export interface ObjectScheme extends CommonScheme {
52
+ properties?: Scheme[];
53
+ allowNoProperty?: boolean; // true
54
+ }
55
+
56
+
57
+ /* eslint-disable @typescript-eslint/no-empty-interface */
58
+ export interface DateScheme extends MinMaxScheme<string | Date> {
59
+ // min, max string for date string
60
+ }
61
+
62
+ // no additional rule
63
+ export type RegExpScheme = CommonScheme;
64
+
65
+ export interface ArrayScheme extends CommonScheme {
66
+ unique?: boolean; // false
67
+ items?: AllDataType | Scheme | Scheme[];
68
+
69
+ length?: number;
70
+ minLength?: number;
71
+ maxLength?: number;
72
+ }
73
+
74
+ export type Scheme =
75
+ BooleanScheme
76
+ | NumberScheme
77
+ | StringScheme
78
+ | ObjectScheme
79
+ | DateScheme
80
+ | RegExpScheme
81
+ | ArrayScheme;
82
+
83
+
84
+ export interface Options {
85
+ customErrorMsg?: {
86
+ [key in ErrorType]?: string;
87
+ };
88
+ }
89
+
90
+ export interface InternalOptions extends Options {
91
+ path: string[];
92
+ }
93
+
94
+ export class EjvError {
95
+ public type: ErrorType;
96
+ public message: string;
97
+
98
+ public data: unknown;
99
+ public path: string | undefined;
100
+
101
+ public errorScheme: Scheme | undefined;
102
+ public errorData: unknown | undefined;
103
+
104
+ public isSchemeError: boolean;
105
+ public isDataError: boolean;
106
+
107
+ constructor (param: {
108
+ type: ErrorType,
109
+ message: string,
110
+
111
+ data: unknown,
112
+ path?: string[],
113
+
114
+ errorScheme?: Scheme,
115
+ errorData?: unknown,
116
+
117
+ isSchemeError?: boolean
118
+ }) {
119
+ this.type = param.type;
120
+ this.message = param.message;
121
+
122
+ this.data = param.data;
123
+
124
+ if ('path' in param && param.path !== undefined) {
125
+ this.path = param.path.join('/');
126
+ }
127
+
128
+ if ('errorScheme' in param) {
129
+ this.errorScheme = param.errorScheme;
130
+ }
131
+
132
+ if ('errorData' in param) {
133
+ this.errorData = param.errorData;
134
+ }
135
+
136
+ if (param.isSchemeError) {
137
+ this.isSchemeError = true;
138
+ this.isDataError = false;
139
+ }
140
+ else {
141
+ this.isSchemeError = false;
142
+ this.isDataError = true;
143
+ }
144
+ }
145
+ }
146
+
147
+ export interface AnyObject {
148
+ [key: string]: unknown;
149
+ }