constraints/isarray.js

'use strict';

/**
 * @author schukai GmbH
 */

import {Monster, AbstractConstraint} from "./abstract.js";
import {isArray} from "../types/is.js";

/**
 *
 *
 * you can call the method via the monster namespace `new Monster.Constraint.IsObject()`.
 *
 * ```
 * <script type="module">
 * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.5.0/dist/modules/constraints/isarray.js';
 * console.log(new Monster.Constraint.IsArray())
 * </script>
 * ```
 *
 * Alternatively, you can also integrate this function individually.
 *
 * ```
 * <script type="module">
 * import {IsArray} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.5.0/dist/modules/constraints/isarray.js';
 * console.log(new IsArray())
 * </script>
 * ```
 *
 * @since 1.3.0
 * @copyright schukai GmbH
 * @memberOf Monster/Constraints
 */
class IsArray extends AbstractConstraint {

    /**
     * this method return a promise containing the result of the check.
     *
     * @param {*} value
     * @returns {Promise}
     */
    isValid(value) {
        if(isArray(value)) {
            return Promise.resolve(value);
        }

        return Promise.reject(value);
    }

}

Monster.assignToNamespace('Monster.Constraints', IsArray);
export {Monster, IsArray}