Class: Transformer

Transformer

Useful Transformations for CloudEvent objects. Note that all methods here are static, so no need to instance this class; see it as an Utility/Companion class.
Source:
Throws:
instancing not allowed for this class
Type
Error

Members

(static, readonly) timezoneOffsetMsec :number

Utility variable that returns the timezone offset value, in msec.

Utility variable that returns the timezone offset value, in msec.
Type:
  • number
Source:

Methods

(static) dumpObject(obj, nameopt) → {string}

Utility function that return a dump of the given object.

Utility function that return a dump of the given object.
Parameters:
Name Type Attributes Default Description
obj object | Map | Set the object to dump
name string <optional>
'noname' the name to assign in the returned string, or 'noname' as default value
Source:
Returns:
the dump of the object or a message when obj is undefined/null/not an object
Type
string

(static) errorToData(errnon-null, optionsopt) → {object}

Utility function that map an Error into an object (compatible with the CloudEvent standard), to fill its 'data' attribute.

Utility function that map an Error into an object (compatible with the CloudEvent standard), to fill its 'data' attribute.
Parameters:
Name Type Attributes Default Description
err Error the Error to transform
options object <optional>
{} transformation options: - includeStackTrace flag (default false) to add the StackTrace into the object to return, - addStatus flag (default true) to add a 'status' attribute into the object to return, - addTimestamp flag (default false) to add the current 'timestamp' as attribute into the object to return,
Source:
Throws:
if err is undefined or null, or is not an Error instance
Type
TypeError
Returns:
the object representation of the error
Type
object

(static) mergeObjects(basenon-null, …others) → {object}

Utility function that merge the given objects (at least one base and another) and returns the new one (but with the prototype of the first).

Utility function that merge the given objects (at least one base and another) and returns the new one (but with the prototype of the first).
Parameters:
Name Type Attributes Description
base object the first object to merge
others object <repeatable>
all other(s) object to merge (at least one)
Source:
Throws:
if base is undefined or null, or is not an object
Type
TypeError
Returns:
the new object
Type
object

(static) processInfoToData() → {object}

Utility function that get some process-related info and wrap into an object (compatible with the CloudEvent standard), to fill its 'data' attribute.

Utility function that get some process-related info and wrap into an object (compatible with the CloudEvent standard), to fill its 'data' attribute.
Source:
Returns:
the object representation of process-related info data
Type
object

(static) stringFromBase64(objnullable) → {string}

Utility function that decodes a base64 string into a normal string using 'utf8' encoding (compatible with the CloudEvent standard).

Utility function that decodes a base64 string into a normal string using 'utf8' encoding (compatible with the CloudEvent standard).
Parameters:
Name Type Attributes Description
obj string <nullable>
the string to decode, or '' if not defined or null
Source:
Throws:
if str is not a string instance
Type
TypeError
Returns:
the string decoded from base64
Type
string

(static) stringToBase64(objnullable) → {string}

Utility function that encodes a string in base64 (compatible with the CloudEvent standard).

Utility function that encodes a string in base64 (compatible with the CloudEvent standard).
Parameters:
Name Type Attributes Description
obj string <nullable>
the string to encode, or '' if not defined or null
Source:
Throws:
if str is not a string instance
Type
TypeError
Returns:
the string encoded in base64
Type
string

(static) timestampFromNumber(objnon-null, timezoneOffsetopt) → {object}

Utility function that parse a number representation of the given timestamp (Date) and returns it (if possible).

Utility function that parse a number representation of the given timestamp (Date) and returns it (if possible). Note that the value returned could be adjusted with the current timezone offset.
Parameters:
Name Type Attributes Default Description
obj number the timestamp/date to parse (as a number)
timezoneOffset number <optional>
0 a timezone offset to add (in msec, default 0)
Source:
Throws:
if obj is undefined or null, or is not a number
Type
TypeError
Returns:
the parsed version, as a timestamp (Date) object, if possible
Type
object

(static) timestampFromString(objnon-null, timezoneOffsetopt) → {object}

Utility function that parse a string representation (compatible with the CloudEvent standard) of the given timestamp (Date) and returns it (if possible).

Utility function that parse a string representation (compatible with the CloudEvent standard) of the given timestamp (Date) and returns it (if possible). Note that the value returned could be adjusted with the current timezone offset.
Parameters:
Name Type Attributes Default Description
obj string the timestamp/date to parse (as a string)
timezoneOffset number <optional>
0 a timezone offset to add (in msec, default 0)
Source:
Throws:
if obj is undefined or null, or is not a string
Type
TypeError
Returns:
the parsed version, as a timestamp (Date) object, if possible
Type
object

(static) timestampToNumber(objnullable) → {number}

Utility function that return a number representation of the given timestamp (Date), or the current one will be used.

Utility function that return a number representation of the given timestamp (Date), or the current one will be used. Note that the value returned is in the UTC format.
Parameters:
Name Type Attributes Description
obj object <nullable>
the timestamp/date to convert, or the current one if not defined or null
Source:
Throws:
if obj is not a Date instance
Type
TypeError
Returns:
the number representation of the object
Type
number

(static) timestampToString(objnullable) → {string}

Utility function that return a string representation (compatible with the CloudEvent standard) of the given timestamp (Date), or the current one will be used.

Utility function that return a string representation (compatible with the CloudEvent standard) of the given timestamp (Date), or the current one will be used. Note that the value returned is in the UTC format.
Parameters:
Name Type Attributes Description
obj object <nullable>
the timestamp/date to convert, or the current one if not defined or null
Source:
Throws:
if obj is undefined or null, or is not a Date instance
Type
TypeError
Returns:
the string representation of the object
Type
string

(static) uriStripArguments(urlnon-null, optionsopt) → {string}

Utility function that strip all arguments (if any) from the given URI/URL string and returns the string without them.

Utility function that strip all arguments (if any) from the given URI/URL string and returns the string without them.
Parameters:
Name Type Attributes Default Description
url string the URI/URL (as a string)
options object <optional>
{} containing: strict (boolean, default false) to check it in a more strict way
Source:
Throws:
if url is undefined or null, or is not a string
Type
TypeError
Returns:
the parsed version, but without arguments (if any)
Type
string