Monster/Data

Monster/Data

In this namespace you will find classes and methods for handling data.

Author:
  • schukai GmbH

Classes

Pathfinder
Pipe
Transformer

Methods

# (static) Diff(first, second) → {array}

With the diff function you can perform the change of one object to another. The result shows the changes of the second object to the first object.

The operator add means that something has been added to the second object. delete means that something has been deleted from the second object compared to the first object.

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

<script type="module">
import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/data/diff.js';
console.log(Monster.Data.Diff(a, b))
</script>

Alternatively, you can also integrate this function individually.

<script type="module">
import {Diff} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/data/diff.js';
console.log(Diff(a, b))
</script>
Parameters:
Name Type Description
first *
second *
Since:
  • 1.6.0
Returns:
Type
array
Example
import {Diff} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/data/diff.js';

// given are two objects x and y.

let x = {
    a: 1,
    b: "Hello!"
}

 let y = {
    a: 2,
    c: true
}

// These two objects can be compared with each other.

console.log(Diff(x, y));

// the result is then the following

//
// [
// {
//        operator: 'update',
//        path: [ 'a' ],
//        first: { value: 1, type: 'number' },
//        second: { value: 2, type: 'number' }
//    },
// {
//        operator: 'delete',
//        path: [ 'b' ],
//        first: { value: 'Hello!', type: 'string' }
//    },
// {
//        operator: 'add',
//        path: [ 'c' ],
//        second: { value: true, type: 'boolean' }
//    }
// ]

# (static) extend(target) → {object}

extend copies all enumerable own properties from one or more source objects to a target object. It returns the modified target object.

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

<script type="module">
import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/data/extend.js';
console.log(Monster.Data.extend(a, b))
</script>

Alternatively, you can also integrate this function individually.

<script type="module">
import {extend} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/data/extend.js';
console.log(extend(a, b))
</script>
Parameters:
Name Type Description
target object
object
Since:
  • 1.10.0
Throws:
  • unsuported argument

    Type
    Error
  • type mismatch

    Type
    Error
Returns:
Type
object