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.
Files changed (75) hide show
  1. package/.eslintrc.json +88 -0
  2. package/.mocharc.json +8 -0
  3. package/CHANGELOG.md +70 -29
  4. package/README-KR.md +6 -2
  5. package/README.md +6 -2
  6. package/build/{constants.js → cjs/constants.js} +117 -118
  7. package/build/cjs/constants.js.map +1 -0
  8. package/build/cjs/ejv.js +1263 -0
  9. package/build/cjs/ejv.js.map +1 -0
  10. package/build/{public_api.js → cjs/index.js} +14 -14
  11. package/build/cjs/index.js.map +1 -0
  12. package/build/cjs/interfaces.js +29 -0
  13. package/build/cjs/interfaces.js.map +1 -0
  14. package/build/cjs/package.json +1 -0
  15. package/build/{tester.js → cjs/tester.js} +273 -268
  16. package/build/cjs/tester.js.map +1 -0
  17. package/build/cjs/util.js +103 -0
  18. package/build/cjs/util.js.map +1 -0
  19. package/build/constants.d.ts +101 -104
  20. package/build/ejv.d.ts +2 -2
  21. package/build/esm/constants.js +115 -0
  22. package/build/esm/constants.js.map +1 -0
  23. package/build/esm/ejv.js +1261 -0
  24. package/build/esm/ejv.js.map +1 -0
  25. package/build/esm/index.js +4 -0
  26. package/build/esm/index.js.map +1 -0
  27. package/build/esm/interfaces.js +33 -0
  28. package/build/esm/interfaces.js.map +1 -0
  29. package/build/esm/package.json +1 -0
  30. package/build/esm/tester.js +240 -0
  31. package/build/esm/tester.js.map +1 -0
  32. package/build/esm/util.js +96 -0
  33. package/build/esm/util.js.map +1 -0
  34. package/build/index.d.ts +3 -0
  35. package/build/interfaces.d.ts +78 -38
  36. package/build/scripts/add-js-extensions.js +46 -0
  37. package/build/scripts/add-js-extensions.js.map +1 -0
  38. package/build/tester.d.ts +33 -34
  39. package/build/util.d.ts +7 -1
  40. package/package.json +48 -37
  41. package/scripts/add-js-extensions.ts +59 -0
  42. package/spec/ArrayScheme.ts +1021 -0
  43. package/spec/CommonScheme.ts +251 -0
  44. package/spec/DateScheme.ts +472 -0
  45. package/spec/NumberScheme.ts +1032 -0
  46. package/spec/ObjectScheme.ts +499 -0
  47. package/spec/RegExpScheme.ts +112 -0
  48. package/spec/StringScheme.ts +1239 -0
  49. package/spec/common-test-util.ts +63 -0
  50. package/spec/ejv.spec.ts +133 -4558
  51. package/spec/testers.spec.ts +17 -16
  52. package/src/constants.ts +41 -42
  53. package/src/ejv.ts +1141 -564
  54. package/src/index.ts +14 -0
  55. package/src/interfaces.ts +127 -41
  56. package/src/tester.ts +75 -69
  57. package/src/util.ts +106 -41
  58. package/tsconfig.cjs.json +8 -0
  59. package/tsconfig.esm.json +7 -0
  60. package/tsconfig.json +21 -18
  61. package/tsconfig.scripts.json +14 -0
  62. package/tsconfig.types.json +9 -0
  63. package/build/constants.js.map +0 -1
  64. package/build/ejv.js +0 -685
  65. package/build/ejv.js.map +0 -1
  66. package/build/interfaces.js +0 -15
  67. package/build/interfaces.js.map +0 -1
  68. package/build/public_api.d.ts +0 -3
  69. package/build/public_api.js.map +0 -1
  70. package/build/tester.js.map +0 -1
  71. package/build/util.js +0 -66
  72. package/build/util.js.map +0 -1
  73. package/spec/common-test-runner.ts +0 -17
  74. package/src/public_api.ts +0 -3
  75. 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,gBAAI,EAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC/C,MAAM,WAAW,GAAa,CAAC,MAAM,IAAA,kBAAO,EAAC,WAAW,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;S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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
- export declare const typeTester: (value: any, type: DataType) => boolean;
3
- export declare const definedTester: (value: any) => value is boolean;
4
- export declare const enumTester: <T>(value: T, arr: T[]) => boolean;
5
- export declare const lengthTester: (value: string | any[], length: number) => boolean;
6
- export declare const minLengthTester: (value: string | any[], minLength: number) => boolean;
7
- export declare const maxLengthTester: (value: string | any[], maxLength: number) => boolean;
8
- export declare const booleanTester: (value: any) => boolean;
9
- export declare const numberTester: (value: any) => value is number;
10
- export declare const integerTester: (value: number) => boolean;
11
- export declare const indexTester: (value: number) => value is number;
12
- export declare const minNumberTester: (value: number, min: number) => boolean;
13
- export declare const exclusiveMinNumberTester: (value: number, min: number) => boolean;
14
- export declare const maxNumberTester: (value: number, max: number) => boolean;
15
- export declare const exclusiveMaxNumberTester: (value: number, max: number) => boolean;
16
- export declare const stringTester: (value: any) => value is string;
17
- export declare const stringRegExpTester: (value: string, regExp: string | RegExp) => boolean;
18
- export declare const emailTester: (value: string) => boolean;
19
- export declare const dateFormatTester: (value: string) => boolean;
20
- export declare const timeFormatTester: (value: string) => boolean;
21
- export declare const dateTimeFormatTester: (value: string) => boolean;
22
- export declare const objectTester: (value: any) => value is {
23
- [key: string]: any;
24
- };
25
- export declare const hasPropertyTester: (value: object) => boolean;
26
- export declare const dateTester: (value: any) => value is Date;
27
- export declare const minDateTester: (value: Date, min: Date) => boolean;
28
- export declare const exclusiveMinDateTester: (value: Date, min: Date) => boolean;
29
- export declare const maxDateTester: (value: Date, max: Date) => boolean;
30
- export declare const exclusiveMaxDateTester: (value: Date, max: Date) => boolean;
31
- export declare const arrayTester: (value: any) => value is any[];
32
- export declare const arrayTypeOfTester: (array: any[], type: DataType) => boolean;
33
- export declare const uniqueItemsTester: (array: any[]) => boolean;
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
- export declare const clone: (obj: any) => any;
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
- "name": "ejv",
3
- "version": "1.1.10",
4
- "description": "Easy JSON Validator",
5
- "main": "build/public_api.js",
6
- "types": "build/public_api.d.ts",
7
- "scripts": {
8
- "clean": "rimraf ./build",
9
- "prebuild": "yarn clean",
10
- "build": "tsc",
11
- "prebuild:test": "yarn clean",
12
- "build:test": "tsc -p tsconfig.spec.json",
13
- "pretest": "yarn build:test",
14
- "test": "mocha ./build/**/*.spec.js"
15
- },
16
- "repository": {
17
- "type": "git",
18
- "url": "git+https://github.com/han41858/ejv.git"
19
- },
20
- "keywords": [
21
- "json",
22
- "validator",
23
- "validation"
24
- ],
25
- "author": "Janghyun Han <han41858@gmail.com>",
26
- "license": "MIT",
27
- "bugs": {
28
- "url": "https://github.com/han41858/ejv/issues"
29
- },
30
- "homepage": "https://github.com/han41858/ejv#readme",
31
- "devDependencies": {
32
- "@types/chai": "^4.2.14",
33
- "@types/mocha": "^8.2.0",
34
- "chai": "^4.2.0",
35
- "mocha": "^8.2.1",
36
- "rimraf": "^3.0.2",
37
- "typescript": "^4.1.3"
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
+ })();