'use strict';
/**
* @author schukai GmbH
*/
import {Monster} from '../namespace.js';
import {isPrimitive, isBoolean, isString, isObject, isArray, isFunction} from '../types/is.js';
/**
* this method checks if the type matches the primitive type. this function is identical to isPrimitive() except that a TypeError is thrown.
*
* you can call the method via the monster namespace `Monster.Types.validatePrimitive()`.
*
* ```
* <script type="module">
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.1.0/dist/modules/types/validate.js';
* console.log(Monster.Types.validatePrimitive('2')) // ↦ undefined
* console.log(Monster.Types.validatePrimitive([])) // ↦ TypeError
* </script>
* ```
*
* Alternatively, you can also integrate this function individually.
*
* ```
* <script type="module">
* import {validatePrimitive} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.1.0/dist/modules/types/validate.js';
* console.log(validatePrimitive('2')) // ↦ undefined
* console.log(validatePrimitive([])) // ↦ TypeError
* </script>
* ```
*
* @param {*} value
* @return {undefined}
* @since 1.0.0
* @copyright schukai GmbH
* @memberOf Monster/Types
* @throws {TypeError} value is not a primitive
* @see {@link isPrimitive}
* @see {@link Monster/Types/isPrimitive}
* @see {@link Monster/Types#isPrimitive}
*/
function validatePrimitive(value) {
if (!isPrimitive(value)) {
throw new TypeError('value is not a primitive')
}
}
/**
* this method checks if the type matches the boolean type. this function is identical to isBoolean() except that a TypeError is thrown.
*
* you can call the method via the monster namespace `Monster.Types.validateBoolean()`.
*
* ```
* <script type="module">
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.1.0/dist/modules/types/validate.js';
* console.log(Monster.Types.validateBoolean(true)) // ↦ undefined
* console.log(Monster.Types.validateBoolean('2')) // ↦ TypeError
* console.log(Monster.Types.validateBoolean([])) // ↦ TypeError
* </script>
* ```
*
* Alternatively, you can also integrate this function individually.
*
* ```
* <script type="module">
* import {validateBoolean} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.1.0/dist/modules/types/validate.js';
* console.log(validateBoolean(false)) // ↦ undefined
* console.log(validateBoolean('2')) // ↦ TypeError
* console.log(validateBoolean([])) // ↦ TypeError
* </script>
* ```
*
* @param {*} value
* @return {undefined}
* @since 1.0.0
* @copyright schukai GmbH
* @memberOf Monster/Types
* @throws {TypeError} value is not primitive
*/
function validateBoolean(value) {
if (!isBoolean(value)) {
throw new TypeError('value is not a boolean')
}
}
/**
* this method checks if the type matches the string type. this function is identical to isString() except that a TypeError is thrown.
*
* you can call the method via the monster namespace `Monster.Types.validateString()`.
*
* ```
* <script type="module">
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.1.0/dist/modules/types/validate.js';
* console.log(Monster.Types.validateString('2')) // ↦ undefined
* console.log(Monster.Types.validateString([])) // ↦ TypeError
* </script>
* ```
*
* Alternatively, you can also integrate this function individually.
*
* ```
* <script type="module">
* import {validateString} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.1.0/dist/modules/types/validate.js';
* console.log(validateString('2')) // ↦ undefined
* console.log(validateString([])) // ↦ TypeError
* </script>
* ```
*
* @param {*} value
* @return {undefined}
* @since 1.0.0
* @copyright schukai GmbH
* @memberOf Monster/Types
* @throws {TypeError} value is not a string
*/
function validateString(value) {
if (!isString(value)) {
throw new TypeError('value is not a string')
}
}
/**
* this method checks if the type matches the object type. this function is identical to isObject() except that a TypeError is thrown.
*
* you can call the method via the monster namespace `Monster.Types.validateObject()`.
*
* ```
* <script type="module">
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.1.0/dist/modules/types/validate.js';
* console.log(Monster.Types.validateObject({})) // ↦ undefined
* console.log(Monster.Types.validateObject('2')) // ↦ TypeError
* console.log(Monster.Types.validateObject([])) // ↦ TypeError
* </script>
* ```
*
* Alternatively, you can also integrate this function individually.
*
* ```
* <script type="module">
* import {validateObject} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.1.0/dist/modules/types/validate.js';
* console.log(validateObject({})) // ↦ undefined
* console.log(validateObject('2')) // ↦ TypeError
* console.log(validateObject([])) // ↦ TypeError
* </script>
* ```
*
* @param {*} value
* @return {undefined}
* @since 1.0.0
* @copyright schukai GmbH
* @memberOf Monster/Types
* @throws {TypeError} value is not a object
*/
function validateObject(value) {
if (!isObject(value)) {
throw new TypeError('value is not a object')
}
}
/**
* this method checks if the type matches the array type. this function is identical to isArray() except that a TypeError is thrown.
*
* you can call the method via the monster namespace `Monster.Types.validateArray()`.
*
* ```
* <script type="module">
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.1.0/dist/modules/types/validate.js';
* console.log(Monster.Types.validateArray('2')) // ↦ TypeError
* console.log(Monster.Types.validateArray([])) // ↦ undefined
* </script>
* ```
*
* Alternatively, you can also integrate this function individually.
*
* ```
* <script type="module">
* import {validateArray} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.1.0/dist/modules/types/validate.js';
* console.log(validateArray('2')) // ↦ TypeError
* console.log(validateArray([])) // ↦ undefined
* </script>
* ```
*
* @param {*} value
* @return {undefined}
* @since 1.0.0
* @copyright schukai GmbH
* @memberOf Monster/Types
* @throws {TypeError} value is not a array
*/
function validateArray(value) {
if (!isArray(value)) {
throw new TypeError('value is not not a array')
}
}
/**
* this method checks if the type matches the function type. this function is identical to isFunction() except that a TypeError is thrown.
*
* you can call the method via the monster namespace `Monster.Types.validateFunction()`.
*
* ```
* <script type="module">
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.1.0/dist/modules/types/validate.js';
* console.log(Monster.Types.validateFunction(()=>{})) // ↦ undefined
* console.log(Monster.Types.validateFunction('2')) // ↦ TypeError
* console.log(Monster.Types.validateFunction([])) // ↦ TypeError
* </script>
* ```
*
* Alternatively, you can also integrate this function individually.
*
* ```
* <script type="module">
* import {validateFunction} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.1.0/dist/modules/types/validate.js';
* console.log(validateFunction(()=>{})) // ↦ undefined
* console.log(validateFunction('2')) // ↦ TypeError
* console.log(validateFunction([])) // ↦ TypeError
* </script>
* ```
*
* @param {*} value
* @return {undefined}
* @since 1.0.0
* @copyright schukai GmbH
* @memberOf Monster/Types
* @throws {TypeError} value is not a function
*/
function validateFunction(value) {
if (!isFunction(value)) {
throw new TypeError('value is not a function')
}
}
Monster.assignToNamespace('Monster.Types', validatePrimitive, validateBoolean, validateString, validateObject, validateArray, validateFunction);
export {Monster, validatePrimitive, validateBoolean, validateString, validateObject, validateArray, validateFunction}