OrOperator

Monster.Constraints. OrOperator

Constraints are used to define conditions that must be met by the value of a variable.

The uniform API of the constraints allows chains to be formed.

The OrOperator is used to link several constraints. The constraint is fulfilled if one of the constraints is fulfilled.

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

Alternatively, you can also integrate this function individually.

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

Constructor

# new OrOperator()

A or operator

Since:
  • 1.3.0
Example
import {Valid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.30.0/dist/modules/constraints/valid.js';
import {Invalid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.30.0/dist/modules/constraints/invalid.js';
import {OrOperator} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.30.0/dist/modules/constraints/oroperator.js';

new OrOperator(
new Valid(), new Invalid()).isValid()
.then(()=>console.log(true))
.catch(()=>console.log(false));
// ↦ true

new OrOperator(
new Invalid(), new Invalid()).isValid()
.then(()=>console.log(true))
.catch(()=>console.log(false));
// ↦ false

Methods

# isValid(value) → {Promise}

this method return a promise containing the result of the check.

Parameters:
Name Type Description
value *
Returns:
Type
Promise