one-server-tools
v0.0.6
Published
> It's a common-used tool kit for nodejs server.
Downloads
4
Readme
It's a common-used tool kit for nodejs server.
Functions
// fetch.ts
class FetchResult {
req:any
res:any
init(res:any, req?:any):void;
data( data?:Buffer ): Buffer|void;
json(): any;
text(): string;
}
function fetch( url:string, options?:{ method?:string; headers?:any; }, body?:any ): Promise<FetchResult>;
// jwt.ts
function jwtSign(payload:object, secret:string, expiresIn?: number|string): string;
function jwtVerify(token:string, secret:string): any;
// req.ts
function getIP(req: any): string;
function isExpress(req:any): boolean;
class RawDat {
/**
* 原始数据
* @returns
*/
data(): Promise<Buffer>;
/**
* 解析为JSON参数
* @returns
*/
parse(): Promise<object>;
}
/**
* 从request中获取原始数据
* @param req 请求体
* @returns RawDat
*/
function _raw(req:any): RawDat;
// res.ts
function reply(res:any, data:number|string, chunks?:boolean): void;
function reply(res:any, data:{[field:string]:any}, chunks?:boolean): void;
function reply(res:any, err:Error, errcode?:number, chunks?:boolean): void;
function download(res:any, file:string, filename?: string): void;
function download(res:any, buff:Buffer, filename?: string): void;
// transmit.ts
class TransResult {
req:any;
res:any;
init(res:any, req?:any):void;
data( data?:Buffer ): Buffer|void;
json(): any;
text(): string;
}
type GFields = { [field: string]: string; }
type GFile = {
name: string;
path?: string;
content?: string;
contentBinary?: Buffer;
}
type GFiles = {
[file: string]: GFile;
}
/**
* simulate multipart upload
* @param url upload URL
* @param options http(s).RequestOptions
* @param fields { [field: string]: string; }
* @param files { [file: string]: GFile; }
*/
function transmit( url:string, options: any, fields: GFields, files: GFiles): Promise<TransResult>;