Pipe

Monster.Data. Pipe

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

You can call the method via the monster namespace new Monster.Data.Pipe().

<script type="module">
import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.30.0/dist/monster.js';
new Monster.Data.Pipe()
</script>

Alternatively, you can also integrate this function individually.

<script type="module">
import {Pipe} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.30.0/dist/modules/data/pipe.js';
new Pipe()
</script>

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:
Name Type Description
pipe string

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

Since:
  • 1.5.0
Throws:
TypeError
Example
import {Pipe} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.30.0/dist/modules/data/pipe.js';

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

Parameters:
Name Type Description
value *
Returns:
Type
*

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

Parameters:
Name Type Description
name string
callback function
context object
Throws:
  • value is not a string

    Type
    TypeError
  • value is not a function

    Type
    TypeError
Returns:
Type
Transformer