Modules Common Library / Utilities
Utilities
Common utility functions that can be used across bundles and tabs
Functions
assertFunctionOfLength()
Call Signature
function assertFunctionOfLength<T>(
f,
l,
func_name,
type_name?,
param_name?): asserts f is T;Defined in: lib/modules-lib/node_modules/js-slang/dist/utils/rttc.d.ts:97
Assertion version of isFunctionOfLength
Type Parameters
| Type Parameter |
|---|
|
Parameters
| Parameter | Type | Description |
|---|---|---|
| (... | Value to validate |
|
| Number of parameters that |
|
| Function within which the validation is occurring |
|
| Optional alias for the function type |
|
| Name of the parameter that's being validated |
Returns
asserts f is T
Call Signature
function assertFunctionOfLength<T>(
f,
l,
func_name,
type_name?,
param_name?): asserts f is FunctionOfLength<T>;Defined in: lib/modules-lib/node_modules/js-slang/dist/utils/rttc.d.ts:98
Assertion version of isFunctionOfLength
Type Parameters
| Type Parameter |
|---|
|
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| Value to validate |
|
| Number of parameters that |
|
| Function within which the validation is occurring |
|
| Optional alias for the function type |
|
| Name of the parameter that's being validated |
Returns
asserts f is FunctionOfLength<T>
assertNumberWithinRange()
Call Signature
function assertNumberWithinRange(
value,
func_name,
min?,
max?,
integer?,
param_name?): asserts value is number;Defined in: lib/modules-lib/node_modules/js-slang/dist/utils/rttc.d.ts:127
Assertion version of isNumberWithinRange
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Returns
asserts value is number
Call Signature
function assertNumberWithinRange(value, options): asserts value is number;Defined in: lib/modules-lib/node_modules/js-slang/dist/utils/rttc.d.ts:128
Assertion version of isNumberWithinRange
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
Returns
asserts value is number
assertTupleOfLength()
Call Signature
function assertTupleOfLength<T, U>(
obj,
l,
func_name,
param_name?): asserts obj is TupleOfLength<T, U>;Defined in: lib/modules-lib/node_modules/js-slang/dist/utils/rttc.d.ts:110
Assertion version of isTupleOfLength
Type Parameters
| Type Parameter |
|---|
|
|
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
|
|
|
|
Returns
asserts obj is TupleOfLength<T, U>
Call Signature
function assertTupleOfLength<T>(
obj,
l,
func_name,
param_name?): asserts obj is TupleOfLength<T>;Defined in: lib/modules-lib/node_modules/js-slang/dist/utils/rttc.d.ts:111
Assertion version of isTupleOfLength
Type Parameters
| Type Parameter |
|---|
|
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
|
|
|
|
Returns
asserts obj is TupleOfLength<T>
callIfFuncAndRightArgs()
function callIfFuncAndRightArgs(
f,
line,
column,
source,
nativeStorage, ...
args): any;Defined in: lib/modules-lib/node_modules/js-slang/dist/utils/operators.d.ts:34
Calls the provided value as if it were a function being called from the line and column within the provided source file, checking for argument count.
- If
nativeStorageis provided, then infinite recursion protection is also added.
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
|
|
|
|
|
|
... |
|
Returns
any
callWithoutMetadata()
function callWithoutMetadata<T>(f, ...args): ReturnType<T>;Defined in: lib/modules-lib/node_modules/js-slang/dist/utils/operators.d.ts:39
Convenience wrapper for callIfFuncAndRightArgs that doesn't require any extra metadata to be passed into the function.
Type Parameters
| Type Parameter |
|---|
|
Parameters
| Parameter | Type |
|---|---|
|
|
... |
|
Returns
ReturnType<T>
degreesToRadians()
function degreesToRadians(degrees): number;Defined in: lib/modules-lib/src/utilities.ts:15
Converts an angle in degrees into radians
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| Angle in degrees |
Returns
number
Angle in radians
hexToColor()
function hexToColor(hex, func_name?): [number, number, number];Defined in: lib/modules-lib/src/utilities.ts:33
Converts a color hex value string to its red, green and blue components, each normalized to between 0 and 1. The leading # is optional.
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
Returns
[number, number, number]
Tuple of three numbers representing the R, G and B components
hueToRgb()
function hueToRgb(hue): [number, number, number];Defined in: lib/modules-lib/src/utilities.ts:60
Converts a hue value in [0,1) into an RGB triple in [0,255].
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| hue around the colour wheel, where 0 and 1 both map to red |
Returns
[number, number, number]
[r, g, b] values between 0 and 255
isFunctionOfLength()
Call Signature
function isFunctionOfLength<T>(f, l): f is T;Defined in: lib/modules-lib/node_modules/js-slang/dist/utils/rttc.d.ts:86
Type guard for checking that the provided value is a function and that it has the specified number of parameters. Of course at runtime parameter types are not checked, so this is only useful when combined with TypeScript types.
Type Parameters
| Type Parameter |
|---|
|
Parameters
| Parameter | Type |
|---|---|
| (... |
|
|
Returns
f is T
Call Signature
function isFunctionOfLength<T>(f, l): f is FunctionOfLength<T>;Defined in: lib/modules-lib/node_modules/js-slang/dist/utils/rttc.d.ts:87
Type guard for checking that the provided value is a function and that it has the specified number of parameters. Of course at runtime parameter types are not checked, so this is only useful when combined with TypeScript types.
Type Parameters
| Type Parameter |
|---|
|
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
Returns
f is FunctionOfLength<T>
isNumberWithinRange()
Call Signature
function isNumberWithinRange(
value,
min?,
max?,
integer?): value is number;Defined in: lib/modules-lib/node_modules/js-slang/dist/utils/rttc.d.ts:118
Function for checking if a given value is a number and that it also potentially satisfies a bunch of other criteria:
- Within a given range of [min, max]
- Is an integer
- Is not NaN
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
|
|
|
|
Returns
value is number
Call Signature
function isNumberWithinRange(value, options): value is number;Defined in: lib/modules-lib/node_modules/js-slang/dist/utils/rttc.d.ts:119
Function for checking if a given value is a number and that it also potentially satisfies a bunch of other criteria:
- Within a given range of [min, max]
- Is an integer
- Is not NaN
Parameters
| Parameter | Type |
|---|---|
|
|
|
Returns
value is number
isTupleOfLength()
Call Signature
function isTupleOfLength<T, U>(obj, l): obj is TupleOfLength<T, U>;Defined in: lib/modules-lib/node_modules/js-slang/dist/utils/rttc.d.ts:103
Function for checking if the given obj is a tuple of the given length. Optionally, providing a type guard function or string can type check the entire tuple.
Type Parameters
| Type Parameter |
|---|
|
|
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
Returns
obj is TupleOfLength<T, U>
Call Signature
function isTupleOfLength<T, U>(
obj,
l,
guard): obj is TupleOfLength<T, U>;Defined in: lib/modules-lib/node_modules/js-slang/dist/utils/rttc.d.ts:104
Function for checking if the given obj is a tuple of the given length. Optionally, providing a type guard function or string can type check the entire tuple.
Type Parameters
| Type Parameter |
|---|
|
|
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
| ( |
Returns
obj is TupleOfLength<T, U>
Call Signature
function isTupleOfLength<T, U>(
obj,
l,
guard): obj is TupleOfLength<T, TypeOfConstantToType<U>>;Defined in: lib/modules-lib/node_modules/js-slang/dist/utils/rttc.d.ts:105
Function for checking if the given obj is a tuple of the given length. Optionally, providing a type guard function or string can type check the entire tuple.
Type Parameters
| Type Parameter |
|---|
|
|
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
|
|
Returns
obj is TupleOfLength<T, TypeOfConstantToType<U>>
Call Signature
function isTupleOfLength<T>(obj, l): obj is TupleOfLength<T>;Defined in: lib/modules-lib/node_modules/js-slang/dist/utils/rttc.d.ts:106
Function for checking if the given obj is a tuple of the given length. Optionally, providing a type guard function or string can type check the entire tuple.
Type Parameters
| Type Parameter |
|---|
|
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
Returns
obj is TupleOfLength<T>
mockDebuggerContext()
function mockDebuggerContext<T>(moduleState, name): DebuggerContext;Defined in: lib/modules-lib/src/utilities.ts:81
Returns a partial DebuggerContext object that contains a context which contains the mocked module state for the given module. Function intended for testing use only.
Type Parameters
| Type Parameter |
|---|
|
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
Returns
radiansToDegrees()
function radiansToDegrees(radians): number;Defined in: lib/modules-lib/src/utilities.ts:24
Converts an angle in radians into degrees
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| Angle in radians |
Returns
number
Angle in degrees
wrapFunction()
Call Signature
function wrapFunction<T, OptArgs>(
f,
optArgCount,
funcName?,
stringified?,
source?): T;Defined in: lib/modules-lib/node_modules/js-slang/dist/utils/operators.d.ts:60
Augment the given function with the necessary information for it to be called properly by callIfFuncAndRightArgs. It won't redefine any existing details that the function has already been wrapped with.
Type Parameters
| Type Parameter |
|---|
|
|
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
|
|
|
|
|
|
Returns
T
Example
export const wrapped = wrap((...args: any[]) => args.length, true, 'wrapped');optArgCount: Represents the number of optional arguments the function has- If set to
undefined, it will be assumed to be 0 - If set to a number, that will be taken to be the number of optional arguments
- If set to
true, the function is assumed to have a rest argument
- If set to
If
stringifiedisundefined, the function won't try to definetoReplString.funcName- If
funcNameisundefined, the function won't try to define thenameproperty. - If
funcNameis provided, thenameproperty will get overriden.
- If
Call Signature
function wrapFunction<T>(
f,
optArgCount,
funcName?,
stringified?,
source?): T;Defined in: lib/modules-lib/node_modules/js-slang/dist/utils/operators.d.ts:61
Augment the given function with the necessary information for it to be called properly by callIfFuncAndRightArgs. It won't redefine any existing details that the function has already been wrapped with.
Type Parameters
| Type Parameter |
|---|
|
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
|
|
|
|
|
|
Returns
T
Example
export const wrapped = wrap((...args: any[]) => args.length, true, 'wrapped');optArgCount: Represents the number of optional arguments the function has- If set to
undefined, it will be assumed to be 0 - If set to a number, that will be taken to be the number of optional arguments
- If set to
true, the function is assumed to have a rest argument
- If set to
If
stringifiedisundefined, the function won't try to definetoReplString.funcName- If
funcNameisundefined, the function won't try to define thenameproperty. - If
funcNameis provided, thenameproperty will get overriden.
- If
Call Signature
function wrapFunction<T>(
f,
optArgCount?,
funcName?,
stringified?,
source?): T;Defined in: lib/modules-lib/node_modules/js-slang/dist/utils/operators.d.ts:62
Augment the given function with the necessary information for it to be called properly by callIfFuncAndRightArgs. It won't redefine any existing details that the function has already been wrapped with.
Type Parameters
| Type Parameter |
|---|
|
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
|
|
|
|
|
|
Returns
T
Example
export const wrapped = wrap((...args: any[]) => args.length, true, 'wrapped');optArgCount: Represents the number of optional arguments the function has- If set to
undefined, it will be assumed to be 0 - If set to a number, that will be taken to be the number of optional arguments
- If set to
true, the function is assumed to have a rest argument
- If set to
If
stringifiedisundefined, the function won't try to definetoReplString.funcName- If
funcNameisundefined, the function won't try to define thenameproperty. - If
funcNameis provided, thenameproperty will get overriden.
- If
wrapFunctionUnsafe()
function wrapFunctionUnsafe<T>(
f,
optArgCount?,
funcName?,
stringified?,
source?): T;Defined in: lib/modules-lib/node_modules/js-slang/dist/utils/operators.d.ts:67
A type-agnostic version of wrap to make it easier when the function type is not known.
Type Parameters
| Type Parameter |
|---|
|
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
|
|
|
|
|
|
Returns
T