new Resolve()
- Source:
Members
(static) numberRegex :RegExp
Gets a regular expression that can be used to match valid integers,
floats and floats in scientific notation.
Type:
- RegExp
- Source:
Methods
(static) asNumber(value) → {Number|BigInt}
Attempts conversion of a number in a string to a native number.
Parameters:
Name | Type | Description |
---|---|---|
value |
String | A number (as int, float or scientific notation) to be parsed to a native Number object. Also supports the literal 'NaN'. |
- Source:
Throws:
-
if the value cannot be parsed as a number.
- Type
- Error
Returns:
the value parsed as Number.
- Type
- Number | BigInt
(async, static) asyncFuncOrPromise(asyncFuncOrPromise) → {T}
Parameters:
Name | Type | Description |
---|---|---|
asyncFuncOrPromise |
producerHandler.<(T|Promise.<T>)> | Promise.<T> | An (async) function or a Promise. |
- Source:
- See:
Returns:
The result of deeply resolving the given function or Promise.
- Type
- T
(static) isFunction(value) → {Boolean}
Parameters:
Name | Type | Description |
---|---|---|
value |
any | function | AsyncFunction |
- Source:
Returns:
true, iff the given value is an (async) function
- Type
- Boolean
(static) isNumber(value) → {Boolean}
Parameters:
Name | Type | Description |
---|---|---|
value |
any | Number |
- Source:
Returns:
true, iff the given number or NaN is of type Number
- Type
- Boolean
(static) isPrimitive(value) → {Boolean}
Parameters:
Name | Type | Description |
---|---|---|
value |
any |
- Source:
Returns:
true, iff the value is primitive
- Type
- Boolean
(static) isPromise(value) → {Boolean}
Parameters:
Name | Type | Description |
---|---|---|
value |
any | Promise |
- Source:
Returns:
true, iff the value is an instance of Promise
- Type
- Boolean
(static) isSymbol(value) → {Boolean}
Parameters:
Name | Type | Description |
---|---|---|
value |
Symbol |
- Source:
Returns:
- Type
- Boolean
(static) isTypeOf(value, exampleOrTypeOrClassName) → {Boolean}
Check whether or not a value is of a specific type, that can be given
as an example, an actual Type/Class or the name of a class.
Parameters:
Name | Type | Description |
---|---|---|
value |
any | the value to check |
exampleOrTypeOrClassName |
any | String | an examplary other value you'd expect, a type (e.g. RegExp) or class or the name of a class or c'tor-function. |
- Source:
Returns:
- Type
- Boolean
(async, static) optionalToValue() → {T}
Similar to @see {toValue}, this method returns the default value for the given
value, should it be undefined. Other than that, this method returns the same as
- Source:
- See:
-
- {toValue}.
- {toValue}
Returns:
the resolved-to value or its default, should it be undefined.
- Type
- T
(async, static) toValue(value, exampleOrTypeOrClassNameopt, resolveFuncsopt, resolvePromisesopt) → {T}
Resolve a literal value, a function or Promise to a value. If enabled, deeply
resolves functions or Promises. Attempts to resolve (to a) value until it matches
the expected example, type/class or class name.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
value |
any | T | producerHandler.<T> | Promise.<T> | a literal value or an (async) function or Promise that may produce a value of the expected type or exemplary value. | ||
exampleOrTypeOrClassName |
any | string | T |
<optional> |
Optional. If not given, will only resolve functions and promises to a value that is not a function and not a Promise. Otherwise, pass in an examplary other value you'd expect, a type (e.g. RegExp) or class or the name of a class or c'tor-function. | |
resolveFuncs |
Boolean |
<optional> |
true | Optional. Defaults to true. If true, then functions will be called and their return value will be checked against the expected type or exemplary value. Note that this parameter applies recursively, until a function's returned value no longer is a function. |
resolvePromises |
Boolean |
<optional> |
true | Optional. Defaults to true. If true, then Promises will be awaited and their resolved value will be checked against the expected type or exemplary value. Note that this parameter applies recursively, until a Promise's resolved value no longer is a Promise. |
- Source:
- See:
Throws:
-
if the value cannot be resolved to the expected type or exemplary value.
- Type
- Error
Returns:
the resolved-to value
- Type
- T
(static) tryAsNumber(value) → {T|String|Number|BigInt}
Attempts conversion of a value to number, iff it is a valid number. Otherwise
returns the value as is. Uses @see {asNumber}.
Parameters:
Name | Type | Description |
---|---|---|
value |
T | String | Number | BigInt | A value that is checked for whether it is a valid number or not. If the value is already a Number, it is returned as is. If it is a String, it is attempted to parse. Should that fail, the value is returned as is. If the value is not a Number and not a String, it is also returned as is. |
- Source:
Returns:
- Type
- T | String | Number | BigInt