Members#

(constant) Level#

Logging levels.

(constant) LogFmt#

Logging formats which are suitable for general messages (usually strings) as 'log', arrays as 'tab' or 'dir' and objects as 'dir'.

Methods#

ctxt(replacePattern, replaceStr, padLen) → {string}#

Gets name of calling function name for logging purposes.

Parameters:
NameTypeDescription
replacePatternRegExp

Pattern to replace from start of function name as it is returned from the stack trace. Default: /http.*/js//

replaceStrstring

Replacement string for pattern from start of function name as it is returned from the stack trace. Default: ''

padLennumber

Length for left-padding function name. Default: 52

Returns:

The caller function name, filtered as specified.

Type: 
string
Example
CODE
// Example import:
import { Level, loggingAt, logging, ctxt, log } from './logging.js';
// Example usage:
LOGLEV = Level.Debug;
function someFunc() {
log(Level.Info, `The current log level is '${LOGLEV}'`, ctxt());
log(Level.Debug, `This is a debugging message`, ctxt());
}
// Specifying non-default args:
// Note: Set args to 'undefined' for default parameter values
const ctxt1 = ctxt(/.*[@].*\/js\//);
const ctxt2 = ctxt(undefined, ':');
const ctxt3 = ctxt(undefined, undefined, 60);

log(level, obj, logCtxt, logFmt)#

Logs the given message at the current global logging level.

Parameters:
NameTypeDescription
levelobject

A valid Level value which is the logging level at which to log this message.

objobject

The object to log at the specified logging level. this would typically be a string (message) but could also be, e.g., an array or class object, particularly if used in conjunction with a non-defualt value for logFmt.

logCtxtstring

The logging context. Can be any string but would usually contain information about the calling function.

logFmtobject

A valid LogFmt value. Valid options: 'log', 'dir', 'tab'. 'log' will log as one of console.log, console.warn or console.error; 'dir' will log as console.dir; 'tab' will log as console.table. Default: 'log'

Example
CODE
LOGLEV = Level.Info;
log(Level.Info, `The current log level is '${LOGLEV}'`, ctxt());
const value = { 1: 'one', 2: 'two', 3: 'three' };
log(Level.Debug, value, ctxt(), 'tab');
log(Level.Debug, value, ctxt(), 'dir');
class Fruit {
constructor(type, colour) {
this.type = type;
this.colour = colour;
}
}
log(Level.Vbose, new Fruit('avo', 'green'), ctxt(), 'dir');

logging() → {boolean}#

Checks if the logging level is enabled, i.e. if it is above 'Level.None'.

Returns:

true if logging is enabled, false if not.

Type: 
boolean
Example
CODE
if (logging()) { log(Level.Info, 'Logging is enabled.'); }

loggingAt(level) → {boolean}#

Checks if the logging level is enabled at or above the specified level.

Parameters:
NameTypeDescription
levelobject

The Level value to check.

Returns:

true if logging is enabled at or above the specified level, false if not.

Type: 
boolean
Example
CODE
if (loggingAt(Level.Info)) { log(Level.Info, 'Logging at info level.'); }
if (loggingAt(Level.Debug)) { log(Level.Info, 'Logging at debug level.'); }

Type Definitions#

Config#

Class to manage static configuration information for the number grid and associated classes.

Type:
  • Object

Dims#

A collection of static functions relating dimensions for NumberGrid.

Type:
  • Object

GridAnimator#

Class to handle grid animation, i.e. the animated 'counting along'.

Type:
  • Object

GridScroller#

Class to handle scrolling of the grid if the animation goes vertically outside of the current viewport.

Type:
  • Object

InputValidator#

Class to handle input validation for the grid configuration.

Type:
  • object
Properties
NameTypeDescription
configColsArray.<object>

An array of HTML elements which are the containers for columns in the config form.

keyOrderArray.<string>

An array of strings which are the HTML id's of the fields to validate.

fieldsArray.<object>

An associative array of HTMLInputElement objects which are the input fields to validate. The keys must match those in keyOrder.

validArray.<object>

An associative array of boolean values, one for each of the input fields to validate, named according to the keys in keyOrder.

MediaHandler#

Class to handle media queries.

Type:
  • Object

NumberGrid#

Class to manage the number grid.

Type:
  • Object

State#

Class to represent possible number grid states.

Type:
  • Object

TitleAnimator#

Class to manage animating the HTML title.

Type:
  • Object