API Docs for: 2.0.0

Class node-utils

Class defined in: src/node-utils.js:11

Provides utility functions for the SAGE2 server

checkPackages( inDevelopement )
src/node-utils.js:394

Compare the installed pacakges versus the specified ones in packages.json warms the user of outdated packages

Parameters:
  • inDevelopement <Bool>

    whether or not to check in production mode (no devel packages)

compareFilename( a, b )
src/node-utils.js:327

Utility function, used while sorting, to compare two objects based on filename independently of case. Needs a .exif.FileName field

Parameters:
compareString( a, b )
src/node-utils.js:307

Utility function to compare two strings independently of case. Used for sorting

Parameters:
compareTitle( a, b )
src/node-utils.js:347

Utility function to compare two objects based on title independently of case. Needs a .exif.metadata.title field Used for sorting

Parameters:
deleteFiles( pattern, cb )
src/node-utils.js:644

Delete files, with glob, and a callback when done

Parameters:
deregisterSAGE2( config, callback )
src/node-utils.js:469

Unregister from EVL server

Parameters:
  • config <Object>

    local SAGE2 configuration

  • callback <Function>

    to be called when done

String encodeReservedPath( aUrl )
src/node-utils.js:505

Return a safe URL string: make Windows path to URL

Parameters:
  • aUrl <String>

    URL to be sanitized


Returns: <String>

cleanup version of the URL

String encodeReservedURL( aUrl )
src/node-utils.js:492

Return a safe URL string: convert odd characters to HTML representations

Parameters:
  • aUrl <String>

    URL to be sanitized


Returns: <String>

cleanup version of the URL

Bool fileExists( filename )
src/node-utils.js:69

Test if file is exists

Parameters:
  • filename <String>

    name of the file to be tested


Returns: <Bool>

true if exists

Bool folderExists( directory )
src/node-utils.js:89

Test if folder is exists

Parameters:
  • directory <String>

    name of the folder to be tested


Returns: <Bool>

true if exists

getFullVersion( callback )
src/node-utils.js:187

Full version is processed from git information

Parameters:
  • callback <Function>

    function to be run when finished, parameter is an object containing base, branch, commit and date fields

String getHomeDirectory( )
src/node-utils.js:517

Return a home directory on every platform


Returns: <String>

string representing a folder path

String getNodeVersion( )
src/node-utils.js:176

Node.js version


Returns: <String>

version number

String getShortVersion( )
src/node-utils.js:161

Base version comes from evaluating the package.json file


Returns: <String>

version number as x.x.x

String header( h )
src/node-utils.js:273

Utility function to create a header for console messages

Parameters:
Returns: <String>

header formatted text

isTrue( value )
src/node-utils.js:368

Utility function to test if a string or number represents a true value. Used for parsing JSON values

Parameters:
  • value <Object>

    value to test

Array loadCABundle( filename )
src/node-utils.js:129

Load a CA bundle file and return an array of certificates

Parameters:
  • filename <String>

    name of the file to parse


Returns: <Array>

array of certificates data

log( head, params )
src/node-utils.js:287

Log function for SAGE2, adds a header with color

Parameters:
  • head <String>

    The header

  • params <Array>

    The parameters

Boolean mergeObjects( a, b, ignore )
src/node-utils.js:613

Merges object a and b into b

Parameters:
  • a <Object>

    source object

  • b <Object>

    destination

  • ignore <Array>

    object fields to ignore during merge


Returns: <Boolean>

return true if b was modified

String mkdirParent( dirPath )
src/node-utils.js:528

Creates recursively a series of folders if needed (synchronous function and throws error)

Parameters:
  • dirPath <String>

    path to be created


Returns: <String>

null or directory created

monitorFolders( folders, excludesFiles, excludesFolders, callback )
src/node-utils.js:567

Place a callback on a list of folders to monitor callback triggered when a change is detected: this.root contains the monitored folder parameter contains the following list: addedFiles, modifiedFiles, removedFiles, addedFolders, modifiedFolders, removedFolders

Parameters:
  • folders <Array>

    list of folders to monitor

  • excludesFiles <Array>

    The excludes files

  • excludesFolders <Array>

    The excludes folders

  • callback <Function>

    to be called when a change is detected

registerSAGE2( config )
src/node-utils.js:450

Register SAGE2 with EVL server

Parameters:
  • config <Object>

    local SAGE2 configuration

String sanitizedURL( aURL )
src/node-utils.js:254

Cleanup URL from XSS attempts

Parameters:
  • aURL <String>

    a URL we received from a request


Returns: <String>

cleanup string

Object secureContext( key, crt, ca )
src/node-utils.js:109

Create a SSL context / credentials

Parameters:
Returns: <Object>

secure context

updateWithGIT( branch, callback )
src/node-utils.js:233

Upate the source code using git

Parameters:
  • branch <String>

    name of the remote branch

  • callback <Function>

    function to be run when finished

_NODE_VERSION <Number>
src/node-utils.js:47

Parse and store NodeJS version number: detect version 0.10.x or newer