Registers the methods of the module utils in microTasks.
Copy a list of values from and to payload.
Name | Type | Default | Description |
---|---|---|---|
definition | object |
{} |
to: from object list |
Example
microTasks.taskRun([{
method: 'utils.copy',
params: { 'newUserId': 'user.id', 'newUserAge': 'user.age' }
}],
{
user: { id: 123, age: 18 } // payload
})
// payload = { user: { id: 123, age: 18 }, newUserId: 123, newUserAge: 18 }
Run a lodash method.
Name | Type | Description |
---|---|---|
method | string |
Name of lodash method. |
args | * |
Method arguments |
Example
microTasks.taskRun([{
method: 'utils.lodash',
params: ['map', [1, 2], (item) => item * 2],
resultPath: 'result'
}])
// payload = { result: [2, 4] }
Set defaultValue if value is undefined
Name | Type | Description |
---|---|---|
key | string |
Key to set |
defaultValue | * |
Value to set |
Example
microTasks.taskRun([{
method: 'utils.default',
params: ['foo', 123]
}])
Returns the processing time of a task
Name | Type | Description |
---|---|---|
payload | object |
Payload of the task |
Example
microTasks.methodRun('utils.getTaskTime', payload)
// 145 milliseconds
Returns a replaced string.
Name | Type | Description |
---|---|---|
str | string |
Source string |
substr | string |
A string that is to be replaced by replacement |
replacement | string |
The String that replaces the substr |
Example
microTasks.taskRun([{
method: 'utils.replace',
params: ['foo', 'o', 'a'],
resultPath: 'newString'
}])
// payload.newString = 'faa'
Set a value in payload.
Name | Type | Description |
---|---|---|
to | string |
destination path in payload |
from | * |
source value in payload |
Example
microTasks.taskRun([{
method: 'utils.set',
params: ['foo', true]
}])
// payload.foo = true
Returns the size of a value.
Name | Type | Description |
---|---|---|
Value | * |
value to get size |
Example
microTasks.taskRun([{
method: 'utils.size',
params: [[1, 2]],
resultPath: 'size'
}])
// payload.size = 2
Wait for time
milliseconds before resolving the action.
Name | Type | Description |
---|---|---|
time | number |
time to wait |
Example
microTasks.taskRun([{
method: 'utils.wait',
params: 10000 // 10 seconds
}])