Javascript utilities
This reference covers built-in Javascript utility functions. These functions are available anywhere that Javascript can be used in Sirveo.
Built-in functions are usually implemented because they are either convenient for common needs, or much more performant than pure-javascript alternatives, or because they provide capabilities which are impractical or impossible to implement in pure javascript.
Accessing utility functions
All built-in utility functions are namespaced on a global lib
object, such that they can be accessed with lib.UUID()
, for example.
Utility functions
The following code snippets are for use in JS Code nodes, although the utility functions are available everywhere that javascript is supported in Sirveo.
lib.UUID
Generate a new UUIDv4 value.
Output:
lib.NowISO
Obtain the current timestamp, as an ISO string format, necessarily in UTC.
Output:
lib.NowSec
Obtain the current timestamp, as unix time / unix epoch.
Output:
lib.NowMs
Obtain the current timestamp, as unix time / unix epoch, but with milliseconds.
Output:
lib.SHA256
Obtain the hex-encoded SHA256 digest for the given input. It is recommended to use string inputs.
Output:
lib.Base64Encode
Perform base64 encoding on the input string, as per RFC4648.
The following example demonstrates all base64-related utilities.
Output:
lib.Base64Decode
Decodes a base64 string value. Invalid input results in an empty string.
See example usage.
lib.Base64EncodeUrl
Perform URL-safe base64 encoding on the input string, as per section 5.
See example usage.
lib.Base64DecodeUrl
Decodes a url-safe base64 string value. Invalid input results in an empty string.
See example usage.
Tips
The output of the timestamp-related utility functions will be as accurate as the system clock.