ejv 1.1.10 → 2.0.0
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/.eslintrc.json +88 -0
- package/.mocharc.json +8 -0
- package/CHANGELOG.md +70 -29
- package/README-KR.md +6 -2
- package/README.md +6 -2
- package/build/{constants.js → cjs/constants.js} +117 -118
- package/build/cjs/constants.js.map +1 -0
- package/build/cjs/ejv.js +1263 -0
- package/build/cjs/ejv.js.map +1 -0
- package/build/{public_api.js → cjs/index.js} +14 -14
- 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/{tester.js → cjs/tester.js} +273 -268
- 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 +101 -104
- package/build/ejv.d.ts +2 -2
- package/build/esm/constants.js +115 -0
- package/build/esm/constants.js.map +1 -0
- package/build/esm/ejv.js +1261 -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 +240 -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 +78 -38
- package/build/scripts/add-js-extensions.js +46 -0
- package/build/scripts/add-js-extensions.js.map +1 -0
- package/build/tester.d.ts +33 -34
- package/build/util.d.ts +7 -1
- package/package.json +48 -37
- package/scripts/add-js-extensions.ts +59 -0
- package/spec/ArrayScheme.ts +1021 -0
- package/spec/CommonScheme.ts +251 -0
- package/spec/DateScheme.ts +472 -0
- package/spec/NumberScheme.ts +1032 -0
- package/spec/ObjectScheme.ts +499 -0
- package/spec/RegExpScheme.ts +112 -0
- package/spec/StringScheme.ts +1239 -0
- package/spec/common-test-util.ts +63 -0
- package/spec/ejv.spec.ts +133 -4558
- package/spec/testers.spec.ts +17 -16
- package/src/constants.ts +41 -42
- package/src/ejv.ts +1141 -564
- package/src/index.ts +14 -0
- package/src/interfaces.ts +127 -41
- package/src/tester.ts +75 -69
- package/src/util.ts +106 -41
- package/tsconfig.cjs.json +8 -0
- package/tsconfig.esm.json +7 -0
- package/tsconfig.json +21 -18
- package/tsconfig.scripts.json +14 -0
- package/tsconfig.types.json +9 -0
- package/build/constants.js.map +0 -1
- package/build/ejv.js +0 -685
- package/build/ejv.js.map +0 -1
- package/build/interfaces.js +0 -15
- package/build/interfaces.js.map +0 -1
- package/build/public_api.d.ts +0 -3
- package/build/public_api.js.map +0 -1
- package/build/tester.js.map +0 -1
- package/build/util.js +0 -66
- package/build/util.js.map +0 -1
- package/spec/common-test-runner.ts +0 -17
- package/src/public_api.ts +0 -3
- package/tsconfig.spec.json +0 -19
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const node_path_1 = require("node:path");
|
|
4
|
+
const promises_1 = require("node:fs/promises");
|
|
5
|
+
// patch targets
|
|
6
|
+
// cjs: const interfaces_1 = require("./interfaces.js");
|
|
7
|
+
// esm: import { EjvError } from './interfaces.js';
|
|
8
|
+
console.log('* add-js-extensions');
|
|
9
|
+
(async () => {
|
|
10
|
+
// get all .js file in build folder
|
|
11
|
+
const buildFolder = (0, node_path_1.join)('.', 'build');
|
|
12
|
+
const folderNames = (await (0, promises_1.readdir)(buildFolder, { withFileTypes: true }))
|
|
13
|
+
.filter((one) => one.isDirectory())
|
|
14
|
+
.map((one) => one.name);
|
|
15
|
+
const importStateRegExp = /['"]\.\/[a-z]+['"]/g;
|
|
16
|
+
let modifiedFileCount = 0;
|
|
17
|
+
let modifiedStrCount = 0;
|
|
18
|
+
for await (const folder of folderNames) {
|
|
19
|
+
const jsFilePaths = (await (0, promises_1.readdir)((0, node_path_1.join)(buildFolder, folder), { withFileTypes: true }))
|
|
20
|
+
.filter((one) => one.isFile() && one.name.endsWith('.js'))
|
|
21
|
+
.map((one) => (0, node_path_1.join)(buildFolder, folder, one.name));
|
|
22
|
+
for await (const jsFilePath of jsFilePaths) {
|
|
23
|
+
let fileContents = await (0, promises_1.readFile)(jsFilePath, {
|
|
24
|
+
encoding: 'utf-8'
|
|
25
|
+
});
|
|
26
|
+
const matchResults = [...fileContents.matchAll(importStateRegExp)];
|
|
27
|
+
if (matchResults.length > 0) {
|
|
28
|
+
for (let i = 0; i < matchResults.length; i++) {
|
|
29
|
+
const oneResult = matchResults[i];
|
|
30
|
+
const beforeStr = oneResult[0];
|
|
31
|
+
const afterStr = beforeStr.endsWith('"')
|
|
32
|
+
? beforeStr.replace(/"$/, '.js"')
|
|
33
|
+
: beforeStr.replace(/'$/, '.js\'');
|
|
34
|
+
fileContents = fileContents.replace(beforeStr, afterStr);
|
|
35
|
+
++modifiedStrCount;
|
|
36
|
+
}
|
|
37
|
+
await (0, promises_1.writeFile)(jsFilePath, fileContents, {
|
|
38
|
+
encoding: 'utf-8'
|
|
39
|
+
});
|
|
40
|
+
++modifiedFileCount;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
console.log(`${modifiedStrCount} import statements in ${modifiedFileCount} files patched`);
|
|
45
|
+
})();
|
|
46
|
+
//# sourceMappingURL=add-js-extensions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-js-extensions.js","sourceRoot":"","sources":["../../scripts/add-js-extensions.ts"],"names":[],"mappings":";;AAAA,yCAAiC;AAEjC,+CAAgE;AAEhE,gBAAgB;AAChB,qDAAqD;AACrD,gDAAgD;AAEhD,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;AAEnC,CAAC,KAAK,IAAmB,EAAE;IAC1B,mCAAmC;IACnC,MAAM,WAAW,GAAW,IAAA,g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AI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;oBAC9C,MAAM,SAAS,GAAqB,YAAY,CAAC,CAAC,CAAC,CAAC;oBAEpD,MAAM,SAAS,GAAW,SAAS,CAAC,CAAC,CAAC,CAAC;oBACvC,MAAM,QAAQ,GAAW,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC;wBAC/C,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;wBACjC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;oBAEpC,YAAY,GAAG,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;oBAEzD,EAAE,gBAAgB,CAAC;gBACpB,CAAC;gBAED,MAAM,IAAA,oBAAS,EAAC,UAAU,EAAE,YAAY,EAAE;oBACzC,QAAQ,EAAE,OAAO;iBACjB,CAAC,CAAC;gBAEH,EAAE,iBAAiB,CAAC;YACrB,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,GAAI,gBAAiB,yBAA0B,iBAAkB,gBAAgB,CAAC,CAAC;AAChG,CAAC,CAAC,EAAE,CAAC"}
|
package/build/tester.d.ts
CHANGED
|
@@ -1,34 +1,33 @@
|
|
|
1
|
-
import { DataType } from './constants';
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
14
|
-
export declare const
|
|
15
|
-
export declare const
|
|
16
|
-
export declare const
|
|
17
|
-
export declare const
|
|
18
|
-
export declare const
|
|
19
|
-
export declare const
|
|
20
|
-
export declare const
|
|
21
|
-
export declare const
|
|
22
|
-
export declare const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
export declare const
|
|
26
|
-
export declare const
|
|
27
|
-
export declare const
|
|
28
|
-
export declare const
|
|
29
|
-
export declare const
|
|
30
|
-
export declare const
|
|
31
|
-
export declare const
|
|
32
|
-
export declare const
|
|
33
|
-
export declare const
|
|
34
|
-
export declare const regExpTester: (value: any) => value is RegExp;
|
|
1
|
+
import { DataType } from './constants';
|
|
2
|
+
import { AnyObject } from './interfaces';
|
|
3
|
+
export declare const typeTester: (value: unknown, type: DataType) => 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 lengthTester: (value: string | unknown[], length: number) => boolean;
|
|
7
|
+
export declare const minLengthTester: (value: string | unknown[], minLength: number) => boolean;
|
|
8
|
+
export declare const maxLengthTester: (value: string | unknown[], maxLength: number) => boolean;
|
|
9
|
+
export declare const booleanTester: (value: unknown) => value is boolean;
|
|
10
|
+
export declare const numberTester: (value: unknown) => value is number;
|
|
11
|
+
export declare const integerTester: (value: number) => boolean;
|
|
12
|
+
export declare const indexTester: (value: number) => value is number;
|
|
13
|
+
export declare const minNumberTester: (value: number, min: number) => boolean;
|
|
14
|
+
export declare const exclusiveMinNumberTester: (value: number, min: number) => boolean;
|
|
15
|
+
export declare const maxNumberTester: (value: number, max: number) => boolean;
|
|
16
|
+
export declare const exclusiveMaxNumberTester: (value: number, max: number) => boolean;
|
|
17
|
+
export declare const stringTester: (value: unknown) => value is string;
|
|
18
|
+
export declare const stringRegExpTester: (value: string, regExp: string | RegExp) => boolean;
|
|
19
|
+
export declare const emailTester: (value: string) => boolean;
|
|
20
|
+
export declare const dateFormatTester: (value: string) => boolean;
|
|
21
|
+
export declare const timeFormatTester: (value: string) => boolean;
|
|
22
|
+
export declare const dateTimeFormatTester: (value: string) => boolean;
|
|
23
|
+
export declare const objectTester: (value: unknown) => boolean;
|
|
24
|
+
export declare const hasPropertyTester: (value: AnyObject) => boolean;
|
|
25
|
+
export declare const dateTester: (value: unknown) => value is Date;
|
|
26
|
+
export declare const minDateTester: (value: Date, min: Date) => boolean;
|
|
27
|
+
export declare const exclusiveMinDateTester: (value: Date, min: Date) => boolean;
|
|
28
|
+
export declare const maxDateTester: (value: Date, max: Date) => boolean;
|
|
29
|
+
export declare const exclusiveMaxDateTester: (value: Date, max: Date) => boolean;
|
|
30
|
+
export declare const arrayTester: (value: unknown) => value is unknown[];
|
|
31
|
+
export declare const arrayTypeOfTester: (array: unknown[], type: DataType) => boolean;
|
|
32
|
+
export declare const uniqueItemsTester: (array: unknown[]) => boolean;
|
|
33
|
+
export declare const regExpTester: (value: unknown) => value is RegExp;
|
package/build/util.d.ts
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { ErrorMsg } 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: ErrorMsg, param?: {
|
|
6
|
+
placeholders?: (string | number)[];
|
|
7
|
+
}) => string;
|
package/package.json
CHANGED
|
@@ -1,39 +1,50 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
2
|
+
"name": "ejv",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Easy JSON Validator",
|
|
5
|
+
"exports": {
|
|
6
|
+
"require": "./build/cjs/index.js",
|
|
7
|
+
"import": "./build/esm/index.js"
|
|
8
|
+
},
|
|
9
|
+
"types": "build/public_api.d.ts",
|
|
10
|
+
"main": "build/cjs/public_api.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 src/**/*.ts spec/**/*.ts"
|
|
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
|
+
"@types/chai": "^4.3.11",
|
|
39
|
+
"@types/mocha": "^10.0.6",
|
|
40
|
+
"@types/node": "20.8.0",
|
|
41
|
+
"@typescript-eslint/eslint-plugin": "^6.14.0",
|
|
42
|
+
"@typescript-eslint/parser": "^6.14.0",
|
|
43
|
+
"chai": "^4.3.10",
|
|
44
|
+
"eslint": "^8.55.0",
|
|
45
|
+
"mocha": "^10.2.0",
|
|
46
|
+
"rimraf": "^5.0.5",
|
|
47
|
+
"ts-node": "^10.9.2",
|
|
48
|
+
"typescript": "^5.3.3"
|
|
49
|
+
}
|
|
39
50
|
}
|
|
@@ -0,0 +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
|
+
})();
|