Module for some common utility functions and references
- Description:
Module for some common utility functions and references
- Source:
Classes
Members
(inner, constant) common
- Source:
(inner, constant) moment
- Source:
Methods
(inner) escape_html_entities(key, value, more) → {any}
- Description:
Escape special characters in the given value, may be nested object
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string | key of the value |
value |
any | value to escape |
more |
boolean | if false, escapes only tags, if true escapes also quotes and ampersands |
Returns:
escaped value
- Type
- any
(inner) getJSON(val) → {object}
- Description:
Check if string is a valid json
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
val |
string | string that might be json encoded |
Returns:
with property data for parsed data and property valid to check if it was valid json encoded string or not
- Type
- object
(inner) isPlainContainer(value) → {boolean}
- Description:
Whether a value is a plain object or an array, and so should be walked rather than escaped as a scalar.
Tested by prototype identity rather than by reading value.constructor.
constructoris an ordinary property name, so a JSON body can carry its own: {"constructor": true, ...} makes value.constructor evaluate to true, which used to fail the check and return the object with its keys and values unescaped. Since escape_html_entities is the replacer for every returnOutput and returnMessage, that turned any user controlled property name into markup wherever a response is rendered.Prototype identity cannot be spoofed by an own property, and it keeps the original intent: ObjectIDs, Dates and other class instances are still escaped as scalars rather than walked.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
value |
Any | value under inspection |
Returns:
true when it should be recursed into
- Type
- boolean
(inner) mergeableKeys(source) → {Array.<string>}
- Description:
Own enumerable keys of a source object that may be used as a field name on a merge target. for...in also yields inherited keys, and a key naming an Object.prototype member resolves to the target's prototype instead of an own slot when the target is indexed with it, so both are removed here once rather than at each operator loop.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
source |
object | object whose keys are about to be walked |
Returns:
keys that are safe to write through
- Type
- Array.<string>
(inner) parseDeclaredStructure(value, type) → {any}
- Description:
Parse a declared Object or Array argument that arrived as its JSON text.
Request parameters are scalars by the time a handler sees them, so a caller that means to send a structure sends its JSON. This lets a declared type accept either form, so an endpoint does not have to parse it itself.
Applied wherever a structure is declared, not only at the literal "Object" and "Array" types: a nested schema declares one too.
Widening only: an argument that was already the declared type is untouched, and text that is not that type still fails the check below.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
value |
any | the argument as supplied |
type |
string | the declared type, "Object" or "Array" |
Returns:
the parsed value, or the original when it does not apply
- Type
- any
(inner) recordMetric(params, metric, props, tmpSet, updateUsersZero, updateUsersMonth)
- Description:
Record specific metric
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
params |
Params | params object |
metric |
string | metric to record |
props |
object | properties of a metric defining how to record it |
tmpSet |
object | object with already set meta properties |
updateUsersZero |
object | object with already set update for zero docs |
updateUsersMonth |
object | object with already set update for months docs |
(inner) recordSegmentMetric(params, metric, name, val, props, tmpSet, updateUsersZero, updateUsersMonth, zeroObjUpdate, monthObjUpdate)
- Description:
Record specific metric segment
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
params |
Params | params object |
metric |
string | metric to record |
name |
string | name of the segment to record |
val |
string | value of the segment to record |
props |
object | properties of a metric defining how to record it |
tmpSet |
object | object with already set meta properties |
updateUsersZero |
object | object with already set update for zero docs |
updateUsersMonth |
object | object with already set update for months docs |
zeroObjUpdate |
Array.<string> | segments to fill for for zero docs |
monthObjUpdate |
Array.<string> | segments to fill for months docs |
(inner) stripPort(ip) → {string}
- Description:
This function takes ipv4 or ipv6 with possible port, removes port information and returns plain ip address
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
ip |
string | ip address to check for port and return plain ip |
Returns:
plain ip address
- Type
- string