API Docs for: 0.8.0
Show:

Util Class

Defined in: include/util.js:29
Module: Services

Provides a set of utility functions used throughout the code base

Item Index

Methods

Properties

Methods

ane

(
  • obj
)
static

Defined in include/util.js:64

Checks if the supplied object is an errof. If the object is an error the function will throw the error.

Parameters:

  • obj Object

    The object to check

arrayPushAll

(
  • from
  • to
)
Boolean static

Defined in include/util.js:434

Pushes all of one array's values into another

Parameters:

  • from Array
  • to Array

Returns:

Boolean:

FALSE when the parameters are not Arrays

arrayToHash

(
  • array
  • [defaultVal=true]
)
Object static

Defined in include/util.js:255

Hashes an array

Parameters:

  • array Array

    The array to hash

  • [defaultVal=true] optional

    Default value if the hashing fails

Returns:

Object:

Hash

arrayToObj

(
  • array
  • keyFieldOrTransform
  • [valFieldOrTransform]
)
Object static

Defined in include/util.js:284

Converts an array to an object.

Parameters:

  • array Array

    The array of items to transform from an array to an object

  • keyFieldOrTransform String | Function

    When this field is a string it is expected that the array contains objects and that the objects contain a property that the string represents. The value of that field will be used as the property name in the new object. When this parameter is a function it is passed two parameters: the array being operated on and the index of the current item. It is expected that the function will return a value representing the key in the new object.

  • [valFieldOrTransform] String | Function optional

    When this value is a string it is expected that the array contains objects and that the objects contain a property that the string represents. The value of that field will be used as the property value in the new object. When this parameter is a function it is passed two parameters: the array being operated on and the index of the current item. It is expected that the function return a value representing the value of the derived property for that item.

Returns:

Object:

The converted array.

cb

() static

Defined in include/util.js:452

Empty callback function just used as a place holder if a callback is required and the result is not needed.

clone

(
  • object
)
Object | Array static

Defined in include/util.js:38

Clones an object by serializing it and then re-parsing it. WARNING: Objects with circular dependencies will cause an error to be thrown.

Parameters:

  • object Object

    The object to clone

Returns:

Object | Array:

Cloned object

copyArray

(
  • array
)
Array static

Defined in include/util.js:410

Clones an array

Parameters:

  • array Array

Returns:

Array:

Cloned array

deepMerge

(
  • from
  • to
)
Object static

Defined in include/util.js:50

Performs a deep merge and returns the result. NOTE: DO NOT ATTEMPT TO MERGE PROPERTIES THAT REFERENCE OTHER PROPERTIES. This could have unintended side-effects as well as cause errors due to circular dependencies.

Parameters:

  • from Object
  • to Object

Returns:

Object:

escapeRegExp

(
  • The
)
String deprecated static

Defined in include/util.js:99

Deprecated: since 0.7.1 Will be removed in 1.0. Use RegExpUtils

Escapes a regular expression.

Parameters:

  • The String

    expression to escape

Returns:

String:

Escaped regular expression.

forEach

(
  • iterable
  • handler
)
static

Defined in include/util.js:223

Provides an implementation of for each that accepts an array or object.

Parameters:

  • iterable Object | Array
  • handler Function

    A function that accepts 4 parameters. The value of the current property or index. The current index (property name if object). The iterable. Finally, the numerical index if the iterable is an object.

getDirectories

(
  • dirPath
  • cb
)
static

Defined in include/util.js:527

Retrieves the subdirectories of a path

Parameters:

  • dirPath String

    The starting path

  • cb Function

    Callback function

getExtension

(
  • filePath
  • [options]
)
String static

Defined in include/util.js:734

Retrieves the extension off of the end of a string that represents a URI to a resource

Parameters:

  • filePath String

    URI to the resource

  • [options] Object optional
    • [lower=false] Boolean optional

      When TRUE the extension will be returned as lower case

    • [sep] String optional

      The file path separator used in the path. Defaults to the OS default.

Returns:

String:

The value after the last '.' character

getFileExtensionFilter

(
  • extension
)
Function static

Defined in include/util.js:772

Creates a filter function to be used with the getFiles function to skip files that are not of the specified type

Parameters:

  • extension Object

Returns:

Function:

getFiles

(
  • dirPath
  • [options]
  • cb
)
static

Defined in include/util.js:566

Retrieves file and/or directorie absolute paths under a given directory path.

Parameters:

  • dirPath String

    The path to the directory to be examined

  • [options] Object optional

    Options that customize the results

    • [recursive=false] Boolean optional

      A flag that indicates if directories should be recursively searched.

    • [filter] Function optional

      A function that returns a boolean indicating if the file should be included in the result set. The function should take two parameters. The first is a string value representing the absolute path of the file. The second is the stat object for the file.

  • cb Function

    A callback that takes two parameters. The first is an Error, if occurred. The second is an array of strings representing the absolute paths for files that met the criteria specified by the filter function.

getTasks

(
  • iterable
  • getTaskFunction
)
static

Defined in include/util.js:141

Creates a set of tasks that can be executed by the "async" module.

Parameters:

  • iterable Array

    The array of items to build tasks for

  • getTaskFunction Function

    The function that creates and returns the task to be executed.

Example:

var items = ['apple', 'orange']; var tasks = util.getTasks(items, function(items, i) { return function(callback) { console.log(items[i]); callback(null, null); }; }); async.series(tasks, util.cb);

hashToArray

(
  • obj
  • [hashKeyProp]
)
Array static

Defined in include/util.js:365

Converts a hash to an array. When provided, the hashKeyProp will be the property name of each object in the array that holds the hash key.

Parameters:

  • obj Object

    The object to convert

  • [hashKeyProp] String optional

    The property name that will hold the hash key.

Returns:

Array:

An array of each property value in the hash.

inherits

(
  • Type1
  • Type2
)
static

Defined in include/util.js:790

Overrides the basic inherit functionality to include static functions and properties of prototypes

Parameters:

  • Type1 Function
  • Type2 Function

initArray

(
  • cnt
  • val
)
Array static

Defined in include/util.js:77

Initializes an array with the specified number of values. The value at each index can be static or a function may be provided. In the event that a function is provided the function will be called for each item to be placed into the array. The return value of the function will be placed into the array.

Parameters:

  • cnt Integer

    The length of the array to create

  • val Function | String | Number

    The value to initialize each index of the array

Returns:

Array:

The initialized array

invertHash

(
  • obj
)
Object static

Defined in include/util.js:389

Inverts a hash

Parameters:

  • obj Object

    Hash object

Returns:

Object:

Inverted hash

isBoolean

(
  • value
)
Boolean static

Defined in include/util.js:516

Tests if a value is a boolean

Parameters:

  • value

Returns:

Boolean:

isFunction

(
  • value
)
Boolean static

Defined in include/util.js:494

Tests if a value is a function

Parameters:

  • value

Returns:

Boolean:

isNullOrUndefined

(
  • value
)
Boolean static

Defined in include/util.js:505

Tests if a value is NULL or undefined

Parameters:

  • value

Returns:

Boolean:

isObject

(
  • value
)
Boolean static

Defined in include/util.js:472

Tests if a value is an object

Parameters:

  • value

Returns:

Boolean:

isString

(
  • value
)
Boolean static

Defined in include/util.js:483

Tests if a value is an string

Parameters:

  • value

Returns:

Boolean:

merge

(
  • from
  • to
)
Object

Defined in include/util.js:111

Merges the properties from the first parameter into the second. This modifies the second parameter instead of creating a new object.

Parameters:

  • from Object
  • to Object

Returns:

Object:

The 'to' variable

mkdirsSync

(
  • absoluteDirPath
  • isFileName
)
static

Defined in include/util.js:700

Synchronously makes the specified directory structure.

Parameters:

  • absoluteDirPath String

    The absolute path of the directory structure to be created

  • isFileName Boolean

    When true the value after the last file separator is treated as a file. This means that a directory with that value will not be created.

objArrayToHash

(
  • array
  • hashProp
)
Object static

Defined in include/util.js:342

Converts an array of objects into a hash where the key the value of the specified property. If multiple objects in the array have the same value for the specified value then the last one found will be kept.

Parameters:

  • array Array

    The array to convert

  • hashProp String

    The property who's value will be used as the key for each object in the array.

Returns:

Object:

A hash of the values in the array

union

() Object static

Defined in include/util.js:127

Creates an object that has both the properties of "a" and "b". When both objects have a property with the same name, "b"'s value will be preserved.

Returns:

Object:

The union of properties from both a and b.

uniqueId

() String static

Defined in include/util.js:462

Creates a unique Id

Returns:

String:

Unique Id Object

wrapTask

(
  • context
  • func
  • [argArray]
)
Function static

Defined in include/util.js:168

Wraps a function in an anonymous function. The wrapper function will call the wrapped function with the provided context. This comes in handy when creating your own task arrays in conjunction with the async function when a prototype function needs to be called with a specific context.

Parameters:

  • context

    The value of "this" for the function to be called

  • func Function

    The function to be executed

  • [argArray] Array optional

    The arguments to be supplied to the func parameter when executed.

Returns:

Function:

wrapTimedTask

(
  • context
  • func
  • [name]
  • [argArray]
)
Function static

Defined in include/util.js:191

Wraps a task in a context as well as a function to mark the start and end time. The result of the task will be provided in the callback as the "result" property of the result object. The time of execution can be found as the "time" property.

Parameters:

  • context

    The value of "this" for the function to be called

  • func Function

    The function to be executed

  • [name] String optional

    The task's name

  • [argArray] Array optional

    The arguments to be supplied to the func parameter when executed.

Returns:

Function:

Properties

TIME

Object static

Defined in include/util.js:807

Provides typical conversions for time