Expression Library Starter Pack

Download Link
Shared Libraries.zip (4.8 KB)

Description:
These expression files have been created as examples for integration professionals and/or convenience functions for citizen developers. The expression files can be included at the organization’s root-level shared folder or project-space shared folder for ease of use. The included pipeline provides simple examples for many of the functions contained in these libraries.

Samples:
lib.string.lpad(‘123’, 5, ‘0’) yields “00123”
lib.date.fromEpoch(1234567890) yields “2009-02-13T23:31:30.000 UTC”
lib.date.trunc(Date.now(), ‘HH’) yields current date/time truncated to hour

Release used: master-7317 - 4.21 GA

=============================================================

date.expr

Many new customers struggle with date manipulation in JavaScript. This expression library was created to provide some of the functionality they may see as “missing” in JavaScript.

Static Variables

Two static variables are defined:

  • timezone - The timezone to be used by the functions in this expression library if a timezone is not provided. This should be set using the appropriate timezone values for Date.toLocaleDateTimeString function
  • defaultFormat - The format string to be used by the functions in this expression library if a format string is not provided

Functions

  • format (Date[, FormatString[, TimeZone]]) - format a Date object, returned as a String
    • If FormatString is not specified, “defaultFormat” provided in the Static Variables section will be used
    • If TimeZone is not specified, “timezone” provided in the Static Variables section will be used
  • firstDayOfMonth (Date) - return a Date object for the first day of the month from the Date object specified
  • lastDayOfMonth (Date) - return a Date object for the last day of the month from the Date object specified
  • toEpoch (Date) - return a BigInt value representing the epoch time (number of seconds since 1-Jan-1970) from the Date object specified
  • fromEpoch (seconds) - return a Date object calculated from the epoch time specified
  • getAge (Date, AsOfDate) - return an integer value representing the difference in years between AsOfDate and Date specified
    • If AsOfDate is not specified, current date/time is used
  • segmentHour (Date, numSegments) - return a Date object where the Minutes value has been set according to the number of segments specified.
    • For example, if numSegments is 4 the minutes returned will be 00, 15, 30, 45; if numSegments is 6 the minutes returned will be 00, 10, 20, 30, 40, 50
    • Note that the minutes value is truncated (not rounded) to the segment, so a numSegments of 4:
      • Minutes 0-14 → 00
      • Minutes 15-29 → 15
      • Minutes 30-44 → 30
      • Minutes 45-59 → 45
  • trunc (Date[, FormatString) - return a Date object that has been truncated based on the desired format
    • Valid FormatString values:
      • yyyy - truncate to year
      • MM - truncate to month
      • dd - truncate to day
      • HH - truncate to hour
      • mm - truncate to minute
      • ss - truncate to second

string.expr

Many new customers struggle with formatting strings for specific purposes. This expression library was created to provide some of the functionality they may see as “missing” in JavaScript.

Functions

  • lpad (String, size[, fill-character]) - return a String value that has been left-padded to the specified size, using the fill-character specified
    • Default fill character is space
    • String will be truncated to “size” if original string is longer
  • rpad (String, size[, fill-character]) - return a String value that has been right-padded to the specified size, using the fill-character specified
    • Default fill character is space
    • String will be truncated to “size” if original string is longer
  • objectToKeyValuePairs (Object[, key/value separator[, data separator[, encode]]]) - return a String that contains key/value pairs joined from all fields in an object
    • If “key/value separator” is not specified, default value colon “:” is used
    • If “data separator” is not specified, default value comma “,” is used
    • If “encode” is set to true, each data value will be passed through encodeURIComponent
  • keyValuePairsToObject (String[, key/value separator[, data separator[, decode]]]) - return an Object parsed from the key/value pairs String
    • If “key/value separator” is not specified, default value colon “:” is used
    • If “data separator” is not specified, default value comma “,” is used
    • If “decode” is set to true, each data value will be passed through decodeURIComponent
  • flattenObject (Object, SubObjectName) - return a new object with the members of SubObjectName merged into Object; useful for flattening data after a Lookup or other snaps that move data into “original”
  • numberWithCommas (Number[, Precision]) - return a String that is formatted from the specified Number, placing a comma “,” character at every 3rd position
    • Decimal values are not formatted but will be rounded to the requested precision
  • bytesToFileSize (Bytes[, Precision]) - convert a number that represents a file size in bytes to a human readable (concise) format up to YottaByte notation

xml.expr

The XML Generator does not handle incoming data that is not XML-safe. This expression library provides simple functions to encode and decode String values.

Functions

  • encode (String) - return a String that has replaced all occurrences of XML special characters with appropriate escape-sequence strings
  • decode (String) - return a String that has replaced all occurrences of XML escape-string sequences with equivalent symbols
3 Likes