Skip to content

Commit

Permalink
Add shitty and primitive map operation
Browse files Browse the repository at this point in the history
  • Loading branch information
hershal committed Sep 7, 2017
1 parent 8fbf244 commit f0c3029
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export default class Dispatch {
split: {dispatcher: DispatcherStandardInputStream, operation: TextOperations.Split},
trim: {dispatcher: DispatcherStandardInputStream, operation: TextOperations.Trim},
cat: {dispatcher: DispatcherStandardInputStream, operation: TextOperations.Cat},
map: {dispatcher: DispatcherStandardInputStream, operation: TextOperations.Map},
/* join: {dispIInputStreamDelegaterStandardInputStream, operation: TextOperations.Join} */
};
public streamDelegate?: IStreamDelegate;
Expand Down
14 changes: 14 additions & 0 deletions src/TextOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,17 @@ export class Cat implements IStreamingOperation {
return data + this.stringToConcatenate;
}
}


export class Map implements IStreamingOperation {
private debug = Debug('Map');
private func: any;

public parse(args: string[]): void {
this.func = args.join(' ');
}

public run(data: string): string {
return eval(this.func)(data);
}
}
11 changes: 11 additions & 0 deletions test/DispatchSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,15 @@ describe('DispatcherStandardInputStream', function () {
stdin.write('ello\nsomething');
stdin.end();
});

it('Dispatches to map', function (done) {
const cat = new TextOperations.Map();
dispatch
.dispatch(cat, [`(x) => {const path = require('path'); return x + path.extname(x);}`])
.then(() => expect(handlerDelegate.buffer).to.deep.equal(['hello.world.world']))
.then(() => done())
.catch((err) => console.log(err));
stdin.write('hello.world');
stdin.end();
});
});

0 comments on commit f0c3029

Please sign in to comment.