ejv 1.1.11 → 2.0.1

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} +45 -46
  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} +88 -83
  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 +37 -40
  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 +51 -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 +145 -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,145 @@
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
+ enum?: number[];
32
+
33
+ format?: string | string[] | NumberFormat | NumberFormat[];
34
+ }
35
+
36
+ export interface StringScheme extends CommonScheme {
37
+ enum?: string[];
38
+
39
+ format?: string | string[] | StringFormat | StringFormat[];
40
+ pattern?: string | string[] | RegExp | RegExp[];
41
+
42
+ length?: number;
43
+ minLength?: number;
44
+ maxLength?: number;
45
+ }
46
+
47
+ export interface ObjectScheme extends CommonScheme {
48
+ properties?: Scheme[];
49
+ allowNoProperty?: boolean; // true
50
+ }
51
+
52
+
53
+ /* eslint-disable @typescript-eslint/no-empty-interface */
54
+ export interface DateScheme extends MinMaxScheme<string | Date> {
55
+ // min, max string for date string
56
+ }
57
+
58
+ // no additional rule
59
+ export type RegExpScheme = CommonScheme;
60
+
61
+ export interface ArrayScheme extends CommonScheme {
62
+ unique?: boolean; // false
63
+ items?: AllDataType | Scheme | Scheme[];
64
+
65
+ length?: number;
66
+ minLength?: number;
67
+ maxLength?: number;
68
+ }
69
+
70
+ export type Scheme =
71
+ BooleanScheme
72
+ | NumberScheme
73
+ | StringScheme
74
+ | ObjectScheme
75
+ | DateScheme
76
+ | RegExpScheme
77
+ | ArrayScheme;
78
+
79
+
80
+ export interface Options {
81
+ customErrorMsg?: {
82
+ [key in ErrorType]?: string;
83
+ };
84
+ }
85
+
86
+ export interface InternalOptions extends Options {
87
+ path: string[];
88
+ }
89
+
90
+ export class EjvError {
91
+ public type: ErrorType;
92
+ public message: string;
93
+
94
+ public data: unknown;
95
+ public path: string | undefined;
96
+
97
+ public errorScheme: Scheme | undefined;
98
+ public errorData: unknown | undefined;
99
+
100
+ public isSchemeError: boolean;
101
+ public isDataError: boolean;
102
+
103
+ constructor (param: {
104
+ type: ErrorType,
105
+ message: string,
106
+
107
+ data: unknown,
108
+ path?: string[],
109
+
110
+ errorScheme?: Scheme,
111
+ errorData?: unknown,
112
+
113
+ isSchemeError?: boolean
114
+ }) {
115
+ this.type = param.type;
116
+ this.message = param.message;
117
+
118
+ this.data = param.data;
119
+
120
+ if ('path' in param && param.path !== undefined) {
121
+ this.path = param.path.join('/');
122
+ }
123
+
124
+ if ('errorScheme' in param) {
125
+ this.errorScheme = param.errorScheme;
126
+ }
127
+
128
+ if ('errorData' in param) {
129
+ this.errorData = param.errorData;
130
+ }
131
+
132
+ if (param.isSchemeError) {
133
+ this.isSchemeError = true;
134
+ this.isDataError = false;
135
+ }
136
+ else {
137
+ this.isSchemeError = false;
138
+ this.isDataError = true;
139
+ }
140
+ }
141
+ }
142
+
143
+ export interface AnyObject {
144
+ [key: string]: unknown;
145
+ }