Utility methods of Longo.
These methods are also available from application.
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
Returns:
result
- Type
- Array
-
<static> asNoop() → {function}
-
return noop as function.
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
Returns:
result
- Type
- Any
-
<static> createLogger(prefix) → {Object}
-
return prefixed logger.
Parameters:
Name Type Description prefix
prefix Returns:
logger
- Type
- Object
-
<static> dataFromId(id) → {Date}
-
Parse id to
Date
objectParameters:
Name Type Description id
String start with timestamp
Returns:
result
- Type
- Date
-
<static> defer(f) → {Promise}
-
Return promise object
Parameters:
Name Type Description f
function This function should call
done
andreject
.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 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 Returns:
result
- Type
- Any
-
<static> existy(val) → {Boolean}
-
return true if input is not
null
orundefined
.Parameters:
Name Type Description val
Object 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 Returns:
result
- Type
- Any
-
<static> inherits(ctor) → {function}
-
Browser-friendly inheritance fully compatible with standard node.js inherits
This method have Side-effectParameters:
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 Returns:
result
- Type
- Boolean
-
<static> isNegativeNum(val) → {Boolean}
-
return true if input is less than 0
Parameters:
Name Type Description val
Object Returns:
result
- Type
- Boolean
-
<static> isOne(val) → {Boolean}
-
return true if input is the 1
Parameters:
Name Type Description val
Object Returns:
result
- Type
- Boolean
-
<static> isPositiveNum(val) → {Boolean}
-
return true if input is greater than 0
Parameters:
Name Type Description val
Object Returns:
result
- Type
- Boolean
-
<static> isTrue(val) → {Boolean}
-
return true if input is the
true
Parameters:
Name Type Description val
Object Returns:
result
- Type
- Boolean
-
<static> isZero(val) → {Boolean}
-
return true if input is the 0
Parameters:
Name Type Description val
Object Returns:
result
- Type
- Boolean
-
<static> noop()
-
Do nothing
Returns:
undefined
-
<static> objectId(id) → {String}
-
Generate objectId
Parameters:
Name Type Argument Default Description id
String <optional>
null 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 Returns:
result
- Type
- Array
-
<static> truthy(val) → {Boolean}
-
return true if input is not
null
orundefined
orfalse
0
,-1
,""
is detected as truthyParameters:
Name Type Description val
Object Returns:
result
- Type
- Boolean
-
<static> tryParseJSON(str) → {Array}
-
Try parse string to JSON object
Parameters:
Name Type Description str
String JSON formated string
Returns:
result A Tuple
[error, parsed]
- Type
- Array
-
<static> uuid() → {String}
-
Return uuid like random value
Returns:
uuid uuid like random value
- Type
- String