调整文档,改进设计
This commit is contained in:
37
src/base.ts
37
src/base.ts
@@ -1,31 +1,5 @@
|
||||
/**
|
||||
* 配置基类,下划线开头的变量不会被序列化
|
||||
*/
|
||||
export class ConfigBase {
|
||||
name: string = '';
|
||||
version:string = '1.0.0';
|
||||
[key: string]: any;
|
||||
import { ConfigBase } from "./models/config";
|
||||
|
||||
/**
|
||||
* 加载反序列化数据
|
||||
* @param data
|
||||
*/
|
||||
load(data:Record<string,unknown>){
|
||||
for (const key of Object.getOwnPropertyNames(this).filter(i=>i[0]!=='_')) {
|
||||
if(data[key]!=undefined){
|
||||
this[key] = data[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 序列化json方法
|
||||
* @returns
|
||||
*/
|
||||
toJson(){
|
||||
return JSON.stringify(this,(k,v)=>k[0]=='_'?undefined:v);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加工处理器上下文
|
||||
@@ -52,13 +26,4 @@ export abstract class ProcessorBase<TInput,TOutput,TConfig extends ConfigBase> {
|
||||
public readonly name: string = '';
|
||||
public readonly version: string = '1.0.0';
|
||||
public abstract exec(context:ProcessorContext<TInput,TOutput,TConfig>):Promise<void>|void
|
||||
}
|
||||
|
||||
export interface FileOptions {
|
||||
encode?: string;
|
||||
addBOM?: boolean;
|
||||
}
|
||||
export interface FileInfo extends FileOptions {
|
||||
name: string,
|
||||
content: string | Blob | Uint8Array,
|
||||
}
|
@@ -1,3 +1,4 @@
|
||||
export * from './base';
|
||||
export * from './processors';
|
||||
export * from './parsers';
|
||||
export * from './parsers';
|
||||
export * from './models/config';
|
||||
export * from './models/file';
|
28
src/models/config.ts
Normal file
28
src/models/config.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* 配置基类,下划线开头的变量不会被序列化
|
||||
*/
|
||||
export class ConfigBase {
|
||||
name: string = '';
|
||||
version:string = '1.0.0';
|
||||
[key: string]: any;
|
||||
|
||||
/**
|
||||
* 加载反序列化数据
|
||||
* @param data
|
||||
*/
|
||||
load(data:Record<string,unknown>){
|
||||
for (const key of Object.getOwnPropertyNames(this).filter(i=>i[0]!=='_')) {
|
||||
if(data[key]!=undefined){
|
||||
this[key] = data[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 序列化json方法
|
||||
* @returns
|
||||
*/
|
||||
toJson(){
|
||||
return JSON.stringify(this,(k,v)=>k[0]=='_'?undefined:v);
|
||||
}
|
||||
}
|
8
src/models/file.ts
Normal file
8
src/models/file.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export interface FileOptions {
|
||||
encode?: string;
|
||||
addBOM?: boolean;
|
||||
}
|
||||
export interface FileInfo extends FileOptions {
|
||||
name: string,
|
||||
content: string | Blob | Uint8Array,
|
||||
}
|
@@ -1,4 +1,6 @@
|
||||
import { ConfigBase, FileInfo, ProcessorBase } from "./base";
|
||||
import { ProcessorBase } from "./base";
|
||||
import { ConfigBase } from "./models/config";
|
||||
import { FileInfo } from "./models/file";
|
||||
|
||||
// todo: 类型参数待补完
|
||||
|
||||
|
Reference in New Issue
Block a user