Monster. Types

Namespace for types.

Author
  • schukai GmbH

Classes

Base
BaseWithOptions
DataUrl
ID

Automatic generation of ids

MediaType
Node

A Node Class

NodeList

A NodeList class

NodeRecursiveIterator

An iterator to run recursively through a tree of nodes

Observer
ObserverList
ProxyObserver
Queue

A Queue (Fifo)

RandomID

class to generate random numbers

Stack
TokenList
UniqueQueue

A queue for unique values

UUID
Version

The version object contains a sematic version number

Methods

(static) escapeString(value) → {string}

This function prefixes all special characters that may appear in a regex with a slash.

This function prefixes all special characters that may appear in a regex with a slash.

Parameters:
NameTypeDescription
valuestring
Since
  • 1.26.0
License
  • AGPLv3
Throws:

value is not a string

Type
TypeError
Returns:
Type: 
string

(static) fromBinary(binary) → {String}

You can call the function via the monster namespace Monster.Types.fromBinary().

You can call the function via the monster namespace Monster.Types.fromBinary().

Parameters:
NameTypeDescription
binaryString
Since
  • 1.18.0
License
  • AGPLv3
Throws:

value is not a string

Type
TypeError
Returns:
Type: 
String

(static) getGlobal() → {objec}

Return globalThis

If globalThis is not available, it will be polyfilled

.

Return globalThis

If globalThis is not available, it will be polyfilled

Since
  • 1.6.0
License
  • AGPLv3
Returns:

globalThis

Type: 
objec

(static) getGlobalFunction(name) → {objec}

Return global function or throw Error

You can call the method via the monster namespace Monster.Types.getGlobalFunction().

Return global function or throw Error

You can call the method via the monster namespace Monster.Types.getGlobalFunction().

<script type="module">
import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/[email protected]/dist/monster.mjs';
console.log(Monster.Types.getGlobalFunction('parseInt')) // ↦ f parseInt() { }
</script>

Alternatively, you can also integrate this function individually.

<script type="module">
import {getGlobalFunction} from 'https://cdn.jsdelivr.net/npm/@schukai/[email protected]/dist/modules/types/global.mjs';
console.log(getGlobalFunction('parseInt')) // ↦ f parseInt() { }
</script>
Parameters:
NameTypeDescription
namestring
Since
  • 1.6.0
License
  • AGPLv3
Throws:
  • value is not a function

    Type
    TypeError
  • the function is not defined

    Type
    Error
  • value is not a string

    Type
    TypeError
Returns:
Type: 
objec

(static) getGlobalObject(name) → {objec}

Return global object or throw Error

You can call the method via the monster namespace Monster.Types.getGlobalObject().

Return global object or throw Error

You can call the method via the monster namespace Monster.Types.getGlobalObject().

<script type="module">
import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/[email protected]/dist/monster.mjs';
Monster.Types.getGlobalObject('document')
// ↦ { }
</script>

Alternatively, you can also integrate this function individually.

<script type="module">
import {getGlobalObject} from 'https://cdn.jsdelivr.net/npm/@schukai/[email protected]/dist/modules/types/global.mjs';
getGlobalObject('document')
// ↦ { }
</script>
Parameters:
NameTypeDescription
namestring
Since
  • 1.6.0
License
  • AGPLv3
Throws:
  • the object is not defined

    Type
    Error
  • value is not a object

    Type
    TypeError
  • value is not a string

    Type
    TypeError
Returns:
Type: 
objec

(static) isArray(value) → {boolean}

Checks whether the value passed is a array

This method is used in the library to have consistent names.

Checks whether the value passed is a array

This method is used in the library to have consistent names.

Parameters:
NameTypeDescription
value*
Since
  • 1.0.0
License
  • AGPLv3
Returns:
Type: 
boolean
Example
import {isArray} from '@schukai/monster/source/types/is.mjs';

isArray('2')  // ↦ false
isArray([])  // ↦ true

(static) isBoolean(value) → {boolean}

Checks whether the value passed is a boolean.

Checks whether the value passed is a boolean.

This method is used in the library to have consistent names.

Parameters:
NameTypeDescription
value*
Since
  • 1.0.0
License
  • AGPLv3
Returns:
Type: 
boolean
Example
import {isBoolean} from '@schukai/monster/source/types/is.mjs';

isBoolean('2')  // ↦ false
isBoolean([])  // ↦ false
isBoolean(2 > 4)  // ↦ true

(static) isFunction(value) → {boolean}

Checks whether the value passed is a function

This method is used in the library to have consistent names.

Checks whether the value passed is a function

This method is used in the library to have consistent names.

Parameters:
NameTypeDescription
value*
Since
  • 1.0.0
License
  • AGPLv3
Returns:
Type: 
boolean
Example
import {isFunction} from '@schukai/monster/source/types/is.mjs';

isFunction(() => {
}) // ↦ true
isFunction('2')  // ↦ false
isFunction([])  // ↦ false

(static) isInstance(value, instance) → {boolean}

Checks whether the value passed is a object and instance of instance.

Checks whether the value passed is a object and instance of instance.

This method is used in the library to have consistent names.

Parameters:
NameTypeDescription
value*
instance*
Since
  • 1.5.0
License
  • AGPLv3
Returns:
Type: 
boolean
Example
import {isInstance} from '@schukai/monster/source/types/is.mjs';

isInstance('2')  // ↦ false
isInstance([])  // ↦ false

(static) isInteger(value) → {boolean}

Checks whether the value passed is an integer.

Checks whether the value passed is an integer.

This method is used in the library to have consistent names.

Parameters:
NameTypeDescription
value*
Since
  • 1.4.0
License
  • AGPLv3
Returns:
Type: 
boolean
Example
import {isInteger} from '@schukai/monster/source/types/is.mjs';

isInteger(() => {
}) // ↦ true
isInteger('2')  // ↦ false
isInteger(2)  // ↦ true

(static) isIterable(value) → {boolean}

With this function you can check if a value is iterable.

With this function you can check if a value is iterable.

This method is used in the library to have consistent names.

You can call the method via the monster namespace Monster.Types.isPrimitive().

Parameters:
NameTypeDescription
value*
Since
  • 1.2.0
License
  • AGPLv3
Returns:
Type: 
boolean
Example
import {isIterable} from '@schukai/monster/source/types/is.mjs';

isIterable(null)  // ↦ false
isIterable('hello')  // ↦ true
isIterable([])  // ↦ true

(static) isObject(value) → {boolean}

Checks whether the value passed is a object

This method is used in the library to have consistent names.

Checks whether the value passed is a object

This method is used in the library to have consistent names.

Parameters:
NameTypeDescription
value*
Since
  • 1.0.0
License
  • AGPLv3
Returns:
Type: 
boolean
Example
import {isObject} from '@schukai/monster/source/types/is.mjs';

isObject('2')  // ↦ false
isObject([])  // ↦ false

(static) isPrimitive(value) → {boolean}

Checks whether the value passed is a primitive (string, number, boolean, NaN, undefined, null or symbol)

This method is used in the library to have consistent names.

Checks whether the value passed is a primitive (string, number, boolean, NaN, undefined, null or symbol)

This method is used in the library to have consistent names.

Parameters:
NameTypeDescription
value*
Since
  • 1.0.0
License
  • AGPLv3
Returns:
Type: 
boolean
Example
import {isPrimitive} from '@schukai/monster/source/types/is.mjs';

isPrimitive('2') // ↦ true
isPrimitive([])  // ↦ false

(static) isString(value) → {boolean}

Checks whether the value passed is a string

This method is used in the library to have consistent names.

Checks whether the value passed is a string

This method is used in the library to have consistent names.

Parameters:
NameTypeDescription
value*
Since
  • 1.0.0
License
  • AGPLv3
Returns:
Type: 
boolean
Example
import {isString} from '@schukai/monster/source/types/is.mjs';

isString('2')  // ↦ true
isString([])  // ↦ false

(static) isSymbol(value) → {boolean}

Checks whether the value passed is a symbol

This method is used in the library to have consistent names.

Checks whether the value passed is a symbol

This method is used in the library to have consistent names.

Parameters:
NameTypeDescription
value*
Since
  • 1.9.0
License
  • AGPLv3
Returns:
Type: 
boolean
Example
import {isSymbol} from '@schukai/monster/source/types/is.mjs';

isSymbol(Symbol('a'))  // ↦ true
isSymbol([])  // ↦ false

(static) parseDataURL(dataurl) → {Monster.Types.DataUrl}

You can call the function via the monster namespace Monster.Types.parseDataURL().

You can call the function via the monster namespace Monster.Types.parseDataURL().

Specification:

dataurl    := "data:" [ mediatype ] [ ";base64" ] "," data
mediatype  := [ type "/" subtype ] *( ";" parameter )
data       := *urlchar
parameter  := attribute "=" value
Parameters:
NameTypeDescription
dataurlString
Throws:
  • incorrect or missing data protocol

    Type
    TypeError
  • malformed data url

    Type
    TypeError
Returns:
Type: 
Monster.Types.DataUrl

(static) parseMediaType(mediatype) → {Monster.Types.MediaType}

You can call the function via the monster namespace Monster.Types.parseMediaType().

You can call the function via the monster namespace Monster.Types.parseMediaType().

<script type="module">
import {Monster} from '@schukai/monster/source//monster.mjs';
console.log(Monster.Types.parseMediaType())
</script>

Alternatively, you can also integrate this function individually.

<script type="module">
import {parseMediaType} from '@schukai/monster/source/types/dataurl.mjs';
console.log(parseMediaType())
</script>

Specification:

dataurl    := "data:" [ mediatype ] [ ";base64" ] "," data
mediatype  := [ type "/" subtype ] *( ";" parameter )
data       := *urlchar
parameter  := attribute "=" value
Parameters:
NameTypeDescription
mediatypeString
Throws:
  • the mimetype can not be parsed

    Type
    TypeError
  • blank value is not allowed

    Type
    TypeError
  • malformed data url

    Type
    TypeError

(static) toBinary(binary) → {String}

You can call the function via the monster namespace Monster.Types.toBinary().

You can call the function via the monster namespace Monster.Types.toBinary().

Parameters:
NameTypeDescription
binaryString
Since
  • 1.18.0
License
  • AGPLv3
Throws:

value is not a string

Type
TypeError
Returns:
Type: 
String

(static) typeOf(value) → {string}

The built-in typeof method is known to have some historical weaknesses.

The built-in typeof method is known to have some historical weaknesses. This function tries to provide a better and more accurate result.

Parameters:
NameTypeDescription
value*
Since
  • 1.7.0
License
  • AGPLv3
Throws:

value is not a primitive

Type
TypeError
Returns:
Type: 
string
Example
import {typeOf} from '@schukai/monster/source/types/typeof.mjs';

typeOf(undefined); // ↦ undefined
typeOf(""); // ↦ string
typeOf(5); // ↦ number
typeOf({}); // ↦ object
typeOf([]); // ↦ array
typeOf(new Map); // ↦ map
typeOf(true); // ↦ boolean

(static) validateArray(value) → {*}

This method checks if the type matches the array type.

This method checks if the type matches the array type. this function is identical to isArray() except that a TypeError is thrown.

<script type="module">
import {validateArray} from '@schukai/monster/source/types/validate.mjs';
console.log(validateArray('2'))  // ↦ TypeError
console.log(validateArray([]))  // ↦ value
</script>
Parameters:
NameTypeDescription
value*
Since
  • 1.0.0
License
  • AGPLv3
Throws:

value is not an array

Type
TypeError
Returns:
Type: 
*

(static) validateBoolean(value) → {*}

This method checks if the type matches the boolean type.

This method checks if the type matches the boolean type. this function is identical to isBoolean() except that a TypeError is thrown.

<script type="module">
import {validateBoolean} from '@schukai/monster/source/types/validate.mjs';
console.log(validateBoolean(false))  // ↦ value
console.log(validateBoolean('2'))  // ↦ TypeError
console.log(validateBoolean([]))  // ↦ TypeError
</script>
Parameters:
NameTypeDescription
value*
Since
  • 1.0.0
License
  • AGPLv3
Throws:

value is not primitive

Type
TypeError
Returns:
Type: 
*

(static) validateFunction(value) → {*}

This method checks if the type matches the function type.

This method checks if the type matches the function type. this function is identical to isFunction() except that a TypeError is thrown.

<script type="module">
import {validateFunction} from '@schukai/monster/source/types/validate.mjs';
console.log(validateFunction(()=>{})) // ↦ value
console.log(validateFunction('2'))  // ↦ TypeError
console.log(validateFunction([]))  // ↦ TypeError
</script>
Parameters:
NameTypeDescription
value*
Since
  • 1.0.0
License
  • AGPLv3
Throws:

value is not a function

Type
TypeError
Returns:
Type: 
*

(static) validateInstance(value) → {*}

This method checks if the type matches the object instance.

This method checks if the type matches the object instance.

<script type="module">
import {validateInstance} from '@schukai/monster/source/types/validate.mjs';
console.log(validateInstance({}, Object)) // ↦ value
console.log(validateInstance('2', Object)) // ↦ TypeError
console.log(validateInstance([], Object)) // ↦ TypeError
</script>
Parameters:
NameTypeDescription
value*
Since
  • 1.5.0
License
  • AGPLv3
Throws:

value is not an instance of

Type
TypeError
Returns:
Type: 
*

(static) validateInteger(value) → {*}

This method checks if the type is an integer.

This method checks if the type is an integer. this function is identical to isInteger() except that a TypeError is thrown.

<script type="module">
import {validateFunction} from '@schukai/monster/source/types/validate.mjs';
console.log(validateInteger(true)) // ↦ TypeError
console.log(validateInteger('2'))  // ↦ TypeError
console.log(validateInteger(2))  // ↦ value
</script>
Parameters:
NameTypeDescription
value*
Since
  • 1.4.0
License
  • AGPLv3
Throws:

value is not an integer

Type
TypeError
Returns:
Type: 
*

(static) validateIterable(value) → {*}

This method checks if the type matches the primitive type.

This method checks if the type matches the primitive type. this function is identical to isPrimitive() except that a TypeError is thrown.

<script type="module">
import {validateIterable} from '@schukai/monster/source/types/validate.mjs';
console.log(validateIterable('2'))  // ↦ TypeError
console.log(validateIterable([]))  // ↦ value
</script>
Parameters:
NameTypeDescription
value*
Since
  • 1.2.0
License
  • AGPLv3
See
Throws:

value is not a primitive

Type
TypeError
Returns:
Type: 
*

(static) validateObject(value) → {*}

This method checks if the type matches the object type.

This method checks if the type matches the object type. this function is identical to isObject() except that a TypeError is thrown.

<script type="module">
import {validateObject} from '@schukai/monster/source/types/validate.mjs';
console.log(validateObject({}))  // ↦ value
console.log(validateObject('2'))  // ↦ TypeError
console.log(validateObject([]))  // ↦ TypeError
</script>
Parameters:
NameTypeDescription
value*
Since
  • 1.0.0
License
  • AGPLv3
Throws:

value is not a object

Type
TypeError
Returns:
Type: 
*

(static) validatePrimitive(value) → {*}

This method checks if the type matches the primitive type.

This method checks if the type matches the primitive type. this function is identical to isPrimitive() except that a TypeError is thrown.

<script type="module">
import {validatePrimitive} from '@schukai/monster/source/types/validate.mjs';
console.log(validatePrimitive('2'))  // ↦ value
console.log(validatePrimitive([]))  // ↦ TypeError
</script>
Parameters:
NameTypeDescription
value*
Since
  • 1.0.0
License
  • AGPLv3
See
Throws:

value is not a primitive

Type
TypeError
Returns:
Type: 
*

(static) validateString(value) → {*}

This method checks if the type matches the string type.

This method checks if the type matches the string type. this function is identical to isString() except that a TypeError is thrown.

<script type="module">
import {validateString} from '@schukai/monster/source/types/validate.mjs';
console.log(validateString('2'))  // ↦ value
console.log(validateString([]))  // ↦ TypeError
</script>
Parameters:
NameTypeDescription
value*
Since
  • 1.0.0
License
  • AGPLv3
Throws:

value is not a string

Type
TypeError
Returns:
Type: 
*

(static) validateSymbol(value) → {*}

This method checks if the type matches the symbol type.

This method checks if the type matches the symbol type. this function is identical to isSymbol() except that a TypeError is thrown.

<script type="module">
import {validateSymbol} from '@schukai/monster/source/types/validate.mjs';
console.log(validateSymbol('2'))  // ↦ TypeError
console.log(validateSymbol())  // ↦ value
</script>
Parameters:
NameTypeDescription
value*
Since
  • 1.9.0
License
  • AGPLv3
Throws:

value is not an symbol

Type
TypeError
Returns:
Type: 
*

Type Definitions

Parameter

Type:
  • Object
Properties
NameTypeDescription
keystring
valuestring