Options
All
  • Public
  • Public/Protected
  • All
Menu

Deformat(extends Divider) can split value to multiple parts, usually used when parsing logs. Deformat API based on https://www.npmjs.com/package/deformat

example

const combined = `$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"`;
const log = `192.168.203.111 - - [03/Dec/2014:22:07:37 -0800] "GET /api/foo/bar?key=value&key=has space&key has \x22&key2=var2 HTTP/1.1" 404 576 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36"`;
const deformat = new Deformat({
  combined,
});
deformat.next(Gather);
let times = 0;
deformat.handle(log, (result) => {
  console.log(result);
});
// 192.168.203.111
//
// 03/Dec/2014:22:07:37 -0800
//...

Hierarchy

Index

Constructors

constructor

Methods

after

  • The after method can specify Filter to process results after divide.

    after方法可在divide后指定Filter对分裂后的results进行处理

    Parameters

    Returns this

before

  • before(f: Filter<any>): this
  • The before method can specify Filter to process the original result before divide.

    before方法可在divide前指定Filter对原始result进行处理

    Parameters

    Returns this

handle

  • Handle is invoke method of Middleware. Result is the data to be processed. GatherCallback is a callback for processing. GatherCallback accepts Result | undefined.

    handle是Middleware类被调用时使用的方法, result为待处理Result类型, 如果传入值为string类型, 会自动转为["undefined", string] GatherCallback为处理完毕时的回调

    Parameters

    Returns void

next

  • The next method is same as the nextEach method when accepts Middleware However it provides a simple way by using Finisher Type.

    next方法同nextEach方法可以接受一个Middleware, 或者next可以接受Finisher类类型作为一种简写方式

    example
    
     // Gather extends Finisher
     divider.next(new Gather());
     divider.next(Gather);

    Parameters

    Returns this

nextEach

  • The nextEach method accepts a Middleware to handle each result.

    nextEach方法接受一个Middleware处理每个result

    Parameters

    Returns this

nextIndex

  • nextIndex(action: Array<Middleware<any>> | object): this
  • The nextList method accepts {[index:string]: Middleware} / Middleware[], and each Middleware handles the result corresponding to its index.

    nextList方法接受一个索引对象, 每个Middleware处理对应其index对应的result

    Parameters

    Returns this

nextList

  • The nextList method accepts Middleware array, and each Middleware processes result corresponding to index.

    nextList方法接受Middleware数组, 每个Middleware处理对应index的result

    Parameters

    Returns this