munge.js 764 B

1234567891011121314151617181920212223242526272829303132
  1. var PipelineCommand = require('./commands/PipelineCommand');
  2. var Munger = (function(){
  3. // CONSTRUCTOR
  4. var base = Object, proto, klass = function Munger(ops){
  5. if (!ops){
  6. throw new Error("munge requires a pipeline!");
  7. }
  8. if (typeof ops.length !== "number"){
  9. ops = [ops];
  10. }
  11. this.pipeline = new PipelineCommand(ops);
  12. };
  13. proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  14. // PROTOTYPE MEMBERS
  15. proto.execute = function execute(inputs){
  16. var result = {};
  17. result.ok = this.pipeline.run(inputs, result);
  18. return result;
  19. };
  20. return klass;
  21. })();
  22. module.exports = function munge(ops, inputs) {
  23. var munger = new Munger(ops);
  24. if(inputs)
  25. return munger.execute(inputs);
  26. return munger.execute.bind(munger);
  27. };