Origami Frontend Components & Services

JSDoc: o-comment-utilities

padTo2(number)

Global Function

Pad number to 2 characters.

parameter type default description
number Number Number which should be pad to 2 characters.

Returns

  • String | Number - The number in 2 characters.

Links

Config

Global Function

Config class which can be instantiated. It will create an isolated set of configuration options. It can be extended and read.

Returns

  • undefined

Links

get(param)

Global Function

Read the current configuration or a configuration entry

parameter type default description
param string Optional. Entry key of the configuration object. If specified, only the value of the entry is returned.

Returns

  • string | object - Either the value of the key specified or the whole object.

Links

set(keyOrObject, value)

Global Function

Extends the current configuration.

parameter type default description
keyOrObject string | object If a key is specified, then the next parameter (value) will be merged into the current config object. If an object is specified, then the object will be merged into the current config object.
value

Returns

  • undefined

Links

Events

Global Function

When instantiated, it creates an isolated event collection. These events can be handled and triggered using the resulted object.

Returns

  • undefined

Links

on(evt, handler)

Global Function

Registers a new event handler to a specified event which will be called each time the event is triggered.

parameter type default description
evt string Name of the event.
handler function Handler function which will be called when the event is triggered.

Returns

  • undefined

Links

one(evt, handler)

Global Function

Registers a new event handler to a specified event which will be called only the first time the event is triggered.

parameter type default description
evt String Name of the event.
handler function Handler function which will be called when the event is triggered.

Returns

  • undefined

Links

off(evt, handler)

Global Function

Queues off process(es) for the event(s).

parameter type default description
evt string Optional. Name of the event from which the event handler should be removed.
handler function Optional. Handler function to be removed.

Returns

  • undefined

Links

trigger(evt, customData)

Global Function

Queues a trigger process for the event.

parameter type default description
evt string Name of the event which will be triggered.
customData any Optional. Data to be passed to handlers.

Returns

  • undefined

Links

parallel(functions, finalCallback)

Global Function

This submodule is meant to generate a callback only when all functions provided finished their execution. This is achieved by passing a callback as parameter to the functions that are executed.

parameter type default description
functions Object Object with named functions (key-value pairs) that should be executed and synced.
finalCallback function Callback that is called when all functions finished their job. It also gets a parameter which aggregates data from all functions.

Returns

  • undefined

Links

jsonp(options, callback)

Global Function

The actual function which does the jsonp.

parameter type default description
options object Several configuration options (e.g. url, data)
callback function function (err, data)

Returns

  • undefined

Links

param(data)

Global Function

Data object transformation into query string.

parameter type default description
data object Object to be transformed into a query string.

Returns

  • string - Query string.

Links

levelIndex(level)

Global Function

Returns the numeric representation of a string level.

parameter type default description
level string String representation of the log level e.g. warn

Returns

  • number - Numeric representation of the log level e.g. 3

Links

enable

Global Function

Enables the logging.

Returns

  • undefined

Links

disable

Global Function

Disables the logging.

Returns

  • undefined

Links

setLevel(level)

Global Function

Sets the minimum level of log that is considered.

parameter type default description
level number | string Either a numeric (0-4) or string (debug, log, info, warn, error) representation of the level.

Returns

  • undefined

Links

merge(destination, source)

Global Function

Merges two or more objects into a single object. It either overrides if the key is the same, or appends to the existing object. The first parameter is the destination, all the other parameters are the sources. The level of importance increases starting from the destination to the last source (the last source will be the most important).

parameter type default description
destination object The object to which the source objects will be merged
source object Any number of further arguments which are sources and will be merged to the destination.

Returns

  • object - The modified destination object with the sources merged in.

Links

scriptLoader(options, callback)

Global Function

The actual function which does the script loading.

parameter type default description
options object Several configuration options (e.g. url)
callback function function (err)

Returns

  • undefined

Links

StorageWrapper(type)

Global Function

This is a generic wrapper around storage (either localStorage or sessionStorage) which helps storing multiple types of values (not just strings).

parameter type default description
type string Type of the storage to be used. Possible values: - local or localStorage - session or sessionStorage

Returns

  • undefined

Links

setItem(key, value)

Global Function

Sets an item.

parameter type default description
key string The key of the entry.
value string | boolean | date | number | array | object Value which will be stored. The value is serialized when storing the object.

Returns

  • undefined

Links

getItem(key)

Global Function

Reads the item stored with the key. The stored value is unserialized.

parameter type default description
key string The key of the entry

Returns

  • string | boolean | date | number | array | object - Unserialized value

Links

hasItem(key)

Global Function

Checks if there's an entry for the key.

parameter type default description
key string The key of the entry.

Returns

  • Boolean - If it has the item or not.

Links

removeItem(key)

Global Function

Removes the entry that is stored with the key.

parameter type default description
key string The key of the entry.

Returns

  • undefined

Links

clear

Global Function

Clears all entries.

Returns

  • undefined

Links

isLoggedIn

Global Function

Check if the cookies which shows that a user is possibly logged in are set.

Returns

  • Boolean - If the user is logged in or not

Links

getSession

Global Function

Reads the user's session identifier.

Returns

  • String - Session ID

Links

levels

Global Property

Type

  • Array

Levels of logs.

Links

minLevel

Global Property

Type

  • Number

Default level is warn.

Links

enabled

Global Property

Type

  • Boolean

By default it is not enabled.

Links

loggerFunction

Global Property

Function which returns a corresponding wrapper around the native console object. If the console exists, it wraps around it. If it doesn't support calling as a wrapper, it calls directly by stringifying the objects. If the corresponding function of console doesn't exist (e.g. console.debug in IE8), it automatically falls back to the widely available console.log

Links

debug

Global Property

logger.debug, logger function for the debug level.

Links

log

Global Property

logger.log, logger function for the log level.

Links

info

Global Property

logger.info, logger function for the info level.

Links

warn

Global Property

logger.warn, logger function for the warn level.

Links

error

Global Property

logger.error, logger function for the error level.

Links

storageOk

Global Property

Type

  • Boolean

Is storage supported?

Links

native

Global Property

Returns the native storage object.

Links

date.toTimestamp(timestampOrDate)

Static Method

Converts a date in any format to a timestamp in milliseconds.

parameter type default description
timestampOrDate Date | String | Number Can be Date, string which is compatible with the constructor of Date, or a timestamp.

Returns

  • Number - Timestamp in milliseconds

Links

date.toDateObject(timestampOrDate)

Static Method

Converts a date in any format to a JS Date Object.

parameter type default description
timestampOrDate Date | String | Number Can be Date, string which is compatible with the constructor of Date, or a timestamp.

Returns

  • Date - Date object

Links

date.toISOString(timestampOrDate)

Static Method

Shim of Date.toISOString JS function for older browsers. Converts a date to the ISO format.

parameter type default description
timestampOrDate Date | String | Number Can be Date, string which is compatible with the constructor of Date, or a timestamp.

Returns

  • String - Date in ISO format.

Links

Config~config

Inner Property

Type

  • Object

Local object of the configuration.

Links

Events~events

Inner Property

Type

  • Object

Isolated set of events.

Links

Events~getIndexOfHandler(arr, handler)

Inner Function

Helper function to get the index of the handler from the array of handlers attached to an event.

parameter type default description
arr Array Array in which to search.
handler function Handler function which is searched in the Array.

Returns

  • number - Index where the handler was found or -1 if not found.

Links

Events~off(evt, handler)

Inner Function

Removes event handler(s). If there's no parameters, all event handlers are removed. If only the event is specified, all event handlers are removed from that event handler. If an event handler is specified as well, only that specific event handler will be removed.

parameter type default description
evt string Optional. Name of the event from which the event handler should be removed.
handler function Optional. Handler function to be removed.

Returns

  • undefined

Links

Events~trigger(evt, customData)

Inner Function

Triggers an event which causes the call of each handler attached.

parameter type default description
evt string Name of the event which will be triggered.
customData any Optional. Data to be passed to handlers.

Returns

  • undefined

Links

module.exports

Static Property

Type

  • Object

Exports the above defined utility functions.

Links

Switch component view

GitHub Repository

Install o-comment-utilities

If using the Build Service, add o-comment-utilities@^2.4.0 to your script tag.

If running a Manual Build, run bower install --save "o-comment-utilities@^2.4.0".

Help & Support

o-comment-utilities is maintained directly by the Origami team. If you have any questions about o-comment-utilities or Origami in general, we are happy to help. 😊

Slack: #ft-origami
Email: origami.support@ft.com

Feedback / Issues

To report a bug or request features please create an issue on Github. For support or general feedback please get in touch 😊

Slack: #ft-origami
Email: origami.support@ft.com