diff --git a/packages/monster/source/data/pipe.js b/packages/monster/source/data/pipe.js index 84d1f0f8292ca08375f661de38e813ffd2be6e72..57d34cc272d00ea4f6e1123e8268df080f145572 100644 --- a/packages/monster/source/data/pipe.js +++ b/packages/monster/source/data/pipe.js @@ -40,7 +40,7 @@ const DELIMITER = '|'; * * @example * import {Pipe} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.9.0/dist/modules/data/pipe.js'; - * + * * let obj = { * a: { * b: { @@ -50,7 +50,7 @@ const DELIMITER = '|'; * } * } * } - * + * * console.log(new Pipe('path:a.b.c.d | toupper | prefix:Hello\\ ').run(obj)); * // ↦ Hello WORLD * @@ -63,7 +63,7 @@ class Pipe extends Base { /** * * @param {string} pipe a pipe consists of commands whose input and output are connected with the pipe symbol `|`. - * @throws {TypeError} + * @throws {TypeError} */ constructor(pipe) { super(); @@ -71,7 +71,7 @@ class Pipe extends Base { this.pipe = pipe.split(DELIMITER).map((v) => { return new Transformer(v); }); - + } @@ -79,23 +79,18 @@ class Pipe extends Base { * * @param {string} name * @param {function} callback + * @param {object} context * @returns {Transformer} * @throws {TypeError} value is not a string * @throws {TypeError} value is not a function */ - setCallback(name, callback) { + setCallback(name, callback, context) { - for(const [,t] of Object.entries(this.pipe)) { - t.setCallback(name, callback); + for (const [, t] of Object.entries(this.pipe)) { + t.setCallback(name, callback, context); } - + return this; - - // return this.pipe.reduce((accumulator, transformer, currentIndex, array) => { - // return transformer.setCallback(name,callback); - // }, value); - - } /**