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.
- package/.mocharc.json +8 -8
- package/CHANGELOG.md +134 -127
- package/README-KR.md +597 -597
- package/README.md +603 -603
- package/build/cjs/constants.js +124 -0
- package/build/cjs/constants.js.map +1 -0
- package/build/cjs/ejv.js +1341 -0
- package/build/cjs/ejv.js.map +1 -0
- package/build/cjs/index.js +14 -0
- package/build/cjs/index.js.map +1 -0
- package/build/cjs/interfaces.js +29 -0
- package/build/cjs/interfaces.js.map +1 -0
- package/build/cjs/package.json +1 -0
- package/build/cjs/tester.js +288 -0
- package/build/cjs/tester.js.map +1 -0
- package/build/cjs/util.js +103 -0
- package/build/cjs/util.js.map +1 -0
- package/build/constants.d.ts +107 -0
- package/build/ejv.d.ts +2 -0
- package/build/esm/constants.js +121 -0
- package/build/esm/constants.js.map +1 -0
- package/build/esm/ejv.js +1339 -0
- package/build/esm/ejv.js.map +1 -0
- package/build/esm/index.js +4 -0
- package/build/esm/index.js.map +1 -0
- package/build/esm/interfaces.js +33 -0
- package/build/esm/interfaces.js.map +1 -0
- package/build/esm/package.json +1 -0
- package/build/esm/tester.js +252 -0
- package/build/esm/tester.js.map +1 -0
- package/build/esm/util.js +96 -0
- package/build/esm/util.js.map +1 -0
- package/build/index.d.ts +3 -0
- package/build/interfaces.d.ts +77 -0
- package/build/scripts/add-js-extensions.js +46 -0
- package/build/scripts/add-js-extensions.js.map +1 -0
- package/build/tester.d.ts +35 -0
- package/build/util.d.ts +7 -0
- package/eslint.config.mjs +66 -59
- package/package.json +54 -55
- package/scripts/add-js-extensions.ts +59 -59
- package/spec/ArrayScheme.ts +1021 -1021
- package/spec/CommonScheme.ts +251 -251
- package/spec/DateScheme.ts +472 -472
- package/spec/NumberScheme.ts +1160 -1160
- package/spec/ObjectScheme.ts +499 -499
- package/spec/RegExpScheme.ts +112 -112
- package/spec/StringScheme.ts +1407 -1336
- package/spec/common-test-util.ts +63 -63
- package/spec/ejv.spec.ts +235 -235
- package/spec/testers.spec.ts +833 -833
- package/src/constants.ts +164 -162
- package/src/ejv.ts +1751 -1746
- package/src/index.ts +14 -14
- package/src/interfaces.ts +144 -144
- package/src/tester.ts +323 -312
- package/src/util.ts +124 -124
- package/tsconfig.cjs.json +8 -8
- package/tsconfig.esm.json +7 -7
- package/tsconfig.json +19 -18
- package/tsconfig.scripts.json +14 -14
- 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;
|
package/build/util.d.ts
ADDED
|
@@ -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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
'@typescript-eslint/no-
|
|
48
|
-
'no-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
'
|
|
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.
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
"@
|
|
40
|
-
"@types/
|
|
41
|
-
"@types/
|
|
42
|
-
"@
|
|
43
|
-
"@typescript-eslint/
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"eslint": "^
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"typescript": "^
|
|
53
|
-
|
|
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
|
+
})();
|