Monster.Data. Pipe

The pipe class makes it possible to combine several processing steps.

A pipe consists of commands whose input and output are connected with the pipe symbol |.

With the Pipe, processing steps can be combined. Here, the value of an object is accessed via the pathfinder (path command). the word is then converted to uppercase letters and a prefix Hello is added. the two backslash safe the space char.

Constructor

new Pipe(pipe)

Parameters:
NameTypeDescription
pipestring

a pipe consists of commands whose input and output are connected with the pipe symbol |.

Since
  • 1.5.0
License
  • AGPLv3
Throws:
TypeError
Example
import {Pipe} from '@schukai/monster/source/data/pipe.mjs';

let obj = {
    a: {
        b: {
            c: {
                d: "world"
            }
        }
    }
}

console.log(new Pipe('path:a.b.c.d | toupper | prefix:Hello\\ ').run(obj));
// ↦ Hello WORLD

Methods

run(value) → {*}

run a pipe

.

run a pipe

Parameters:
NameTypeDescription
value*
Returns:
Type: 
*

setCallback(name, callback, context) → {Transformer}

Parameters:
NameTypeDescription
namestring
callbackfunction
contextobject
Throws:
  • value is not a string

    Type
    TypeError
  • value is not a function

    Type
    TypeError
Returns:
Type: 
Transformer