Monster 1.24 released
Tags: javascript, dom, node
Published: 2021-11-14 18:59:38

---
title: Monster 1.24 released
published: true
description: Monsterjs Release  
tags: javascript, dom, nodejs
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/me46ovsxd18w0vvez0nx.png
series: Monster-Release
---

Today we released the latest edition of our Monster project. Monster is a collection of javascript classes that we need for daily work in our web projects.

Besides small helper functions and classes it also provides useful functions to enable reactive programming.

Only the changes are described here. The full functionality can be found in the [documentation](https://monsterjs.org/en/doc/1.24.0/).

## Transformer

The transformer class is used by updater and pipe to parse strings and execute the contained commands.

In this version, the Transformer class has been extended with useful commands:

`debug`, `to-base64`, `from-base64`, `path-exists`, `nth-key`, `nth-last-key`, `first`, `last` and optimzed `default`.

### nth-key, nth-last-key, first, last

The commands allow access to certain properties of objects. 

The `nth-key` command allows access to the nth key. The object keys are sorted.

```javascript
import {Transformer} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.24.0/dist/modules/data/transformer.js';

const transformer = new Transformer("nth-key:1")
console.log(transformer.run({a:1,b:2,c:3}))
// ↦ 2
```

`first`is identical to `nth-key:0` and `last` is equivalent to `nth-last-key:0`.

### to-base64, from-base64

As the name suggests, this allows encoding from and to base64 (these are easier to remember aliases for atob and btoa).

```javascript
import {Transformer} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.24.0/dist/modules/data/transformer.js';

const transformer1 = new Transformer("to-base64")
console.log(transformer1.run('hello world!')) 
// ↦ aGVsbG8gd29ybGQh

const transformer2 = new Transformer("from-base64")
console.log(transformer2.run('aGVsbG8gd29ybGQh'))
// ↦ hello world!
```

### debug 

The command `debug` is an auxiliary command that allows to output the current value on the console. This is in interaction with the pipe and DOM Attributes a possibility to debug errors.

```javascript
import {Transformer} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.24.0/dist/modules/data/transformer.js';

const transformer = new Transformer("debug")
console.log(transformer.run({a:true})) 
// ↦ {a: true}
```

The value is returned both on the console and as the return value of the method.

### path-exists

With the command `path-exists` you can check if a certain path is set in the object. This is useful for example to set a class depending on an existing value.

```javascript
import { Transformer } from "https://cdn.jsdelivr.net/npm/@schukai/monster@1.24.0/dist/modules/data/transformer.js";

const transformer = new Transformer("path-exists:a.b.c");
console.log(transformer.run({ a: { b: { c: true } } }));
// ↦ true
```

### default

The default command can be used to specify a default value whenever the input value is `undefined` or `null`.

```javascript
const transformer = new Transformer("default:true:bool");
console.log(transformer.run(undefined));
// ↦ true
```

## trimSpace

The Javascript `trim()` function removes all spaces at the beginning and end of a string.

```javascript
console.log(" test ".trim())
// ↦ "test"
```

The following string would also be shortened.

```javascript
// hint: the two \\ become one \ in the string
console.log(" test\\ ".trim())
// ↦ "test\"
```

```javascript
import {trimSpaces} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.24.0/dist/modules/util/trimspaces.js';
console.log(trimSpaces(' test\\ '))
// ↦ "test\ "
```

There were also a number of minor improvements and optimizations.


_hope you enjoy it!_



## References

* [project home](https://monsterjs.org)
* [documentation, monsterjs.org/en/doc/1.24.0](https://monsterjs.org/en/doc/1.24.0/)
* [form example](https://monsterjs.org/en/doc/1.24.0/tutorial-form-example.html)
* [Transformer](https://monsterjs.org/en/doc/1.24.0/Monster.Data.Transformer.html)
* [tc39.es/ecma262/multipage/text-processing.html#sec-string.prototype.trim](https://tc39.es/ecma262/multipage/text-processing.html#sec-string.prototype.trim)