utils

api. utils

Source:
Properties:
Name Type Description
dotProp Object

The dotProp package.

Utilites for any ActionHero project.

Extends

Methods

(static) arrayUniqueify(arr) → {Array}

Source:

Return only the unique values in an Array.

Parameters:
Name Type Description
arr Array

Source Array.

Returns:

Unique Array.

Type
Array

(async, static) asyncWaterfall(jobs) → {Promise.<Array>}

Source:

In series, run an array of async functions

Example
// without arguments
let sleepyFunc = async () => {
  await new Promise((resolve) => { setTimeout(resolve, 100) })
  return (new Date()).getTime()
}

let jobs = [sleepyFunc, sleepyFunc, sleepyFunc]

let responses = await api.utils.asyncWaterfall(jobs)
// responses = [1506536188356, 1506536188456, 1506536188456]

// with arguments
let sleepyFunc = async (response) => {
  await new Promise((resolve) => { setTimeout(resolve, 100) })
  return response
}

let jobs = [
  {method: sleepyFunc, args: ['a']},
  {method: sleepyFunc, args: ['b']},
  {method: sleepyFunc, args: ['c']}
]

let responses = await api.utils.asyncWaterfall(jobs)
// responses = ['a', 'b', 'c']
Parameters:
Name Type Description
jobs Array

Either an array of methods, or an Array of Objects, with method and arg properties.

Returns:

Array of returned values from the methods in jobs

Type
Promise.<Array>

(static) collapseObjectToArray(obj) → {Array}

Source:

Collapsses an Object with numerical keys (like arguments in a function) to an Array

Parameters:
Name Type Description
obj Object

An Object with a depth of 1 and only Numerical keys

Returns:

Array

Type
Array

(static) createDirSafely(dir) → {string}

Source:

Create a directory, only if it doesn't exist yet. Throws an error if the directory already exists, or encounters a filesystem problem.

Parameters:
Name Type Description
dir string

The directory to create.

Returns:

a message if the file was created to log.

Type
string

(static) createFileSafely(file, data, overwrite) → {string}

Source:

Create a file, only if it doesn't exist yet. Throws an error if the file already exists, or encounters a filesystem problem.

Parameters:
Name Type Description
file string

The file to create.

data string

The new contents of the file.

overwrite boolean

Should we overwrite an existing file?.

Returns:

a message if the file was created to log.

Type
string

(static) createLinkfileSafely(filePath, type, refrence) → {string}

Source:

Create an ActionHero LinkFile, only if it doesn't exist yet. Throws an error if the file already exists, or encounters a filesystem problem.

Parameters:
Name Type Description
filePath string

The path of the new LinkFile

type string

What are we linking (actions, tasks, etc).

refrence string

What we are refrencing via this link.

Returns:

a message if the file was created to log.

Type
string

(static) createSymlinkSafely(destination, source) → {string}

Source:

Create a system symbolic link. Throws an error if it encounters a filesystem problem.

Parameters:
Name Type Description
destination string
source string
Returns:

a message if the symlionk was created to log.

Type
string

(static) dirExists(dir) → {Boolean}

Source:

Check if a directory exists.

Parameters:
Name Type Description
dir string

The directory to check.

Returns:
Type
Boolean

(async, static) eventLoopDelay(itterations) → {Promise.<Number>}

Source:

Returns the averge delay between a tick of hte node.js event loop, as measured for N calls of process.nextTick

Parameters:
Name Type Description
itterations Number

How many process.nextTick cycles of the event loop should we measure?

Returns:

Returns the average evnent loop dealy measured in ms.

Type
Promise.<Number>

(static) fileExists(file) → {Boolean}

Source:

Check if a file exists.

Parameters:
Name Type Description
file string

The file to check.

Returns:
Type
Boolean

(static) filterObjectForLogging(params) → {Object}

Source:

Prepares acton params for logging. Hides any sensitieve data as defined by api.config.general.filteredParams Truncates long strings via api.config.logger.maxLogStringLength

Parameters:
Name Type Description
params Object

Params to filter.

Returns:

Filtered Params.

Type
Object

(static) getExternalIPAddress() → {string}

Source:

Returns this server's external/public IP address

Returns:

This server's external IP address.

Type
string

(static) hashMerge(a, b, arg) → {Object}

Source:

Recursivley merge 2 Objects together. Will resolve functions if they are present, unless the parent Object has the propery _toExpand = false. ActionHero uses this internally to construct and resolve the config. Matching keys in B override A.

Parameters:
Name Type Description
a Object

Object 1

b Object

Object 2

arg Object

Arguments to pass to any functiosn which should be resolved.

Returns:

A new Object, combining A and B

Type
Object

(static) parseCookies(req) → {Object}

Source:

Transform the cookie headers of a node HTTP req Object into a hash.

Parameters:
Name Type Description
req Object

A node.js req Object

Returns:

A Object with Cookies.

Type
Object

(static) parseIPv6URI(addr) → {Object}

Source:
See:

Parse an IPv6 address, returning both host and port.

Parameters:
Name Type Description
addr string

An IPv6 address.

Returns:

An Object with {host, port}

Type
Object

(static) removeLinkfileSafely(filePath, type, refrence) → {string}

Source:

Remove an ActionHero LinkFile, only if it exists. Throws an error if the file does not exist, or encounters a filesystem problem.

Parameters:
Name Type Description
filePath string

The path of the LinkFile

type string

What are we linking (actions, tasks, etc).

refrence string

What we are refrencing via this link.

Returns:

a message if the file was created to log.

Type
string

(static) sortGlobalMiddleware(globalMiddlewareList, middleware)

Source:

Sorts an Array of Objects with a priority key

Parameters:
Name Type Description
globalMiddlewareList Array

The Array to sort.

middleware Array

A specific collection to sort against.