UtilityUnit

libflitter/utility/UtilityUnit~ UtilityUnit

The utility unit contains various utility functions and tools that are made available to almost all other units. Currently, a function for restricting console.log calls by logging level is the one method included. Also provides the path to the root folder of the app.


Constructor

new UtilityUnit(app_rootopt)

Instantiate the unit.

Parameters:
Name Type Attributes Default Description
app_root string <optional>
'./app'

path to the 'app' folder

Extends

Members

(static) name

Gets the name of the service provided by this unit: 'utility'

(static) provides

Array of additional service names provided by this unit.

(static) services

Defines the services required by this unit.

(private) _di_allow_defer :boolean

If true, the injector will defer the class if the class requests any services that the container is missing. These services are filled in later and added to the prototype and any instances. True by default.

Type:
  • boolean

(private) _di_deferred_instances :Array.<module:flitter-di/src/Injectable~Injectable>

Collection of instances of this class that need to have the deferred service instances injected into them when the deferred services are finally provided.

(private) _di_deferred_services :Array.<string>

List of services that were deferred and not provided at the time of injection.

Type:
  • Array.<string>

directory :Promise.<void>|Promise.<string>

Fully-qualified path to the 'app' folder.

Type:
  • Promise.<void> | Promise.<string>

services_dir :Promise.<void>|Promise.<string>

Fully-qualified path to the 'app/services' folder.

Type:
  • Promise.<void> | Promise.<string>

Methods

(async) cleanup(app) → {Promise.<void>}

Cleans up the unit's resources before Flitter closes.

Parameters:
Name Type Description
app module:libflitter/app/FlitterApp~FlitterApp

the Flitter app

Returns:
Type
Promise.<void>

deep_copy(item) → {Object}

Make a deep copy of some item. If item is primitive, return it. It item is an array, create a new array with deep copies of each array item. If item is an object, create a new object with key-values such that the keys are the same, but the values are deep copies of the keys.

Assumes items can eventually be resolved to primitive types, and that they contain no circular structure.

Parameters:
Name Type Description
item
Returns:
Type
Object

deep_merge(obj1, obj2) → {*}

Deep merges object 2 into object 1, recursively. This mutates object 1.

Parameters:
Name Type Description
obj1
obj2
Returns:
Type
*

directives() → {Object}

Get the directives provided by this unit.

Returns:
Type
Object

directories() → {Object}

Get the directories managed by this unit. Includes 'root' for the application root.

Returns:
Type
Object

env(name, default_value) → {string|null|boolean|number}

Grabs an environment variable by name and tries to infer its type.

Parameters:
Name Type Description
name string
default_value
Returns:
Type
string | null | boolean | number

(async) go(app, context) → {Promise.<void>}

Loads the unit. Binds the application root and global logging function to the appropriate contexts.

Parameters:
Name Type Description
app module:libflitter/app/FlitterApp~FlitterApp

the Flitter app

context module:libflitter/Context~Context

the unit's context

Returns:
Type
Promise.<void>

infer(val) → {boolean|null|*|number|undefined}

Attempt to infer the variable type of a string's data.

Parameters:
Name Type Description
val string
Returns:
Type
boolean | null | * | number | undefined

is_json(string) → {boolean}

Checks if a string is valid JSON.

Parameters:
Name Type Description
string
Returns:
  • true if the string is valid JSON
Type
boolean

is_linux() → {boolean}

Returns true if the application is running on Linux.

Returns:
Type
boolean

is_mac() → {boolean}

Returns true if the application is running on macOS.

Returns:
Type
boolean

is_windows() → {boolean}

Returns true if the application is running on Windows.

Returns:
Type
boolean

migrations() → {string}

Get the unit's migrations.

Returns:
Type
string

name() → {String}

Get the name of the unit. Should be a lowercase, alphanum/dash/underscore string.

Returns:
Type
String

root() → {string}

Get the fully-qualified path to the root folder of the Flitter application.

Returns:
Type
string

status(setopt) → {string}

Get or set the unit's current status.

Parameters:
Name Type Attributes Description
set string <optional>

if provided, set the status of the unit

Returns:
  • current status of the unit
Type
string