ejv 2.1.0 → 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 (62) hide show
  1. package/.mocharc.json +8 -8
  2. package/CHANGELOG.md +134 -127
  3. package/README-KR.md +597 -597
  4. package/README.md +603 -603
  5. package/build/cjs/constants.js +124 -0
  6. package/build/cjs/constants.js.map +1 -0
  7. package/build/cjs/ejv.js +1341 -0
  8. package/build/cjs/ejv.js.map +1 -0
  9. package/build/cjs/index.js +14 -0
  10. package/build/cjs/index.js.map +1 -0
  11. package/build/cjs/interfaces.js +29 -0
  12. package/build/cjs/interfaces.js.map +1 -0
  13. package/build/cjs/package.json +1 -0
  14. package/build/cjs/tester.js +288 -0
  15. package/build/cjs/tester.js.map +1 -0
  16. package/build/cjs/util.js +103 -0
  17. package/build/cjs/util.js.map +1 -0
  18. package/build/constants.d.ts +107 -0
  19. package/build/ejv.d.ts +2 -0
  20. package/build/esm/constants.js +121 -0
  21. package/build/esm/constants.js.map +1 -0
  22. package/build/esm/ejv.js +1339 -0
  23. package/build/esm/ejv.js.map +1 -0
  24. package/build/esm/index.js +4 -0
  25. package/build/esm/index.js.map +1 -0
  26. package/build/esm/interfaces.js +33 -0
  27. package/build/esm/interfaces.js.map +1 -0
  28. package/build/esm/package.json +1 -0
  29. package/build/esm/tester.js +252 -0
  30. package/build/esm/tester.js.map +1 -0
  31. package/build/esm/util.js +96 -0
  32. package/build/esm/util.js.map +1 -0
  33. package/build/index.d.ts +3 -0
  34. package/build/interfaces.d.ts +77 -0
  35. package/build/scripts/add-js-extensions.js +46 -0
  36. package/build/scripts/add-js-extensions.js.map +1 -0
  37. package/build/tester.d.ts +35 -0
  38. package/build/util.d.ts +7 -0
  39. package/eslint.config.mjs +66 -59
  40. package/package.json +54 -55
  41. package/scripts/add-js-extensions.ts +59 -59
  42. package/spec/ArrayScheme.ts +1021 -1021
  43. package/spec/CommonScheme.ts +251 -251
  44. package/spec/DateScheme.ts +472 -472
  45. package/spec/NumberScheme.ts +1160 -1160
  46. package/spec/ObjectScheme.ts +499 -499
  47. package/spec/RegExpScheme.ts +112 -112
  48. package/spec/StringScheme.ts +1407 -1336
  49. package/spec/common-test-util.ts +63 -63
  50. package/spec/ejv.spec.ts +235 -235
  51. package/spec/testers.spec.ts +833 -833
  52. package/src/constants.ts +164 -162
  53. package/src/ejv.ts +1751 -1746
  54. package/src/index.ts +14 -14
  55. package/src/interfaces.ts +144 -144
  56. package/src/tester.ts +323 -312
  57. package/src/util.ts +124 -124
  58. package/tsconfig.cjs.json +8 -8
  59. package/tsconfig.esm.json +7 -7
  60. package/tsconfig.json +19 -18
  61. package/tsconfig.scripts.json +14 -14
  62. package/tsconfig.types.json +9 -9
@@ -0,0 +1,35 @@
1
+ import { DATA_TYPE } from './constants';
2
+ import { AnyObject } from './interfaces';
3
+ export declare const typeTester: (value: unknown, type: DATA_TYPE) => boolean;
4
+ export declare const definedTester: (value: unknown) => value is boolean;
5
+ export declare const enumTester: <T>(value: T, arr: T[]) => boolean;
6
+ export declare const notEnumTester: <T>(value: T, arr: T[]) => boolean;
7
+ export declare const lengthTester: (value: string | unknown[], length: number) => boolean;
8
+ export declare const minLengthTester: (value: string | unknown[], minLength: number) => boolean;
9
+ export declare const maxLengthTester: (value: string | unknown[], maxLength: number) => boolean;
10
+ export declare const booleanTester: (value: unknown) => value is boolean;
11
+ export declare const numberTester: (value: unknown) => value is number;
12
+ export declare const integerTester: (value: number) => boolean;
13
+ export declare const indexTester: (value: number) => value is number;
14
+ export declare const minNumberTester: (value: number, min: number) => boolean;
15
+ export declare const exclusiveMinNumberTester: (value: number, min: number) => boolean;
16
+ export declare const maxNumberTester: (value: number, max: number) => boolean;
17
+ export declare const exclusiveMaxNumberTester: (value: number, max: number) => boolean;
18
+ export declare const stringTester: (value: unknown) => value is string;
19
+ export declare const stringRegExpTester: (value: string, regExp: string | RegExp) => boolean;
20
+ export declare const emailTester: (value: string) => boolean;
21
+ export declare const jsonStrTester: (value: string) => boolean;
22
+ export declare const dateFormatTester: (value: string) => boolean;
23
+ export declare const timeFormatTester: (value: string) => boolean;
24
+ export declare const dateTimeFormatTester: (value: string) => boolean;
25
+ export declare const objectTester: (value: unknown) => boolean;
26
+ export declare const hasPropertyTester: (value: AnyObject) => boolean;
27
+ export declare const dateTester: (value: unknown) => value is Date;
28
+ export declare const minDateTester: (value: Date, min: Date) => boolean;
29
+ export declare const exclusiveMinDateTester: (value: Date, min: Date) => boolean;
30
+ export declare const maxDateTester: (value: Date, max: Date) => boolean;
31
+ export declare const exclusiveMaxDateTester: (value: Date, max: Date) => boolean;
32
+ export declare const arrayTester: (value: unknown) => value is unknown[];
33
+ export declare const arrayTypeOfTester: (array: unknown[], type: DATA_TYPE) => boolean;
34
+ export declare const uniqueItemsTester: (array: unknown[]) => boolean;
35
+ export declare const regExpTester: (value: unknown) => value is RegExp;
@@ -0,0 +1,7 @@
1
+ import { ERROR_MESSAGE } from './constants';
2
+ export declare const isArray: <T>(value: unknown) => value is T[];
3
+ export declare const clone: <T>(obj: T, sanitize?: boolean) => T;
4
+ export declare const sift: <T>(arr: T[]) => T[];
5
+ export declare const createErrorMsg: (errorMsg: ERROR_MESSAGE, param?: {
6
+ placeholders?: (string | number)[];
7
+ }) => string;
package/eslint.config.mjs CHANGED
@@ -1,59 +1,66 @@
1
- import globals from 'globals';
2
- import pluginJs from '@eslint/js';
3
- import tseslint from 'typescript-eslint';
4
- import pluginChaiFriendly from 'eslint-plugin-chai-friendly';
5
-
6
-
7
- export default [
8
- {
9
- files: [
10
- '**/*.{ts,js,mjs}'
11
- ]
12
- },
13
- {
14
- languageOptions: {
15
- globals: {
16
- ...globals.browser,
17
- ...globals.node
18
- }
19
- }
20
- },
21
- pluginJs.configs.recommended,
22
- ...tseslint.configs.recommended,
23
-
24
- {
25
- plugins: {
26
- 'chai-friendly': pluginChaiFriendly
27
- },
28
- rules: {
29
- 'indent': ['warn', 'tab',
30
- {
31
- 'ignoreComments': true,
32
- 'SwitchCase': 1,
33
- 'ignoredNodes': [
34
- 'CallExpression *',
35
- 'ExpressionStatement *'
36
- ]
37
- }
38
- ],
39
- // chai expect
40
- '@typescript-eslint/no-unused-expressions': 'off', // disable original rule
41
- 'chai-friendly/no-unused-expressions': 'error',
42
-
43
- 'linebreak-style': ['warn', 'windows'],
44
- 'arrow-parens': 'warn',
45
- 'quotes': ['warn', 'single'],
46
- 'semi': ['warn', 'always'],
47
- '@typescript-eslint/no-shadow': 'error',
48
- 'no-trailing-spaces': 'warn',
49
- 'key-spacing': [
50
- 'warn',
51
- {
52
- 'beforeColon': false,
53
- 'afterColon': true
54
- }
55
- ],
56
- '@typescript-eslint/explicit-function-return-type': 'warn'
57
- }
58
- }
59
- ];
1
+ import globals from 'globals';
2
+ import pluginJs from '@eslint/js';
3
+ import tseslint from 'typescript-eslint';
4
+ import pluginChaiFriendly from 'eslint-plugin-chai-friendly';
5
+
6
+
7
+ export default [
8
+ {
9
+ files: [
10
+ '**/*.{ts,js,mjs}'
11
+ ]
12
+ },
13
+ {
14
+ ignores: [
15
+ 'build/**/*',
16
+ 'node_modules/**/*'
17
+ ]
18
+ },
19
+ {
20
+ languageOptions: {
21
+ globals: {
22
+ ...globals.browser,
23
+ ...globals.node
24
+ }
25
+ }
26
+ },
27
+
28
+ pluginJs.configs.recommended,
29
+ ...tseslint.configs.recommended,
30
+
31
+ {
32
+ plugins: {
33
+ 'chai-friendly': pluginChaiFriendly
34
+ },
35
+ rules: {
36
+ 'indent': ['warn', 'tab',
37
+ {
38
+ 'ignoreComments': true,
39
+ 'SwitchCase': 1,
40
+ 'ignoredNodes': [
41
+ 'CallExpression *',
42
+ 'ExpressionStatement *'
43
+ ]
44
+ }
45
+ ],
46
+ // chai expect
47
+ '@typescript-eslint/no-unused-expressions': 'off', // disable original rule
48
+ 'chai-friendly/no-unused-expressions': 'error',
49
+
50
+ 'linebreak-style': ['warn', 'unix'],
51
+ 'arrow-parens': 'warn',
52
+ 'quotes': ['warn', 'single'],
53
+ 'semi': ['warn', 'always'],
54
+ '@typescript-eslint/no-shadow': 'error',
55
+ 'no-trailing-spaces': 'warn',
56
+ 'key-spacing': [
57
+ 'warn',
58
+ {
59
+ 'beforeColon': false,
60
+ 'afterColon': true
61
+ }
62
+ ],
63
+ '@typescript-eslint/explicit-function-return-type': 'warn'
64
+ }
65
+ }
66
+ ];
package/package.json CHANGED
@@ -1,55 +1,54 @@
1
- {
2
- "name": "ejv",
3
- "version": "2.1.0",
4
- "description": "Easy JSON Validator",
5
- "exports": {
6
- "require": "./build/cjs/index.js",
7
- "import": "./build/esm/index.js"
8
- },
9
- "types": "build/index.d.ts",
10
- "main": "build/cjs/index.js",
11
- "scripts": {
12
- "clean": "rimraf ./build",
13
- "prebuild": "yarn clean",
14
- "build:types": "tsc -p tsconfig.types.json",
15
- "build:cjs": "tsc -p tsconfig.cjs.json&&echo { \"type\": \"commonjs\" } > build/cjs/package.json",
16
- "build:esm": "tsc -p tsconfig.esm.json&&echo { \"type\": \"module\" } > build/esm/package.json",
17
- "build": "yarn build:types&&yarn build:cjs&&yarn build:esm",
18
- "postbuild": "tsc -p tsconfig.scripts.json&&node build/scripts/add-js-extensions",
19
- "test": "mocha",
20
- "lint": "eslint",
21
- "publish": "yarn build&&npm publish"
22
- },
23
- "repository": {
24
- "type": "git",
25
- "url": "git+https://github.com/han41858/ejv.git"
26
- },
27
- "keywords": [
28
- "json",
29
- "validator",
30
- "validation"
31
- ],
32
- "author": "Janghyun Han <han41858@gmail.com>",
33
- "license": "MIT",
34
- "bugs": {
35
- "url": "https://github.com/han41858/ejv/issues"
36
- },
37
- "homepage": "https://github.com/han41858/ejv#readme",
38
- "devDependencies": {
39
- "@eslint/js": "^9.12.0",
40
- "@types/chai": "^5.0.0",
41
- "@types/mocha": "^10.0.8",
42
- "@types/node": "20.16.10",
43
- "@typescript-eslint/eslint-plugin": "^8.8.0",
44
- "@typescript-eslint/parser": "^8.8.0",
45
- "chai": "^5.1.1",
46
- "eslint": "^9.12.0",
47
- "eslint-plugin-chai-friendly": "^1.0.1",
48
- "globals": "^15.10.0",
49
- "mocha": "^10.7.3",
50
- "rimraf": "^6.0.1",
51
- "tsx": "^4.19.1",
52
- "typescript": "^5.6.2",
53
- "typescript-eslint": "^8.8.0"
54
- }
55
- }
1
+ {
2
+ "name": "ejv",
3
+ "version": "2.1.2",
4
+ "description": "Easy JSON Validator",
5
+ "exports": {
6
+ "require": "./build/cjs/index.js",
7
+ "import": "./build/esm/index.js"
8
+ },
9
+ "types": "build/index.d.ts",
10
+ "main": "build/cjs/index.js",
11
+ "scripts": {
12
+ "clean": "rimraf ./build",
13
+ "prebuild": "yarn clean",
14
+ "build:types": "tsc -p tsconfig.types.json",
15
+ "build:cjs": "tsc -p tsconfig.cjs.json&&echo { \"type\": \"commonjs\" } > build/cjs/package.json",
16
+ "build:esm": "tsc -p tsconfig.esm.json&&echo { \"type\": \"module\" } > build/esm/package.json",
17
+ "build": "yarn build:types&&yarn build:cjs&&yarn build:esm",
18
+ "postbuild": "tsc -p tsconfig.scripts.json&&node build/scripts/add-js-extensions",
19
+ "test": "mocha",
20
+ "lint": "eslint"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/han41858/ejv.git"
25
+ },
26
+ "keywords": [
27
+ "json",
28
+ "validator",
29
+ "validation"
30
+ ],
31
+ "author": "Janghyun Han <han41858@gmail.com>",
32
+ "license": "MIT",
33
+ "bugs": {
34
+ "url": "https://github.com/han41858/ejv/issues"
35
+ },
36
+ "homepage": "https://github.com/han41858/ejv#readme",
37
+ "devDependencies": {
38
+ "@eslint/js": "^9.12.0",
39
+ "@types/chai": "^5.0.0",
40
+ "@types/mocha": "^10.0.8",
41
+ "@types/node": "20.16.10",
42
+ "@typescript-eslint/eslint-plugin": "^8.8.0",
43
+ "@typescript-eslint/parser": "^8.8.0",
44
+ "chai": "^5.1.1",
45
+ "eslint": "^9.12.0",
46
+ "eslint-plugin-chai-friendly": "^1.0.1",
47
+ "globals": "^15.10.0",
48
+ "mocha": "^10.7.3",
49
+ "rimraf": "^6.0.1",
50
+ "tsx": "^4.19.1",
51
+ "typescript": "^5.6.2",
52
+ "typescript-eslint": "^8.8.0"
53
+ }
54
+ }
@@ -1,59 +1,59 @@
1
- import { join } from 'node:path';
2
- import { Dirent } from 'node:fs';
3
- import { readdir, readFile, writeFile } from 'node:fs/promises';
4
-
5
- // patch targets
6
- // cjs: const interfaces_1 = require("./interfaces");
7
- // esm: import { EjvError } from './interfaces';
8
-
9
- console.log('* add-js-extensions');
10
-
11
- (async (): Promise<void> => {
12
- // get all .js file in build folder
13
- const buildFolder: string = join('.', 'build');
14
- const folderNames: string[] = (await readdir(buildFolder, { withFileTypes: true }))
15
- .filter((one: Dirent): boolean => one.isDirectory())
16
- .map((one: Dirent): string => one.name);
17
-
18
- const importStateRegExp = /['"]\.\/[a-z]+['"]/g;
19
-
20
- let modifiedFileCount: number = 0;
21
- let modifiedStrCount: number = 0;
22
-
23
- for await (const folder of folderNames) {
24
- const jsFilePaths: string[] = (await readdir(join(buildFolder, folder), { withFileTypes: true }))
25
- .filter((one: Dirent): boolean => one.isFile() && one.name.endsWith('.js'))
26
- .map((one: Dirent): string => join(buildFolder, folder, one.name));
27
-
28
- for await(const jsFilePath of jsFilePaths) {
29
- let fileContents: string = await readFile(jsFilePath, {
30
- encoding: 'utf-8'
31
- });
32
-
33
- const matchResults: RegExpMatchArray[] = [...fileContents.matchAll(importStateRegExp)];
34
-
35
- if (matchResults.length > 0) {
36
- for (let i = 0; i < matchResults.length; i++) {
37
- const oneResult: RegExpMatchArray = matchResults[i];
38
-
39
- const beforeStr: string = oneResult[0];
40
- const afterStr: string = beforeStr.endsWith('"')
41
- ? beforeStr.replace(/"$/, '.js"')
42
- : beforeStr.replace(/'$/, '.js\'');
43
-
44
- fileContents = fileContents.replace(beforeStr, afterStr);
45
-
46
- ++modifiedStrCount;
47
- }
48
-
49
- await writeFile(jsFilePath, fileContents, {
50
- encoding: 'utf-8'
51
- });
52
-
53
- ++modifiedFileCount;
54
- }
55
- }
56
- }
57
-
58
- console.log(`${ modifiedStrCount } import statements in ${ modifiedFileCount } files patched`);
59
- })();
1
+ import { join } from 'node:path';
2
+ import { Dirent } from 'node:fs';
3
+ import { readdir, readFile, writeFile } from 'node:fs/promises';
4
+
5
+ // patch targets
6
+ // cjs: const interfaces_1 = require("./interfaces");
7
+ // esm: import { EjvError } from './interfaces';
8
+
9
+ console.log('* add-js-extensions');
10
+
11
+ (async (): Promise<void> => {
12
+ // get all .js file in build folder
13
+ const buildFolder: string = join('.', 'build');
14
+ const folderNames: string[] = (await readdir(buildFolder, { withFileTypes: true }))
15
+ .filter((one: Dirent): boolean => one.isDirectory())
16
+ .map((one: Dirent): string => one.name);
17
+
18
+ const importStateRegExp = /['"]\.\/[a-z]+['"]/g;
19
+
20
+ let modifiedFileCount: number = 0;
21
+ let modifiedStrCount: number = 0;
22
+
23
+ for await (const folder of folderNames) {
24
+ const jsFilePaths: string[] = (await readdir(join(buildFolder, folder), { withFileTypes: true }))
25
+ .filter((one: Dirent): boolean => one.isFile() && one.name.endsWith('.js'))
26
+ .map((one: Dirent): string => join(buildFolder, folder, one.name));
27
+
28
+ for await(const jsFilePath of jsFilePaths) {
29
+ let fileContents: string = await readFile(jsFilePath, {
30
+ encoding: 'utf-8'
31
+ });
32
+
33
+ const matchResults: RegExpMatchArray[] = [...fileContents.matchAll(importStateRegExp)];
34
+
35
+ if (matchResults.length > 0) {
36
+ for (let i = 0; i < matchResults.length; i++) {
37
+ const oneResult: RegExpMatchArray = matchResults[i];
38
+
39
+ const beforeStr: string = oneResult[0];
40
+ const afterStr: string = beforeStr.endsWith('"')
41
+ ? beforeStr.replace(/"$/, '.js"')
42
+ : beforeStr.replace(/'$/, '.js\'');
43
+
44
+ fileContents = fileContents.replace(beforeStr, afterStr);
45
+
46
+ ++modifiedStrCount;
47
+ }
48
+
49
+ await writeFile(jsFilePath, fileContents, {
50
+ encoding: 'utf-8'
51
+ });
52
+
53
+ ++modifiedFileCount;
54
+ }
55
+ }
56
+ }
57
+
58
+ console.log(`${ modifiedStrCount } import statements in ${ modifiedFileCount } files patched`);
59
+ })();