ejv 2.1.1 → 2.1.2

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 (42) hide show
  1. package/.mocharc.json +8 -8
  2. package/CHANGELOG.md +134 -135
  3. package/README-KR.md +597 -597
  4. package/README.md +603 -603
  5. package/build/cjs/constants.js +1 -0
  6. package/build/cjs/constants.js.map +1 -1
  7. package/build/cjs/ejv.js +3 -0
  8. package/build/cjs/ejv.js.map +1 -1
  9. package/build/cjs/tester.js +11 -1
  10. package/build/cjs/tester.js.map +1 -1
  11. package/build/constants.d.ts +1 -0
  12. package/build/esm/constants.js +1 -0
  13. package/build/esm/constants.js.map +1 -1
  14. package/build/esm/ejv.js +4 -1
  15. package/build/esm/ejv.js.map +1 -1
  16. package/build/esm/tester.js +9 -0
  17. package/build/esm/tester.js.map +1 -1
  18. package/build/tester.d.ts +1 -0
  19. package/eslint.config.mjs +66 -59
  20. package/package.json +54 -54
  21. package/scripts/add-js-extensions.ts +59 -59
  22. package/spec/ArrayScheme.ts +1021 -1021
  23. package/spec/CommonScheme.ts +251 -251
  24. package/spec/DateScheme.ts +472 -472
  25. package/spec/NumberScheme.ts +1160 -1160
  26. package/spec/ObjectScheme.ts +499 -499
  27. package/spec/RegExpScheme.ts +112 -112
  28. package/spec/StringScheme.ts +1407 -1336
  29. package/spec/common-test-util.ts +63 -63
  30. package/spec/ejv.spec.ts +235 -235
  31. package/spec/testers.spec.ts +833 -833
  32. package/src/constants.ts +164 -162
  33. package/src/ejv.ts +1751 -1746
  34. package/src/index.ts +14 -14
  35. package/src/interfaces.ts +144 -144
  36. package/src/tester.ts +323 -312
  37. package/src/util.ts +124 -124
  38. package/tsconfig.cjs.json +8 -8
  39. package/tsconfig.esm.json +7 -7
  40. package/tsconfig.json +19 -19
  41. package/tsconfig.scripts.json +14 -14
  42. package/tsconfig.types.json +9 -9
package/src/util.ts CHANGED
@@ -1,124 +1,124 @@
1
- import { AnyObject } from './interfaces';
2
- import { ERROR_MESSAGE } from './constants';
3
-
4
-
5
- enum CloneDataType {
6
- Boolean = 'boolean',
7
- Number = 'number',
8
- Function = 'function',
9
- String = 'string',
10
- Buffer = 'buffer',
11
- Object = 'object',
12
- Array = 'array',
13
- Date = 'date',
14
- RegExp = 'regexp'
15
- }
16
-
17
- export const isArray = <T> (value: unknown): value is T[] => {
18
- return value !== undefined
19
- && value !== null
20
- && Array.isArray(value);
21
- };
22
-
23
-
24
- // sanitize removes undefined & null fields from object. default false
25
- export const clone = <T> (obj: T, sanitize?: boolean): T => {
26
- let result !: T;
27
-
28
- if (obj) {
29
- let type: CloneDataType = typeof obj as CloneDataType;
30
-
31
- if (type === CloneDataType.Object) {
32
- const objAsObject: AnyObject = obj as unknown as AnyObject;
33
-
34
- if (isArray(objAsObject)) {
35
- type = CloneDataType.Array;
36
- }
37
- else if (objAsObject instanceof Date) {
38
- type = CloneDataType.Date;
39
- }
40
- else if (objAsObject instanceof RegExp) {
41
- type = CloneDataType.RegExp;
42
- }
43
- else if (objAsObject.byteLength
44
- && typeof objAsObject.byteLength === 'function') {
45
- type = CloneDataType.Buffer;
46
- }
47
- }
48
-
49
- switch (type) {
50
- case CloneDataType.Date: {
51
- const objAsDate: Date = obj as unknown as Date;
52
- result = new Date(objAsDate) as unknown as T;
53
- break;
54
- }
55
-
56
- case CloneDataType.Array: {
57
- const objAsArray: unknown[] = obj as unknown as unknown[];
58
- result = objAsArray.map((one: unknown): unknown => {
59
- return clone(one);
60
- }) as unknown as T;
61
- break;
62
- }
63
-
64
- case CloneDataType.Object: {
65
- // sanitize default false
66
- result = {} as unknown as T;
67
-
68
- const entries: [string, unknown][] = Object.entries(obj)
69
- .filter(([, value]): boolean => {
70
- return sanitize
71
- ? value !== undefined && value !== null
72
- : true;
73
- });
74
-
75
-
76
- for (const [key, value] of entries) {
77
- // call recursively
78
- (result as unknown as AnyObject)[key] = clone(value, sanitize);
79
- }
80
- break;
81
- }
82
-
83
- default:
84
- // simple copy
85
- result = obj;
86
- }
87
- }
88
- else {
89
- result = obj; // do not copy null & undefined
90
- }
91
-
92
- return result;
93
- };
94
-
95
-
96
- export const sift = <T> (arr: T[]): T[] => {
97
- return arr.reduce((acc: T[], cur: T) => {
98
- if (cur !== null && cur !== undefined && !acc.includes(cur)) {
99
- acc.push(cur);
100
- }
101
-
102
- return acc;
103
- }, []);
104
- };
105
-
106
-
107
- export const createErrorMsg = (errorMsg: ERROR_MESSAGE, param?: {
108
- placeholders?: (string | number)[]
109
- }): string => {
110
- let result: string = errorMsg;
111
-
112
- if (param?.placeholders) {
113
- param.placeholders.forEach((strToReplace: string | number, i: number): void => {
114
- result = result.replace(
115
- `<<${ i + 1 }>>`,
116
- typeof strToReplace === 'string'
117
- ? strToReplace
118
- : '' + strToReplace
119
- );
120
- });
121
- }
122
-
123
- return result;
124
- };
1
+ import { AnyObject } from './interfaces';
2
+ import { ERROR_MESSAGE } from './constants';
3
+
4
+
5
+ enum CloneDataType {
6
+ Boolean = 'boolean',
7
+ Number = 'number',
8
+ Function = 'function',
9
+ String = 'string',
10
+ Buffer = 'buffer',
11
+ Object = 'object',
12
+ Array = 'array',
13
+ Date = 'date',
14
+ RegExp = 'regexp'
15
+ }
16
+
17
+ export const isArray = <T> (value: unknown): value is T[] => {
18
+ return value !== undefined
19
+ && value !== null
20
+ && Array.isArray(value);
21
+ };
22
+
23
+
24
+ // sanitize removes undefined & null fields from object. default false
25
+ export const clone = <T> (obj: T, sanitize?: boolean): T => {
26
+ let result !: T;
27
+
28
+ if (obj) {
29
+ let type: CloneDataType = typeof obj as CloneDataType;
30
+
31
+ if (type === CloneDataType.Object) {
32
+ const objAsObject: AnyObject = obj as unknown as AnyObject;
33
+
34
+ if (isArray(objAsObject)) {
35
+ type = CloneDataType.Array;
36
+ }
37
+ else if (objAsObject instanceof Date) {
38
+ type = CloneDataType.Date;
39
+ }
40
+ else if (objAsObject instanceof RegExp) {
41
+ type = CloneDataType.RegExp;
42
+ }
43
+ else if (objAsObject.byteLength
44
+ && typeof objAsObject.byteLength === 'function') {
45
+ type = CloneDataType.Buffer;
46
+ }
47
+ }
48
+
49
+ switch (type) {
50
+ case CloneDataType.Date: {
51
+ const objAsDate: Date = obj as unknown as Date;
52
+ result = new Date(objAsDate) as unknown as T;
53
+ break;
54
+ }
55
+
56
+ case CloneDataType.Array: {
57
+ const objAsArray: unknown[] = obj as unknown as unknown[];
58
+ result = objAsArray.map((one: unknown): unknown => {
59
+ return clone(one);
60
+ }) as unknown as T;
61
+ break;
62
+ }
63
+
64
+ case CloneDataType.Object: {
65
+ // sanitize default false
66
+ result = {} as unknown as T;
67
+
68
+ const entries: [string, unknown][] = Object.entries(obj)
69
+ .filter(([, value]): boolean => {
70
+ return sanitize
71
+ ? value !== undefined && value !== null
72
+ : true;
73
+ });
74
+
75
+
76
+ for (const [key, value] of entries) {
77
+ // call recursively
78
+ (result as unknown as AnyObject)[key] = clone(value, sanitize);
79
+ }
80
+ break;
81
+ }
82
+
83
+ default:
84
+ // simple copy
85
+ result = obj;
86
+ }
87
+ }
88
+ else {
89
+ result = obj; // do not copy null & undefined
90
+ }
91
+
92
+ return result;
93
+ };
94
+
95
+
96
+ export const sift = <T> (arr: T[]): T[] => {
97
+ return arr.reduce((acc: T[], cur: T) => {
98
+ if (cur !== null && cur !== undefined && !acc.includes(cur)) {
99
+ acc.push(cur);
100
+ }
101
+
102
+ return acc;
103
+ }, []);
104
+ };
105
+
106
+
107
+ export const createErrorMsg = (errorMsg: ERROR_MESSAGE, param?: {
108
+ placeholders?: (string | number)[]
109
+ }): string => {
110
+ let result: string = errorMsg;
111
+
112
+ if (param?.placeholders) {
113
+ param.placeholders.forEach((strToReplace: string | number, i: number): void => {
114
+ result = result.replace(
115
+ `<<${ i + 1 }>>`,
116
+ typeof strToReplace === 'string'
117
+ ? strToReplace
118
+ : '' + strToReplace
119
+ );
120
+ });
121
+ }
122
+
123
+ return result;
124
+ };
package/tsconfig.cjs.json CHANGED
@@ -1,8 +1,8 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "build/cjs",
5
- "module": "commonjs",
6
- "target": "ES6"
7
- }
8
- }
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "build/cjs",
5
+ "module": "commonjs",
6
+ "target": "ES6"
7
+ }
8
+ }
package/tsconfig.esm.json CHANGED
@@ -1,7 +1,7 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "build/esm",
5
- "module": "ES2022"
6
- }
7
- }
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "build/esm",
5
+ "module": "ES2022"
6
+ }
7
+ }
package/tsconfig.json CHANGED
@@ -1,19 +1,19 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "sourceMap": true,
5
- "strict": true,
6
- "forceConsistentCasingInFileNames": true,
7
- "noImplicitReturns": true,
8
- "noFallthroughCasesInSwitch": true,
9
- "moduleResolution": "Node"
10
- },
11
- "include": [
12
- "src"
13
- ],
14
- "exclude": [
15
- "node_modules",
16
- "spec",
17
- "scripts"
18
- ]
19
- }
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "sourceMap": true,
5
+ "strict": true,
6
+ "forceConsistentCasingInFileNames": true,
7
+ "noImplicitReturns": true,
8
+ "noFallthroughCasesInSwitch": true,
9
+ "moduleResolution": "Node"
10
+ },
11
+ "include": [
12
+ "src"
13
+ ],
14
+ "exclude": [
15
+ "node_modules",
16
+ "spec",
17
+ "scripts"
18
+ ]
19
+ }
@@ -1,14 +1,14 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "build/scripts",
5
- "module": "commonjs"
6
- },
7
- "include": [
8
- "scripts"
9
- ],
10
- "exclude": [
11
- "node_modules",
12
- "spec"
13
- ]
14
- }
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "build/scripts",
5
+ "module": "commonjs"
6
+ },
7
+ "include": [
8
+ "scripts"
9
+ ],
10
+ "exclude": [
11
+ "node_modules",
12
+ "spec"
13
+ ]
14
+ }
@@ -1,9 +1,9 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "emitDeclarationOnly": true,
5
- "outDir": "build",
6
- "declaration": true,
7
- "declarationDir": "build"
8
- }
9
- }
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "emitDeclarationOnly": true,
5
+ "outDir": "build",
6
+ "declaration": true,
7
+ "declarationDir": "build"
8
+ }
9
+ }