new Resolve()
- Source:
Members
(static) numberBinaryRegex :RegExp
Gets a regular expression that can be used to match valid integers,
in binary notation (base 2). Integers can be BigInts.
Type:
- RegExp
- Source:
(static) numberHexRegex :RegExp
Gets a regular expression that can be used to match valid integers,
in hexadecimal notation (base 16). Integers can be BigInts.
Type:
- RegExp
- Source:
(static) numberOctalRegex :RegExp
Gets a regular expression that can be used to match valid integers,
in octal notation (base 8). Integers can be BigInts.
Type:
- RegExp
- Source:
(static) numberRegex :RegExp
Gets a regular expression that can be used to match valid integers,
floats and floats in scientific notation. Integers are only recognized
if they are in Base 10 (i.e., not binary, octal or hexadecimal; you will
have to use the other regexes for that).
Type:
- RegExp
- Source:
Methods
(static) asNumber(value) → {Number|BigInt}
Attempts conversion of a number in a string to a native number. Supports
literal integers and floats, also in scientific notation. Also supports
integers in literal base 2 (binary), 8 (octal) and 16 (hex) notation.
Integers can be BigInts (ending in n).
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. Also throws an error if a literal integer in base 2, 8 or 16 is attempted to be converted to BigInt, in cases where it is larger than @see {Number.MAX_SAFE_INTEGER}.
- 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, tryConvertopt) → {Boolean}
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
value |
any | Number | |||
tryConvert |
Boolean |
<optional> |
false | Optional. Default false. Whether to attempt converting the given value to Number. Returns true should that succeed. |
- Source:
Returns:
true, iff the given number or NaN is of type Number,
or if it was requested to be converted and that conversion succeeded.
- 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