Namespace: Utils

Longo. Utils

Utility methods of Longo.
These methods are also available from application.

Source:

Methods

<static> ab2str(buf) → {String}

Decode Uint16Array to String

Parameters:
Name Type Description
buf Uint16Array

Uint16Array

Source:
See:
Returns:

str decoded string

Type
String

<static> aSlice(arguments) → {Array}

Alias for Array.prototype.slice.apply.

Parameters:
Name Type Description
arguments Object

argument object

Source:
Returns:

result

Type
Array

<static> asNoop() → {function}

return noop as function.

Source:
Returns:

Longo.Utils.noop

Type
function

<static> checkOrElse(val, els, pred) → {Any}

return val if result of input has been evaluated by predictor is truthy else return els

Parameters:
Name Type Description
val Object
els Object
pred function

predictor

Source:
Returns:

result

Type
Any

<static> createLogger(prefix) → {Object}

return prefixed logger.

Parameters:
Name Type Description
prefix prefix
Source:
Returns:

logger

Type
Object

<static> dataFromId(id) → {Date}

Parse id to Date object

Parameters:
Name Type Description
id String

start with timestamp

Source:
Returns:

result

Type
Date

<static> defer(f) → {Promise}

Return promise object

Parameters:
Name Type Description
f function

This function should call done and reject.

Source:
Returns:

promise thenable object

Type
Promise

<static> doWhen(cond, action, values, context) → {Any}

execute action with values when condition is truthy

Parameters:
Name Type Description
cond Boolean
action function
values Array
context Object
Source:
Returns:

result

Type
Any

<static> doWhenOrElse(cond, action, alternative, values, context) → {Any}

execute action with values when condition is truthy else execute alternative

Parameters:
Name Type Description
cond Boolean
action function
alternative function
values Array
context Object
Source:
Returns:

result

Type
Any

<static> existy(val) → {Boolean}

return true if input is not null or undefined.

Parameters:
Name Type Description
val Object
Source:
Returns:

result

Type
Boolean

<static> getOrElse(val, els) → {Any}

return input if input is existy else return els

Parameters:
Name Type Description
val Object
els Object
Source:
Returns:

result

Type
Any

<static> inherits(ctor) → {function}

Browser-friendly inheritance fully compatible with standard node.js inherits
This method have Side-effect

Parameters:
Name Type Description
ctor function

constructor

Source:
See:
Returns:

superCtor constructor of superClass

Type
function

<static> isFalse(val) → {Boolean}

return true if input is the false

Parameters:
Name Type Description
val Object
Source:
Returns:

result

Type
Boolean

<static> isNegativeNum(val) → {Boolean}

return true if input is less than 0

Parameters:
Name Type Description
val Object
Source:
Returns:

result

Type
Boolean

<static> isOne(val) → {Boolean}

return true if input is the 1

Parameters:
Name Type Description
val Object
Source:
Returns:

result

Type
Boolean

<static> isPositiveNum(val) → {Boolean}

return true if input is greater than 0

Parameters:
Name Type Description
val Object
Source:
Returns:

result

Type
Boolean

<static> isTrue(val) → {Boolean}

return true if input is the true

Parameters:
Name Type Description
val Object
Source:
Returns:

result

Type
Boolean

<static> isZero(val) → {Boolean}

return true if input is the 0

Parameters:
Name Type Description
val Object
Source:
Returns:

result

Type
Boolean

<static> noop()

Do nothing

Source:
Returns:

undefined

<static> objectId(id) → {String}

Generate objectId

Parameters:
Name Type Argument Default Description
id String <optional>
null
Source:
Returns:

objectId if id is specified return that id

Type
String

<static> str2ab(str) → {Uint16Array}

Encode String to Uint16Array for zero-copy messageing

Parameters:
Name Type Description
str String

target string

Source:
See:
Returns:

buf encoded Uint16Array

Type
Uint16Array

<static> toArray(val) → {Array}

return input as Array.

Parameters:
Name Type Description
val Object
Source:
Returns:

result

Type
Array

<static> truthy(val) → {Boolean}

return true if input is not null or undefined or false
0, -1, "" is detected as truthy

Parameters:
Name Type Description
val Object
Source:
Returns:

result

Type
Boolean

<static> tryParseJSON(str) → {Array}

Try parse string to JSON object

Parameters:
Name Type Description
str String

JSON formated string

Source:
Returns:

result A Tuple [error, parsed]

Type
Array

<static> uuid() → {String}

Return uuid like random value

Source:
Returns:

uuid uuid like random value

Type
String