ejv 2.0.5 → 2.1.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 (49) hide show
  1. package/.mocharc.json +1 -1
  2. package/CHANGELOG.md +26 -0
  3. package/README-KR.md +166 -165
  4. package/README.md +182 -178
  5. package/build/cjs/constants.js +112 -107
  6. package/build/cjs/constants.js.map +1 -1
  7. package/build/cjs/ejv.js +245 -177
  8. package/build/cjs/ejv.js.map +1 -1
  9. package/build/cjs/index.js +6 -6
  10. package/build/cjs/index.js.map +1 -1
  11. package/build/cjs/interfaces.js.map +1 -1
  12. package/build/cjs/tester.js +12 -8
  13. package/build/cjs/tester.js.map +1 -1
  14. package/build/cjs/util.js.map +1 -1
  15. package/build/constants.d.ts +10 -5
  16. package/build/esm/constants.js +111 -106
  17. package/build/esm/constants.js.map +1 -1
  18. package/build/esm/ejv.js +247 -179
  19. package/build/esm/ejv.js.map +1 -1
  20. package/build/esm/index.js +1 -1
  21. package/build/esm/index.js.map +1 -1
  22. package/build/esm/interfaces.js.map +1 -1
  23. package/build/esm/tester.js +11 -8
  24. package/build/esm/tester.js.map +1 -1
  25. package/build/esm/util.js.map +1 -1
  26. package/build/index.d.ts +1 -1
  27. package/build/interfaces.d.ts +10 -9
  28. package/build/tester.d.ts +4 -3
  29. package/build/util.d.ts +2 -2
  30. package/eslint.config.mjs +59 -0
  31. package/package.json +17 -13
  32. package/spec/ArrayScheme.ts +46 -46
  33. package/spec/CommonScheme.ts +15 -15
  34. package/spec/DateScheme.ts +22 -22
  35. package/spec/NumberScheme.ts +229 -121
  36. package/spec/ObjectScheme.ts +22 -22
  37. package/spec/RegExpScheme.ts +5 -5
  38. package/spec/StringScheme.ts +223 -126
  39. package/spec/common-test-util.ts +2 -2
  40. package/spec/ejv.spec.ts +20 -20
  41. package/spec/testers.spec.ts +5 -5
  42. package/src/constants.ts +12 -5
  43. package/src/ejv.ts +291 -202
  44. package/src/index.ts +1 -1
  45. package/src/interfaces.ts +11 -12
  46. package/src/tester.ts +14 -10
  47. package/src/util.ts +2 -2
  48. package/tsconfig.json +2 -1
  49. package/.eslintrc.json +0 -88
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { ejv } from './ejv';
2
- export { DataType, NumberFormat, StringFormat, ErrorMsg, ErrorType } from './constants';
2
+ export { DATA_TYPE, NUMBER_FORMAT, STRING_FORMAT, ERROR_MESSAGE, ERROR_TYPE } from './constants';
3
3
  export {
4
4
  BooleanScheme,
5
5
  NumberScheme,
package/src/interfaces.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { DataType, ErrorType, NumberFormat, StringFormat } from './constants';
1
+ import { DATA_TYPE, ERROR_TYPE, NUMBER_FORMAT, STRING_FORMAT } from './constants';
2
2
 
3
- export type AllDataType = string | string[] | DataType | DataType[];
3
+ export type AllDataType = string | string[] | DATA_TYPE | DATA_TYPE[];
4
4
 
5
5
 
6
6
  interface CommonScheme {
@@ -29,14 +29,16 @@ export interface MinMaxScheme<T> extends CommonScheme, MinMax<T> {
29
29
 
30
30
  export interface NumberScheme extends MinMaxScheme<number> {
31
31
  enum?: number[];
32
+ notEnum?: number[];
32
33
 
33
- format?: string | string[] | NumberFormat | NumberFormat[];
34
+ format?: string | string[] | NUMBER_FORMAT | NUMBER_FORMAT[];
34
35
  }
35
36
 
36
37
  export interface StringScheme extends CommonScheme {
37
38
  enum?: string[];
39
+ notEnum?: string[];
38
40
 
39
- format?: string | string[] | StringFormat | StringFormat[];
41
+ format?: string | string[] | STRING_FORMAT | STRING_FORMAT[];
40
42
  pattern?: string | string[] | RegExp | RegExp[];
41
43
 
42
44
  length?: number;
@@ -49,11 +51,8 @@ export interface ObjectScheme extends CommonScheme {
49
51
  allowNoProperty?: boolean; // true
50
52
  }
51
53
 
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
- }
54
+ // min, max string for date string
55
+ export type DateScheme = MinMaxScheme<string | Date>
57
56
 
58
57
  // no additional rule
59
58
  export type RegExpScheme = CommonScheme;
@@ -79,7 +78,7 @@ export type Scheme =
79
78
 
80
79
  export interface Options {
81
80
  customErrorMsg?: {
82
- [key in ErrorType]?: string;
81
+ [key in ERROR_TYPE]?: string;
83
82
  };
84
83
  }
85
84
 
@@ -88,7 +87,7 @@ export interface InternalOptions extends Options {
88
87
  }
89
88
 
90
89
  export class EjvError {
91
- public type: ErrorType;
90
+ public type: ERROR_TYPE;
92
91
  public message: string;
93
92
 
94
93
  public data: unknown;
@@ -101,7 +100,7 @@ export class EjvError {
101
100
  public isDataError: boolean;
102
101
 
103
102
  constructor (param: {
104
- type: ErrorType,
103
+ type: ERROR_TYPE,
105
104
  message: string,
106
105
 
107
106
  data: unknown,
package/src/tester.ts CHANGED
@@ -1,35 +1,35 @@
1
- import { DataType } from './constants';
1
+ import { DATA_TYPE } from './constants';
2
2
  import { AnyObject } from './interfaces';
3
3
 
4
- export const typeTester = (value: unknown, type: DataType): boolean => {
4
+ export const typeTester = (value: unknown, type: DATA_TYPE): boolean => {
5
5
  let valid: boolean;
6
6
 
7
7
  switch (type) {
8
- case DataType.BOOLEAN:
8
+ case DATA_TYPE.BOOLEAN:
9
9
  valid = booleanTester(value);
10
10
  break;
11
11
 
12
- case DataType.NUMBER:
12
+ case DATA_TYPE.NUMBER:
13
13
  valid = numberTester(value);
14
14
  break;
15
15
 
16
- case DataType.STRING:
16
+ case DATA_TYPE.STRING:
17
17
  valid = stringTester(value);
18
18
  break;
19
19
 
20
- case DataType.OBJECT:
20
+ case DATA_TYPE.OBJECT:
21
21
  valid = objectTester(value);
22
22
  break;
23
23
 
24
- case DataType.DATE:
24
+ case DATA_TYPE.DATE:
25
25
  valid = dateTester(value);
26
26
  break;
27
27
 
28
- case DataType.REGEXP:
28
+ case DATA_TYPE.REGEXP:
29
29
  valid = regExpTester(value);
30
30
  break;
31
31
 
32
- case DataType.ARRAY:
32
+ case DATA_TYPE.ARRAY:
33
33
  valid = arrayTester(value);
34
34
  break;
35
35
  }
@@ -45,6 +45,10 @@ export const enumTester = <T> (value: T, arr: T[]): boolean => {
45
45
  return arr.includes(value);
46
46
  };
47
47
 
48
+ export const notEnumTester = <T> (value: T, arr: T[]): boolean => {
49
+ return !enumTester(value, arr);
50
+ };
51
+
48
52
  export const lengthTester = (value: string | unknown[], length: number): boolean => {
49
53
  return value.length === length;
50
54
  };
@@ -291,7 +295,7 @@ export const arrayTester = (value: unknown): value is unknown[] => {
291
295
  return Array.isArray(value);
292
296
  };
293
297
 
294
- export const arrayTypeOfTester = (array: unknown[], type: DataType): boolean => {
298
+ export const arrayTypeOfTester = (array: unknown[], type: DATA_TYPE): boolean => {
295
299
  return array.every((item: unknown): boolean => {
296
300
  return typeTester(item, type);
297
301
  });
package/src/util.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AnyObject } from './interfaces';
2
- import { ErrorMsg } from './constants';
2
+ import { ERROR_MESSAGE } from './constants';
3
3
 
4
4
 
5
5
  enum CloneDataType {
@@ -104,7 +104,7 @@ export const sift = <T> (arr: T[]): T[] => {
104
104
  };
105
105
 
106
106
 
107
- export const createErrorMsg = (errorMsg: ErrorMsg, param?: {
107
+ export const createErrorMsg = (errorMsg: ERROR_MESSAGE, param?: {
108
108
  placeholders?: (string | number)[]
109
109
  }): string => {
110
110
  let result: string = errorMsg;
package/tsconfig.json CHANGED
@@ -5,7 +5,8 @@
5
5
  "strict": true,
6
6
  "forceConsistentCasingInFileNames": true,
7
7
  "noImplicitReturns": true,
8
- "noFallthroughCasesInSwitch": true
8
+ "noFallthroughCasesInSwitch": true,
9
+ "moduleResolution": "Node"
9
10
  },
10
11
  "include": [
11
12
  "src"
package/.eslintrc.json DELETED
@@ -1,88 +0,0 @@
1
- {
2
- "env": {
3
- "browser": true,
4
- "es2021": true,
5
- "node": true
6
- },
7
- "extends": [
8
- "eslint:recommended",
9
- "plugin:@typescript-eslint/recommended"
10
- ],
11
- "parser": "@typescript-eslint/parser",
12
- "parserOptions": {
13
- "ecmaVersion": 2020,
14
- "sourceType": "module"
15
- },
16
- "plugins": [
17
- "@typescript-eslint"
18
- ],
19
- "rules": {
20
- "indent": "off",
21
- "@typescript-eslint/indent": [
22
- "warn",
23
- "tab",
24
- {
25
- "ignoreComments": true,
26
- "SwitchCase": 1,
27
- "ignoredNodes": [
28
- "CallExpression *",
29
- "ExpressionStatement *"
30
- ]
31
- }
32
- ],
33
- "linebreak-style": [
34
- "warn",
35
- "windows"
36
- ],
37
- "arrow-parens": "warn",
38
- "quotes": [
39
- "warn",
40
- "single"
41
- ],
42
- "semi": [
43
- "warn",
44
- "always"
45
- ],
46
- "no-shadow": "off",
47
- "@typescript-eslint/no-shadow": "warn",
48
- "no-trailing-spaces": "warn",
49
- "no-var": "warn",
50
- "prefer-const": "warn",
51
- "space-before-function-paren": "warn",
52
- "brace-style": [
53
- "warn",
54
- "stroustrup"
55
- ],
56
- "key-spacing": [
57
- "warn",
58
- {
59
- "beforeColon": false,
60
- "afterColon": true
61
- }
62
- ],
63
- "@typescript-eslint/type-annotation-spacing": [
64
- "warn",
65
- {
66
- "before": false,
67
- "after": true,
68
- "overrides": {
69
- "arrow": {
70
- "before": true,
71
- "after": true
72
- }
73
- }
74
- }
75
- ],
76
- "@typescript-eslint/explicit-function-return-type": "warn",
77
- "@typescript-eslint/no-inferrable-types": "off",
78
- "@typescript-eslint/no-non-null-assertion": "warn",
79
- "@typescript-eslint/no-empty-function": "warn",
80
- "@typescript-eslint/no-unused-vars": "warn",
81
- "@typescript-eslint/explicit-module-boundary-types": "warn",
82
- "operator-linebreak": [
83
- "warn",
84
- "before"
85
- ],
86
- "no-param-reassign": "warn"
87
- }
88
- }