Skip to content

Latest commit

 

History

History
166 lines (130 loc) · 3.78 KB

utils.md

File metadata and controls

166 lines (130 loc) · 3.78 KB

utils

Registers the methods of the module utils in microTasks.

utils~utils.copy(definition)

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 }

utils~utils.lodash(method, args)

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] }

utils~utils.default(key, defaultValue)

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]
}])

utils~utils.getTaskTime(payload)

Returns the processing time of a task

Name Type Description
payload object Payload of the task

Example

microTasks.methodRun('utils.getTaskTime', payload)
// 145 milliseconds

utils~utils.replace(str, substr, replacement)

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'

utils~utils.set(to, from)

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

utils~utils.size(Value)

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

utils~utils.wait(time)

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
}])