Monster.Data. Transformer

The transformer class is a swiss army knife for manipulating values. especially in combination with the pipe, processing chains can be built up.

A simple example is the conversion of all characters to lowercase. for this purpose the command tolower must be used.

let t = new Transformer('tolower').run('ABC'); // ↦ abc

Constructor

new Transformer(definition)

Parameters:
NameTypeDescription
definitionstring
Since
  • 1.5.0
License
  • AGPLv3
Example
import {Transformer} from '@schukai/monster/source/data/transformer.mjs';

const transformer = new Transformer("tolower")

console.log(transformer.run("HELLO"))
// ↦ hello

console.log(transformer.run("WORLD"))
// ↦ world

Methods

run(value) → {*}

Parameters:
NameTypeDescription
value*
Throws:
  • unknown command

    Type
    Error
  • unsupported type

    Type
    TypeError
  • type not supported

    Type
    Error
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