Skip to content

Commit d033c06

Browse files
author
ganmin
committed
use ts4.0, partial realize
1 parent bd65d55 commit d033c06

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+7517
-881
lines changed

.eslintrc.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
parserOptions: {
4+
ecmaVersion: 2020,
5+
sourceType: 'module',
6+
},
7+
env: {
8+
jest: true,
9+
browser: true,
10+
},
11+
extends: [
12+
'plugin:@typescript-eslint/recommended',
13+
'prettier/@typescript-eslint',
14+
'plugin:prettier/recommended',
15+
],
16+
rules: {
17+
'@typescript-eslint/no-unused-vars': [
18+
'error',
19+
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
20+
],
21+
'no-console': 'warn',
22+
},
23+
overrides: [
24+
{
25+
files: [
26+
'jest.config.js',
27+
'webpack.config.js',
28+
'.prettierrc.js',
29+
'.eslintrc.js',
30+
],
31+
env: {
32+
node: true,
33+
},
34+
extends: ['plugin:prettier/recommended'],
35+
rules: {
36+
'@typescript-eslint/no-var-requires': 'off',
37+
},
38+
},
39+
],
40+
};

.gitignore

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# node modules
2-
node_modules
2+
node_modules/
33
# vscode
44
.vscode/*
5-
# build
6-
/src/local
5+
6+
# build files
7+
/local
78
.DS_Store*
8-
yarn.lock
99
package-lock.json
10+
/coverage

.npmignore

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
# dir
22
/src/
3+
/local/
34
/__tests__/
45
/dist/
56
/node_modules/
7+
/coverage
8+
69
# files
7-
tslint.json
8-
yarn.lock
10+
browser.ts
11+
12+
# system temp file
913
.DS_Store
14+
15+
# vscode config
1016
.vscode
11-
.travis.yml
17+
18+
# package
19+
yarn.lock
1220
package-lock.json
21+
22+
# config files
23+
.travis.yml
1324
webpack.config.js
14-
jest.config.json
25+
jest.config.js
26+
.prettierrc.js
27+
.eslintrc.js

.prettierrc.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
semi: true,
3+
trailingComma: "all",
4+
singleQuote: true,
5+
tabWidth: 2
6+
};

.travis.yml

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
language: node_js
2-
node_js:
3-
- '7'
4-
- '8'
5-
- '9'
6-
sudo: false
2+
install:
3+
- yarn
4+
os:
5+
- "linux"
6+
node_js:
7+
- "12"
78
script:
89
- "npm test"
910
after_script:

coverage/.gitkeep

Whitespace-only changes.

jest.config.js

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
const { defaults: tsjPreset } = require('ts-jest/presets');
22
module.exports = {
33
testEnvironment: 'node',
4-
transform: Object.assign({},tsjPreset.transform),
4+
transform: Object.assign({}, tsjPreset.transform),
55
verbose: true,
6-
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
7-
testPathIgnorePatterns: ['<rootDir>/lib/','<rootDir>/dist/','<rootDir>/node_modules/','<rootDir>/src/'],
8-
coverageDirectory: '<rootDir>/',
9-
moduleFileExtensions: [
10-
"ts",
11-
"js",
6+
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
7+
testPathIgnorePatterns: [
8+
'<rootDir>/lib/',
9+
'<rootDir>/dist/',
10+
'<rootDir>/node_modules/',
11+
'<rootDir>/local/',
1212
],
13-
moduleNameMapper:{
14-
'^@/(.*)': '<rootDir>/src/$1'
15-
}
16-
};
13+
coverageDirectory: '<rootDir>/coverage',
14+
collectCoverage: true,
15+
collectCoverageFrom: ['src/**/*.{ts,js}', '!<rootDir>/node_modules/'],
16+
moduleFileExtensions: ['ts', 'js'],
17+
moduleNameMapper: {
18+
'^@/(.*)': '<rootDir>/src/$1',
19+
},
20+
rootDir: '.',
21+
};

lib/helpers/utils.d.ts

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import { Mocker } from '../such';
2-
import { NormalObject, ParamsPathItem } from '../types';
2+
import { TObject, ParamsPathItem } from '../types';
33
export declare const encodeRegexpChars: (chars: string) => string;
44
export declare const typeOf: (target: any) => string;
55
export declare const isFn: (target: any) => boolean;
6-
export declare const map: (target: string | any[] | NormalObject, fn: (item: any, index: string | number) => void) => NormalObject;
6+
export declare const map: (
7+
target: string | any[] | TObject,
8+
fn: (item: any, index: string | number) => void,
9+
) => TObject;
710
export declare const makeRandom: (min: number, max: number) => number;
8-
export declare const makeStrRangeList: (first?: string, last?: string, ...args: string[]) => string[];
11+
export declare const makeStrRangeList: (
12+
first?: string,
13+
last?: string,
14+
...args: string[]
15+
) => string[];
916
export declare const isOptional: () => boolean;
1017
export declare const capitalize: (target: string) => string;
1118
export declare const decodeTrans: (target: string) => string;
@@ -15,7 +22,13 @@ export declare const range: (start: number, end: number, step?: number) => any;
1522
export declare const deepCopy: (target: any, ...args: any[]) => any;
1623
export declare const isNoEmptyObject: (target: any) => boolean;
1724
export declare const isPromise: (target: any) => boolean;
18-
export declare const shiftObject: (obj: NormalObject, keys: string[]) => NormalObject;
25+
export declare const shiftObject: (obj: TObject, keys: string[]) => TObject;
1926
export declare const withPromise: (res: any[]) => any[];
20-
export declare const isRelativePath: (first: (string | number)[], second: (string | number)[]) => boolean;
21-
export declare const getRefMocker: (item: ParamsPathItem, mocker: Mocker) => Mocker;
27+
export declare const isRelativePath: (
28+
first: (string | number)[],
29+
second: (string | number)[],
30+
) => boolean;
31+
export declare const getRefMocker: (
32+
item: ParamsPathItem,
33+
mocker: Mocker,
34+
) => Mocker;

lib/mockit/namespace.d.ts

+28-28
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
import { MockitConfig, NormalObject, SuchOptions } from '../types';
1+
import { MockitConfig, TObject, SuchOptions } from '../types';
22
export declare type Result<T> = T | never;
33
export declare type ModifierFn<T> = (res: T) => T | string | never;
4-
export declare type RuleFn = (cur: NormalObject) => void | NormalObject;
4+
export declare type RuleFn = (cur: TObject) => void | TObject;
55
export default abstract class Mockit<T> {
6-
protected readonly constructorName: string;
7-
protected configOptions: MockitConfig;
8-
protected params: NormalObject;
9-
protected origParams: NormalObject;
10-
protected generateFn: undefined | ((options: SuchOptions) => Result<T>);
11-
protected isValidOk: boolean;
12-
protected hasValid: boolean;
13-
protected invalidKeys: string[];
14-
constructor(constructorName: string);
15-
abstract init(): void;
16-
addModifier(name: string, fn: ModifierFn<T>, pos?: string): void;
17-
addRule(name: string, fn: RuleFn, pos?: string): void;
18-
setParams(params: NormalObject, value: undefined): NormalObject | never;
19-
setParams(key: string, value: NormalObject): NormalObject | never;
20-
frozen(): this;
21-
reGenerate(fn?: (options: SuchOptions) => Result<T>): void;
22-
make(options: SuchOptions): Result<T>;
23-
abstract generate(options: SuchOptions): Result<T>;
24-
abstract test(target: T): boolean;
25-
private add;
26-
private validParams;
27-
private validate;
28-
private resetValidInfo;
29-
private runModifiers;
30-
private runFuncs;
31-
private runAll;
6+
protected readonly constructorName: string;
7+
protected configOptions: MockitConfig;
8+
protected params: TObject;
9+
protected origParams: TObject;
10+
protected generateFn: undefined | ((options: SuchOptions) => Result<T>);
11+
protected isValidOk: boolean;
12+
protected hasValid: boolean;
13+
protected invalidKeys: string[];
14+
constructor(constructorName: string);
15+
abstract init(): void;
16+
addModifier(name: string, fn: ModifierFn<T>, pos?: string): void;
17+
addRule(name: string, fn: RuleFn, pos?: string): void;
18+
setParams(params: TObject, value: undefined): TObject | never;
19+
setParams(key: string, value: TObject): TObject | never;
20+
frozen(): this;
21+
reGenerate(fn?: (options: SuchOptions) => Result<T>): void;
22+
make(options: SuchOptions): Result<T>;
23+
abstract generate(options: SuchOptions): Result<T>;
24+
abstract test(target: T): boolean;
25+
private add;
26+
private validParams;
27+
private validate;
28+
private resetValidInfo;
29+
private runModifiers;
30+
private runFuncs;
31+
private runAll;
3232
}

lib/node/utils.d.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
import { NormalObject } from 'reregexp';
1+
import { TObject } from 'reregexp';
22
import { ParamsPathItem } from '../types';
3-
export declare const loadDict: (filePath: string | string[], useCache?: boolean) => Promise<string[] | string[][]>;
3+
export declare const loadDict: (
4+
filePath: string | string[],
5+
useCache?: boolean,
6+
) => Promise<string[] | string[][]>;
47
export declare const getAllFiles: (directory: string) => Promise<string[]>;
5-
export declare const loadJson: (filePath: string | string[]) => Promise<string[] | string[][]>;
6-
export declare const loadAllData: (allFiles: string[]) => Promise<[string[] | string[][], string[] | string[][]]>;
8+
export declare const loadJson: (
9+
filePath: string | string[],
10+
) => Promise<string[] | string[][]>;
11+
export declare const loadAllData: (
12+
allFiles: string[],
13+
) => Promise<[string[] | string[][], string[] | string[][]]>;
714
export declare const loadTemplate: (file: string) => Promise<{}>;
815
export declare const getRealPath: (item: ParamsPathItem) => string;
9-
export declare const getCascaderValue: (data: NormalObject, values: any[]) => any;
16+
export declare const getCascaderValue: (
17+
data: TObject<unknown>,
18+
values: any[],
19+
) => any;

lib/parser/namespace.d.ts

+39-34
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,51 @@
1-
import { NormalObject, ParserConfig } from '../types';
1+
import { TObject, ParserConfig } from '../types';
22
export interface Tags {
3-
start: string;
4-
end: string;
3+
start: string;
4+
end: string;
55
}
66
export interface ParserConstructor extends ParserConfig {
7-
readonly splitor?: string;
8-
new (): ParserInterface;
7+
readonly splitor?: string;
8+
new (): ParserInterface;
99
}
1010
export declare abstract class ParserInterface {
11-
protected params: string[];
12-
protected patterns: any[][];
13-
protected tags: Tags;
14-
protected code: string;
15-
protected setting: NormalObject;
16-
protected defaults: NormalObject;
17-
constructor();
18-
init(): this;
19-
info(): {
20-
tags: Tags;
21-
params: string[];
22-
code: string;
23-
patterns: any[][];
24-
};
25-
parseCode(code: string, tags: Tags): void;
26-
abstract parse(): object | never;
27-
protected halt(err: string): never;
11+
protected params: string[];
12+
protected patterns: any[][];
13+
protected tags: Tags;
14+
protected code: string;
15+
protected setting: TObject;
16+
protected defaults: TObject;
17+
constructor();
18+
init(): this;
19+
info(): {
20+
tags: Tags;
21+
params: string[];
22+
code: string;
23+
patterns: any[][];
24+
};
25+
parseCode(code: string, tags: Tags): void;
26+
abstract parse(): object | never;
27+
protected halt(err: string): never;
2828
}
2929
export interface ParserList {
30-
[index: string]: ParserConstructor;
30+
[index: string]: ParserConstructor;
3131
}
3232
export interface ParserInstances {
33-
[index: string]: ParserInterface;
33+
[index: string]: ParserInterface;
3434
}
3535
export declare class Dispatcher {
36-
protected parsers: ParserList;
37-
protected tagPairs: string[];
38-
protected pairHash: NormalObject;
39-
protected readonly splitor: string;
40-
protected instances: ParserInstances;
41-
addParser(name: string, config: ParserConfig, parse: () => void, setting?: NormalObject): never | void;
42-
parse(code: string): NormalObject | never;
43-
protected getInstance(name: string): ParserInterface;
44-
protected parseUntilFind(context: string): NormalObject;
45-
protected halt(err: string): never;
36+
protected parsers: ParserList;
37+
protected tagPairs: string[];
38+
protected pairHash: TObject;
39+
protected readonly splitor: string;
40+
protected instances: ParserInstances;
41+
addParser(
42+
name: string,
43+
config: ParserConfig,
44+
parse: () => void,
45+
setting?: TObject,
46+
): never | void;
47+
parse(code: string): TObject | never;
48+
protected getInstance(name: string): ParserInterface;
49+
protected parseUntilFind(context: string): TObject;
50+
protected halt(err: string): never;
4651
}

lib/store.d.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { NormalObject } from './types';
1+
import { TObject } from './types';
22
export interface Store {
3-
(name: string, value: any, alwaysVar: boolean): void;
4-
vars: NormalObject;
5-
fns: NormalObject;
6-
mockits: NormalObject;
7-
alias: NormalObject;
8-
aliasTypes: string[];
9-
fileCache: NormalObject;
10-
config: NormalObject;
3+
(name: string, value: any, alwaysVar: boolean): void;
4+
vars: TObject;
5+
fns: TObject;
6+
mockits: TObject;
7+
alias: TObject;
8+
aliasTypes: string[];
9+
fileCache: TObject;
10+
config: TObject;
1111
}
1212
declare const store: Store;
1313
export default store;

0 commit comments

Comments
 (0)