ow.format

ow.format.addNumberSeparator

ow.format.addNumberSeparator(aNumber, aSeparator) : String

Returns a formatted number with decimal separators (default is comma but you can provide a custom aSeparator).
(available after ow.loadFormat())

ow.format.bool

ow.format.bool(aBoolValue, isLight, anExtra) : String

Given aBoolValue will return a green checkmark or a red cross character. If necessary anExtra ansiColor attributes can be added.

ow.format.cron.howManyAgo

ow.format.cron.howManyAgo(aCron, lastUpdate, aLimit) : Map

Given aCron expression and a date/unix time of a lastUpdate will return a map with a boolean isDelayed, number of  ms delayedAtLeast, if delayed howManyAgo executions missed and the corresponding missed executions dates in missedTimes. When calculating the missed times there is aLimit (defaults to 100).

ow.format.cron.isCronMatch

ow.format.cron.isCronMatch(aDate, aCronExpression) : boolean

Returns trues if the provided aDate is a match for the provided aCronExpression. Otherwise returns false.

ow.format.cron.nextScheduled

ow.format.cron.nextScheduled(expr, count, start, end) : Date

Given a cron expr returns the next Date object when it will occur. If count > 1 it will provide an array of Dates with the next n Dates. If start and end Date are defined they will limit the range on which to provide dates.

ow.format.cron.parse

ow.format.cron.parse(aCronExpression) : Map

Parses aCronExpression and produces a Map with a schedules array and a exceptions array (if any error is found). Each schedules array item map has a key with all the number possibilities for the given aCronExpression provided:

s - seconds (0-59)
m - minutes (0-59)
h - hours (0-23)
D - month day (1-31)
M - month (1-12)
d - week day (1-7)

Example:

ow.format.cron.parse("0 5 * * *"); // 5am


ow.format.cron.prevScheduled

ow.format.cron.prevScheduled(expr, count, start, end) : Date

Given a cron expr returns the previous Date object when it will occur. If count > 1 it will provide an array of Dates with the previous n Dates. If start and end Date are defined they will limit the range on which to provide dates.

ow.format.cron.set2LocalTime

ow.format.cron.set2LocalTime()

Sets the default system-wide cron expression evaluation to the local time (default is UTC).

ow.format.cron.set2UTC

ow.format.cron.set2UTC()

Sets the default system-wide cron expression evaluation to UTC (the default).

ow.format.cron.sleepUntilNext

ow.format.cron.sleepUntilNext(expr)

Sleeps until the cron expr is expected to be true.

ow.format.cron.timeUntilNext

ow.format.cron.timeUntilNext(expr) : Number

Returns a number of ms until the cron expr is expected to be true.

ow.format.dateDiff.inDays

ow.format.dateDiff.inDays(dateBefore, dateAfter, shouldRound) : Number

Difference between dateAfter and dateBefore in days. If shouldRound = true will round from the previous time unit.

ow.format.dateDiff.inHours

ow.format.dateDiff.inHours(dateBefore, dateAfter, shouldRound) : Number

Difference between dateAfter and dateBefore in hours.  If shouldRound = true will round from the previous time unit.

ow.format.dateDiff.inMinutes

ow.format.dateDiff.inMinutes(dateBefore, dateAfter, shouldRound) : Number

Difference between dateAfter and dateBefore in minutes. If shouldRound = true will round from the previous time unit.

ow.format.dateDiff.inMonths

ow.format.dateDiff.inMonths(dateBefore, dateAfter) : Number

Difference between dateAfter and dateBefore in months.

ow.format.dateDiff.inSeconds

ow.format.dateDiff.inSeconds(dateBefore, dateAfter, shouldRound) : Number

Difference between dateAfter and dateBefore in seconds. If shouldRound = true will round from the previous time unit.

ow.format.dateDiff.inWeeks

ow.format.dateDiff.inWeeks(dateBefore, dateAfter, shouldRound) : Number

Difference between dateAfter and dateBefore in weeks. If shouldRound = true will round from the previous time unit.

ow.format.dateDiff.inYears

ow.format.dateDiff.inYears(dateBefore, dateAfter) : Number

Difference between dateAfter and dateBefore in years.

ow.format.dateTimeTransition

ow.format.dateTimeTransition(aZone, aDate) : Map

Given aZone (defaults to Europe/London) and aDate (defaults to now) will return a map with the previous  and next date/time transition.

ow.format.dateTimeZones

ow.format.dateTimeZones() : Array

List all available Java zone ids.

ow.format.elapsedTime

ow.format.elapsedTime(aStartTime, aEndTime, aFormat) : String

Shortcut for ow.format.elapsedTime4ms calculating the absolute difference, in ms, between aStartTime and aEndTime.

ow.format.elapsedTime4ms

ow.format.elapsedTime4ms(aMs, aFormat) : String

Given aMs (milleseconds) will convert into a string with the corresponding human-readable time and date components up to years. This is usually helpful when comparing dates (see also ow.format.elapsedTime). You can control the output format by adding options to aFormat:

Example:

aFormat = {
   full : false, // when true outputs everything even if it's 0 value
   abrev: false, // when true outputs smaller "1h2m3s" instead of "1 hour, 2 minutes and 3 seconds"
   pad  : false, // when true pads values with 0 on the left
   colon: false, // when true outputs just values separated by ":"
   sep  : ", ",  // customizes the values separator, defaults to ", " or "" (in case of abrev = true)
   maxLeft : 7,  // the maximum number of time units to show counting from the left
   maxRight: 7   // the maximum number of time units to show counting from the right
}

ow.format.escapeHTML

ow.format.escapeHTML(aString) : String

Will escape, and return, aString for HTML/XML special characters.
(available after ow.loadFormat())

ow.format.escapeHTML4

ow.format.escapeHTML4(aString) : String

Uses Apache Commons Lang escape HTML4 functionality to convert aString into HTML4 entities where needed.

ow.format.escapeRE

ow.format.escapeRE(aString) : String

Tries to escape in aString all characters that make up a RegExp.

ow.format.escapeString

ow.format.escapeString(aString, aExceptString) : String

Will escape, and return, aString for RegExp special characters with the exception of any characters in aExceptString.
(available after ow.loadFormat())

ow.format.fromBase16

ow.format.fromBase16(aString) : bytes

Given a base 16 aString transforms it back to the original array of bytes.

ow.format.fromBase32

ow.format.fromBase32(aString) : bytes

Given a base 32 aString transforms it back to the original array of bytes.

ow.format.fromBase36

ow.format.fromBase36(aString) : Number

Converts a provided base36 aString into the corresponding number.

ow.format.fromBinary

ow.format.fromBinary(aString) : Number

Converts a provided binary aString into the decimal number.

ow.format.fromByte

ow.format.fromByte(aByte) : Number

Converts a byte info a decimal number.

ow.format.fromBytesAbbreviation

ow.format.fromBytesAbbreviation(aStr, useDecimal) : Number

Tries to reverse the ow.format.toBytesAbbreviation from aStr (string) back to the original value in bytes. Use useDecimal=true to interpret KB as 1000 instead of 1024 (see more in https://en.wikipedia.org/wiki/Byte#Multiple-byte_units)
(available after ow.loadFormat())

ow.format.fromDate

ow.format.fromDate(aDate, aFormat, aTimeZone) : String

Will convert a javascript aDate into a String representation given aFormat:

  G - Era descriptor (AD)
  y - Year (1996; 96)
  Y - Week year (2009; 09)
  M - Month in year (July; Jul; 07)
  w - Week in year (27)
  W - Week in month (2)
  D - Day in year (189)
  d - Day in month (10)
  F - Day of week in month (2)
  E - Day name in week (Tuesday; Tue)
  u - Day number of week (1 = Monday, ..., 7 = Sunday) (1)
  a - Am/pm number (PM)
  H - Hour in day (0-23)
  k - Hour in day (1-24)
  K - Hour in am/pm (0-11)
  h - Hour in am/pm (1-12)
  m - Minute in hour (30)
  s - Second in minute (55)
  S - Millisecond (978)
  z - Time zone (Pacific Standard Time; PST; GMT-08:00)
  Z - Time zone (-0800)
  X - Time zone (-08; -0800; -08:00)

Optionally you can also provide aTimeZone (like 'America/New_York', 'Europe/London', 'UTC', ...)

(available after ow.loadFormat())

ow.format.fromHex

ow.format.fromHex(aString) : Number

Converts a provided hexadecimal aString into the decimal number.

ow.format.fromLDAPDate

ow.format.fromLDAPDate(aLDAPDate) : Date

Converts a numeric aLDAPDate (also known as Windows NT time format, Active Directory timestamps) into a javascript Date.

ow.format.fromOctal

ow.format.fromOctal(aString) : Number

Converts a provided octal aString into the decimal number.

ow.format.fromSIAbbreviation

ow.format.fromSIAbbreviation(aString) : Number

Converts the provided string using SI notationp prefix (do previously make the necessary conversions: 5mV -> 5m, 5cm -> 5c, 9km -> 9k) to the corresponding number. Uses the current approved SI prefix list (https://en.wikipedia.org/wiki/Metric_prefix)

ow.format.fromTimeAbbreviation

ow.format.fromTimeAbbreviation(aStr) : Number

From aStr time abbreviation (e.g. 1h2m3s (1 hour, 2 minutes and 3 seconds)) will return the corresponding amount of time in ms.

ow.format.fromUnixDate

ow.format.fromUnixDate(aUnixDate) : Date

Converts aUnixDate timestamp into a javascript Date.

ow.format.fromWedoDate

ow.format.fromWedoDate(aWedoDate, aFormat) : String

Shortcut for ow.format.fromDate but using a wedo date. See ow.format.fromDate for more help.  
(available after ow.loadFormat())

ow.format.fromWedoDateToDate

ow.format.fromWedoDateToDate(aWedoDate) : Date

Returns a date object from a wedo date. (available after ow.loadFormat())

ow.format.getActualTime

ow.format.getActualTime(useAlternative) : Date

Retrieves the current actual time from worldtimeapi.org (through https). The current actual time will be returned in a Date. If useAlternative = true it will use worldclockapi.com (through http)

ow.format.getClasspath

ow.format.getClasspath() : String

Returns the current java classpath.

ow.format.getCurrentDirectory

ow.format.getCurrentDirectory() : String

Returns the current working directory.

ow.format.getDoH

ow.format.getDoH(aAddr, aType, aProvider) : Array

Performs a DNS over HTTPs query with aAddr. Optionally you can provide the aType of record (defaults to 'a') and the DNS over HTTPs aProvider between 'google' and 'cloudflare'.

ow.format.getHostAddress

ow.format.getHostAddress() : String

Returns the current host ip address.

ow.format.getHostName

ow.format.getHostName() : String

Returns the current hostname.

ow.format.getJavaHome

ow.format.getJavaHome() : String

Returns the current java home directory.

ow.format.getJavaVersion

ow.format.getJavaVersion() : String

Returns the current java version.

ow.format.getOS

ow.format.getOS() : String

Returns the current operating system identifier string.

ow.format.getOSArch

ow.format.getOSArch() : String

Returns the current operating system architecture string.

ow.format.getOSVersion

ow.format.getOSVersion() : String

Returns the current operating system version string.

ow.format.getPublicIP

ow.format.getPublicIP() : Map

Uses the functionality provided by http://ifconfig.co to return a map with the apparent current public ip address, public hostname and a guess of country and city. Please be aware of the request limits of the service (around 1 request per minute).

ow.format.getReverseDoH

ow.format.getReverseDoH(aIP, aProvider) : Array

Tries to retrieve the reverse DNS of aIP using DNS over HTTPs. Optionally you can choose the aProvider between 'google' and 'cloudflare'.

ow.format.getTLSCertificates

ow.format.getTLSCertificates(aHost, aPort, withJava, aPath, aPass, aSoTimeout) : Array

Tries to retreive the TLS certificates from aHost, aPort (defaults to 443). Optionally if withJava=true the original certificate Java object will also be included. If the CA certificates is in a different location you can provide aPath and the corresponding aPass. Additionally you can specificy aSoTimeout (socket timeout in ms) which defaults to 10s.

ow.format.getTmpDir

ow.format.getTmpDir() : String

Returns the current temporary directory.

ow.format.getUserHome

ow.format.getUserHome() : String

Returns the current user home path.

ow.format.getUserName

ow.format.getUserName() : String

Returns the current user name.

ow.format.int2IP

ow.format.int2IP(aIPInt) : String

Converts the decimal IP address representation aIPInt into an IP address.

ow.format.IP2Int

ow.format.IP2Int(aIP) : String

Converts an IP address into it's decimal IP address representation.

ow.format.isEmail

ow.format.isEmail(aEmail) : boolean

Tries to determine if aEmail seems a syntactic valid email.

ow.format.isHost

ow.format.isHost(aHost) : boolean

Tries to determine if aHost seems a syntactic valid host.

ow.format.isIPv4

ow.format.isIPv4(aIP) : boolean

Tries to determine if aIP is a syntactic valid IPv4.

ow.format.isIPv6

ow.format.isIPv6(aIP) : boolean

Tries to determine if aIP is a syntactic valid IPv6.

ow.format.isURL

ow.format.isURL(aURL) : boolean

Tries to determine if aURL seems a syntactic valid URL.

ow.format.isWedoDate

ow.format.isWedoDate(aWedoDate) : boolean

Determines if the aWedoDate object is a wedo date type (returns true if yes, false otherwise).  
(available after ow.loadFormat())

ow.format.isWindows

ow.format.isWindows() : Boolean

Returns true if the operating system is identified as Windows otherwise returns false.

ow.format.logErrWithFooter

ow.format.logErrWithFooter(aMessage, aFooter)

Equivalent to ow.format.printWithFooter (see help ow.format.printWithFooter) using the logErr function.

ow.format.logErrWithProgressFooter

ow.format.logErrWithProgressFooter(aMessage, aTemplate, aPerc, aSize, aUnixBlock, aWindowsBlock, aSpace)

Equivalent to ow.format.printWithProgressFooter (see help ow.format.printWithProgressFooter) using the logErr function.

ow.format.logWarnWithFooter

ow.format.logWarnWithFooter(aMessage, aFooter)

Equivalent to ow.format.printWithFooter (see help ow.format.printWithFooter) using the logWarn function.

ow.format.logWarnWithProgressFooter

ow.format.logWarnWithProgressFooter(aMessage, aTemplate, aPerc, aSize, aUnixBlock, aWindowsBlock, aSpace)

Equivalent to ow.format.printWithProgressFooter (see help ow.format.printWithProgressFooter) using the logWarn function.

ow.format.logWithFooter

ow.format.logWithFooter(aMessage, aFooter)

Equivalent to ow.format.printWithFooter (see help ow.format.printWithFooter) using the log function.

ow.format.logWithProgressFooter

ow.format.logWithProgressFooter(aMessage, aTemplate, aPerc, aSize, aUnixBlock, aWindowsBlock, aSpace)

Equivalent to ow.format.printWithProgressFooter (see help ow.format.printWithProgressFooter) using the log function.

ow.format.logWithWaiting

ow.format.logWithWaiting(aMainFunc, aPrefixMsg, aCompleteMsg, aErrorMsg, aWaitSpeed, aTheme)

Executes aMainFunc while log aPrefixMsg with a waiting aTheme (defaults to a sequence of chars with a rotating bar). When aMainFunc ends it will replace the log with aCompleteMsg or aErrorMsg in case an exception is thrown. Optionally you can provide a different aWaitSpeed while cycling between the aTheme sequence of chars increasing/decreasing the "animation" effect.

ow.format.percentile

ow.format.percentile(aArray, aPercentile) : Number

Will return the percentile (aPercentile between 0 and 1) for the provided aArray of numbers.

ow.format.percProgressReport

ow.format.percProgressReport(aMainFunc, aProgressFunc, aTimeout)

Percentage progress report help function over a function on aMainFunc calling aProgressFunc in parallel with a percentage function parameter (receiving target and source numbers). You can also provide an alternative aTimeout between aProgressFunc calls (defaults to 150ms).

Example:

ow.format.percProgressReport(() => {
   ioStreamCopy(io.writeFileStream("target.file"), io.readFileStream("source.file"));
}, (percFunc) => {
	  var perc = percFunc(io.fileInfo("target.file").size, io.fileInfo("source.file").size);
   ...
});


ow.format.printWithFooter

ow.format.printWithFooter(aMessage, aFooter)

Prints aMessage (if defined) with a aTemplate (template compiled function or string).

ow.format.printWithProgressFooter

ow.format.printWithProgressFooter(aMessage, aTemplate, aPerc, aSize, aUnixBlock, aWindowsBlock, aSpace)

Prints aMessage (if defined) with a aTemplate (template compiled function or string) as a footer for percentage  progress information with the percentage value aPerc, for a given optional aSize (defaults to 50), an optional  aUnixBlock or aWindowsBlock (depending on the current operating system) and aSpace. Example:

   ow.loadTemplate();
   var fn = ow.template.execCompiled(ow.template.compile("(%) progress: ||"));
   ow.format.printWithProgressFooter("processing xyz...", fn, aPerc);
   ow.format.printWithFooter("Done.", "");

ow.format.printWithWaiting

ow.format.printWithWaiting(aMainFunc, aPrefixMsg, aCompleteMsg, aErrorMsg, aWaitSpeed, aTheme, printNLFn, useAsSuffix)

Executes aMainFunc while priting aPrefixMsg with a waiting aTheme (defaults to a sequence of chars with a rotating bar). When aMainFunc ends it will replace the priting with aCompleteMsg or aErrorMsg in case an exception is thrown. Optionally you can provide a different aWaitSpeed while cycling between the aTheme sequence of chars increasing/decreasing the "animation" effect.

ow.format.progressReport

ow.format.progressReport(aMainFunc, aProgressFunc, aTimeout)

Executes aMainFunc to execute some synchronous function while aProgressFunc is called asynchronously to  keep track of progress. You can also provide an alternative aTimeout between aProgressFunc calls (defaults to 150ms).

ow.format.round

ow.format.round(aNumber, aDigits) : String

Will return aNumber rounded to 0 decimal digits or aDigits decimal digits.
(available after ow.loadFormat())

ow.format.sshProgress

ow.format.sshProgress(aFn) : Object

Returns a SSH Java progress monitor callback object to be use with the SSH plugin functions. Expects callback aFn that will be called with state (e.g. begin, count, end) and an Info map. The Info map is composed of:    source - the reported source of the transfer
   target - the reported target of the transfer
   op     - the operation being performed (get or put)
   start  - reported unix epoch when the transfer started
   end    - reported unix epoch when the transfer stopped
   count  - the last reported byte count
   speed  - the calculated speed of transfer

If the returned value is false the transfer will be cancelled.

ow.format.streamHandle

ow.format.streamHandle(aHandle, inHandle, errHandle, outHandle, bufferSize) : Function

Returns a function to help automated interaction with a running process. The function aHandle receives: aType (in/err); aTxt,  inHandle (function), errHandle (function) and an outHandle (function). Optionally you can provide an alternative inHandle function to print stdout text, an errHandle function to print stderr text, an outHandle function to send text to stdin and/or a non default bufferSize.

Example:

var res = $sh("myProcess.sh --something")
          .cb(expect((aType, aTxt, inHandle, errHandle, outHandle) => {
             if (aType == "in") {
                inHandle(aTxt)
                if (/ name\?/.test(aTxt))                return outHandle("Scott\n")
               if (aTxt.indexOf("Anything else?") >= 0) return outHandle("nope!\n")
             }
          }))
          .get(0)


ow.format.streamSH

ow.format.streamSH(aFunction, anEncoding) : Function

To be used with sh, af.sh or ssh.exec as the callbackFunc. Returns a function that will call aFunction for each line and used the returned string with print and printErr.

ow.format.streamSHLog

ow.format.streamSHLog(aFunction) : Function

To be used with sh, af.sh or ssh.exec as the callbackFunc. Returns a function that will call aFunction for each line and used the returned string with log and logErr.

ow.format.streamSHPrefix

ow.format.streamSHPrefix(aPrefix, anEncoding, aSeparator, aTemplate, aFnHandler) : Function

To be used with sh, af.sh or ssh.exec as the callbackFunc. Returns a function that will prefix each line with aPrefix and used the returned string with print and printErr. Optionally you can provide aTemplate to add "prefix" (defaults to "[]") and/or provide aFnHandler to chain another streaming handling function (receives a stream and a boolean to indicate if its stdout or stderr)

ow.format.string.ansiMoveDown

ow.format.string.ansiMoveDown(nLines)

Moves the cursor nLines down.

ow.format.string.ansiMoveLeft

ow.format.string.ansiMoveLeft(nChars)

Moves the cursor left chars.

ow.format.string.ansiMoveRight

ow.format.string.ansiMoveRight(nChars)

Moves the cursor right chars.

ow.format.string.ansiMoveUp

ow.format.string.ansiMoveUp(nLines)

Moves the cursor nLines up.

ow.format.string.ansiScrollDown

ow.format.string.ansiScrollDown(nLines)

Scrolls the screen down by nLines.

ow.format.string.ansiScrollUp

ow.format.string.ansiScrollUp(nLines)

Scrolls the screen up by nLines.

ow.format.string.bestPrefix

ow.format.string.bestPrefix(aString, anArrayOfStrings) : aString

Given anArrayOfStrings will try to find the best prefix string on that array for the provided aString. See ow.format.string.closest if you don't want to be based on the prefix.
Example:
var anArrayOfStrings = [ "/user", "/use", "/username", "/u" ];
ow.format.string.bestPrefix("/user/1", anArrayOfStrings); // Returns /user
ow.format.string.bestPrefix("/u1", anArrayOfStrings); // Returns /u
ow.format.string.bestPrefix("/userna", anArrayOfStrings); // Returns /user


ow.format.string.bool

ow.format.string.bool(aBoolValue, isLight, anExtra) : String

Given aBoolValue will return a green checkmark or a red cross character. If necessary anExtra ansiColor attributes can be added.

ow.format.string.chart

ow.format.string.chart(aName, aDataPoint, aHSIze, aVSize, aMin, aMax, aTheme) : String

Given data aName will store, between calls, aDataPoint provided to plot a chart with a horizontal aHSize and a vertical aVSize. Optionally aMin value and aMax value can be provided. aTheme can optionally also be provided containing the map entries space (char), bar (char), point (char), vertical (boolean) and axis (boolean)

ow.format.string.closest

ow.format.string.closest(aString, anArrayOfStrings, aThreshold) : aString

Given anArrayOfStrings will try to find the closest string on that array for the provided aString. If aThreshold is not provided a default value of 3 will be used. See ow.format.string.bestPrefix if you want to be based on the prefix.
Example:
var anArrayOfStrings = [ "/user", "/use", "/username", "/u" ];
ow.format.string.closest("/user/1", anArrayOfStrings); // Returns /user
ow.format.string.closest("/u1", anArrayOfStrings); // Returns /u
ow.format.string.closest("/userna", anArrayOfStrings); // Returns /user
ow.format.string.closest("/usernam", anArrayOfStrings); // Returns /username

ow.format.string.dataClean

ow.format.string.dataClean(aName)

Given aName for data points entered using ow.format.string.chart and ow.format.string.dataLineChart will effectively delete all cached data. If aName is not provided it will eliminate of cached data.

ow.format.string.dataLineChart

ow.format.string.dataLineChart(aName, aDataPoint, aHSIze, aVSize, aOptions) : String

Given data aName will store, between calls, aDataPoint (number or array of numbers) provided to plot a line chart with a horizontal aHSize and a vertical aVSize. Optionally aOptions, equivalent to ow.format.string.lineChart options, can optionally also be provided.

ow.format.string.distance

ow.format.string.distance(aStringA, aStringB, maxOffset) : Number

Calculates the distance between aStringA and aStringB into the number of inserts, deletions and updates needed. If the maxOffset is not provided a value of 5 maximum characters difference will be  used. (Currently based on Sift4)

ow.format.string.genPass

ow.format.string.genPass(aSize, aSets, aExclude, aWeights) : String

Tries to generate a random password with aSize (defaults to 12) optionally given an array of aSets (between lowercase, uppercase, numbers, symbols and symbols2) and also aExclude a string of characters given an optional percentage of aWeights probability for each aSets.

ow.format.string.getAstralCodePoint

ow.format.string.getAstralCodePoint(aHighSurrogate, aLowSurrogate) : Number

Given a 8-bit aHighSurrogate code and a 8-bit aLowSurogate code returns a 16-bit unicode code

ow.format.string.getSurrogatePair

ow.format.string.getSurrogatePair(astralCodePoint) : Array

Returns an array of two 8 bit codes given an unicode astralCodePoint of 16 bits

ow.format.string.grid

ow.format.string.grid(aMatrix, aX, aY, aBgPattern, shouldReturn) : String

Will generate a aX per aY grid to be displayed with aBgPattern (defaults to " "). Each grid cell with use the contents on aMatrix array of an array. Each cell content can be a map with obj (a Map), a xspan/yspan for in cell spacing, a type (either map, table, chart, area, bar, func or string)  and a title. If shouldReturn = true it will just return the string content instead of trying to print it.
Extra options per type:

 chart: the 'obj' check printChart format string
 bar  : the 'obj' check printBar format stirng; 'max'; 'min'; 'indicator'; 'space'


ow.format.string.leftPad

ow.format.string.leftPad(aString, length, padExpression) : String

Using a padExpression will left pad aString for the given length.

ow.format.string.lineChart

ow.format.string.lineChart(aSeries, aOptions) : String

Given an array of values (1 series) or an array of arrays of values (multiple series) will plot a line chart in  ascii, with the provided aOptions, a return the corresponding string. Available options:

  min     (number)   The minimum value to use in the chart
  max     (number)   The maximum value to use in the chart
  height  (number)   The line chart lines height to use
  width   (number)   The maxium width of the line chart
  colors  (array)    Array of color names to use for each series
  label   (boolean)  Boolean value to indicate if y labels should be included (default true)
  format  (function) Custom functions that receives a value and returns a formatted string for labels
  dColor  (string)   The default color to use
  offset  (number)   The offset to assume (default 2)
  padding (string)   The chart padding string (default "")
  fixed   (number)   If no custom format function is provided will be the fixed decimals to use (default 2)
  symbols (array)    An array of 10 characters to replace the default symbols

ow.format.string.lineChartLegend

ow.format.string.lineChartLegend(titles, options) : Array

Given an array of titles and the options provided to ow.format.string.lineChart will return an array with each "symbol" and color used for each series and the corresponding "title".

ow.format.string.lsHash

ow.format.string.lsHash(aStringA, aStringB, dontCareDiffSize) : String

Generates a locality sensitive hash for aStringA. If aStringB is provided it will compute the  hash difference between aStringA and aStringB returning a number (if 0 means the strings are almost identical; if 200 or higher means the strings are very different). Optionally you can indicate that the difference should care about differences in size dontCareDiffSize = true. This is based on https://github.com/trendmicro/tlsh/blob/master/js_ext.

Note: A aStringA and aStringB should be, at least, 512 characters long and have enough randomness to  generate a proper hash.

ow.format.string.lsHashDiff

ow.format.string.lsHashDiff(aHashA, aHashB, dontCareDiffSize) : String

From a previously created, with ow.format.string.lsHash, aHashA and aHashB will calculate  the difference between them returning a number (if 0 means the strings are almost identical; if 200 or higher means the strings are very different). Optionally you can indicate that the difference should care about differences in size dontCareDiffSize = true. This is based on https://github.com/trendmicro/tlsh/blob/master/js_ext.

ow.format.string.nLinesTemplate

ow.format.string.nLinesTemplate(aSourceTemplate, initMap, alternativeTemplate, alternativePrintFunction) : Function

Returns a function to print multiple lines at the same time (using ansi cursor up). The function accepts a map parameter since it's based on the aSourceTemplate (handlebars). The initial render is performed using initMap. If ansi support is not  available and if alternativeTemplate is defined (and different of "" otherwise it defaults to aSourceTemplate) it will use it as alternative. Optionally it's also possible to define a different print function (alternativePrintFunction) to print (like log, for example).

ow.format.string.pauseString

ow.format.string.pauseString(aString, aMsg)

Given aString starts an interactive paging of the contents of aString.  Optionally aMsg can be provided to be displayed with the paging percentage (use \ to be replaced by the percentage).

ow.format.string.printable

ow.format.string.printable(aByteArray, aDefaultChar) : String

Tries to convert aByteArray into a printable string. If aDefaultChar to replace the non-printable characters is not provided it will default to ".".

ow.format.string.progress

ow.format.string.progress(aNumericValue, aMax, aMin, aSize, aIndicator, aSpace) : String

Outputs an in-line progress bar given aNumericValue, aMax value, aMin value, the aSize of the bar and the aIndicator to use. If not provided, aMax defaults to aValue, aMin defaults to 0, aSize defaults to the current screen width (or 5 if  if can be determined), aIndicator defaults to "#"  and aSpace defaults to " ". If aSize is a negative value and it's possible to determine the current screen width it will subtract to the screen width. Example:

loadLodash(); ow.loadFormat();
var arr = [-30, -25, -10, 0, 3, 5], max = _.max(arr), min = _.min(arr);
for(let i in arr) {
   print(ow.format.string.progress(arr[i], max, min, 5, '-'));
}


ow.format.string.renderLines

ow.format.string.renderLines(aMatrix, numberOfLines, aWidth, aBgPattern, shouldReturn) : String

Tries to render a string grid (if shouldReturn = true won't print it but jsut return it) for a specific aWidth for a numberOfLines with aBgPattern background pattern (defaults to " ") with aMatrix contents (divided by "\n").

ow.format.string.rightPad

ow.format.string.rightPad(aString, length, padExpression) : String

Using a padExpression will right pad aString for the given length.

ow.format.string.separatorsToUnix

ow.format.string.separatorsToUnix(aFilenamePath) : String

Tries to convert the provided aFilenamePath into a path with unix folder separators.

ow.format.string.separatorsToWindows

ow.format.string.separatorsToWindows(aFilenamePath) : String

Tries to convert the provided aFilenamePath into a path with windows folder separators.

ow.format.string.tabExpand

ow.format.string.tabExpand(aStr, aTabSize) : String

Given an input aStr and, optionally, aTabSize will expand the tabs in the string to the provided aTabSize ( similar to the unix expand command).  If aTabSize is not provided it will default to 8.

ow.format.string.toHex

ow.format.string.toHex(aByteArray, aSeparator) : String

Tries to convert aByteArray into a string of hex values separated by aSeparator (defaults to " ").

ow.format.string.toHexArray

ow.format.string.toHexArray(aByteArray, perLine) : String

Returns an array with the ow.format.string.toHex of aByteArray and ow.format.string.printable with a maximum  of perLine (defaults to 30) characters per array element.

ow.format.string.unicode

ow.format.string.unicode(aCodeNumber) : String

Given a unicode aCodeNumber (8 or 16 bits) will convert to the necessary sequence of 8 bit. For example: ow.format.string.unicode(0x1F37A)

ow.format.string.updateLine

ow.format.string.updateLine(aPrintNLFn) : Function

Facilitates updating a message in the same line without entering new-lines. It will use the aPrintNLFn (if not defined uses printnl). Returns an object with two functions: line(aMessage) and end(). The function line() should be called to change the current line message. On the  end calling the function end() will clean-up a return the cursor to the beginning of the line.

ow.format.string.wildcardRE

ow.format.string.wildcardRE(aPattern, caseSensitive) : RegExp

Given aPattern using '*' wildcards (to match zero or more characters) or '?' question-mark to match a single character will return the corresponding RegExp. Optionally if caseSensitive=true the RegExp will include case sensitive option.

ow.format.string.wildcardTest

ow.format.string.wildcardTest(aString, aPattern, caseSensitive) : Boolean

Given aString will try to apply aPattern using '*' wildcards (to match zero or more characters) or '?' question-mark to match a single character. Will return true if the aPattern can be applied to aString. Optionally if caseSensitive=true the pattern will be tested with case sensitive.

ow.format.string.wordWrap

ow.format.string.wordWrap(aString, maxWidth, newLineSeparator, tabDefault) : String

Given aString word wraps the text on it given the maxWidth length per line. Optionally you can provide a newLineSeparator otherwise '\n' will be used. Optionally tabDefault determines how many spaces a tab represents (default 4) (available after ow.loadFormat())

ow.format.string.wordWrapArray

ow.format.string.wordWrapArray(anArray, maxTableSize, sepLen, sepFunc, useIndex) : Array

Given anArray of maps will return an array suitable to use with printTable for a maxTableSize, a separator length (sepLen (which defaults to 1)) and an optional line separator function (sepFunc that receives the max length of a  column). Word-wrap is achieved by creating new map array entries whenever the calculated max size of each line  with sepLen is achieved. The boolean flag useIndex changes the result to a map with lines and idx (array of the positions on the lines array that are a new anArray entry). Example of usage:

  __initializeCon()
  var maxS = __con.getTerminal().getWidth()
  print(printTable(ow.format.string.wordWrapArray(io.listFiles("js").files, maxS, 1, s => ansiColor("FAINT", repeat(s, "-"))), maxS))

ow.format.testHost

ow.format.testHost(aAddress, aTimeout) : Map

Uses the java implementation (e.g. usually ICMP ping) for testing reachability to an aAddress. It timeouts after aTimeout (defaults to 4000ms). Returns a map with the "time" spent trying to get an answer from aAddress and a boolean "reachable" with the result.

ow.format.testPort

ow.format.testPort(aAddress, aPort, aCustomTimeout) : boolean

Tries to connect to aPort (e.g. 1234) on aAddress (e.g. 1.2.3.4). If the connection is successfull it will disconnect and return true, otherwise it will return false. If aCustomTimeout (in ms) is defined, it will use that value as the timeout instead of the 1,5 seconds by default.

ow.format.testPortLatency

ow.format.testPortLatency(aHost, aPort, aCustomTimeout) : Number

Test establishing a TCP socket connection with aHost on aPort. Optionally aCustomTimeout can be provided (defaults to 60000 ms). The test will be timed and the time in ms will be returned. If returned a time < 0 then an error occurred or the  host:port couldn't be reached.

ow.format.testPublicPort

ow.format.testPublicPort(aPort) : Map

Uses the functionality provided by http://ifconfig.co to return a map with the result of testing if aPort is within public  reach from your apparent current public ip address. Please be aware of the request limits of the service (around 1 request per minute).

ow.format.testURLLatency

ow.format.testURLLatency(aURL, aCustomTimeout) : Number

Test sending a HTTP(s) GET to aURL. Optionally aCustomTimeout can be provided. The test will be timed and the time in ms will be returned. If returned a time < 0 then an error occurred or the host:port couldn't be reached.

ow.format.timeago

ow.format.timeago(aDate, isAbv) : String

Will output how much time ago aDate is (e.g. 2 years ago, 30 minutes ago, etc...).
Optionally isAbv = true for abbreviated output.  (available after ow.loadFormat())

ow.format.toAbbreviation

ow.format.toAbbreviation(aNumber, aDigits) : String

Returns a number abbreviation to "k", "m", "b", "t". Will round number to 2 decimals if aDigits doesn't provide a different decimal digits to round to.
(available after ow.loadFormat())

ow.format.toBase16

ow.format.toBase16(aString) : String

Given aString or array of bytes transforms the contents to base 16.

ow.format.toBase32

ow.format.toBase32(aString) : String

Given aString or array of bytes transforms the contents to base 32.

ow.format.toBase36

ow.format.toBase36(aNumber, aLength) : String

Converts a provided aNumber to the base36 representation. Optionally you can provide a length for 0 left pad.

ow.format.toBinary

ow.format.toBinary(aNumber, aLength) : String

Converts a provided aNumber to the binary representation. Optionally you can provide a length for 0 left pad.

ow.format.toBytesAbbreviation

ow.format.toBytesAbbreviation(aNumber, aDigits) : String

Returns a number abbreviation to "bytes", "KB", "MB", "GB", "TB", etc. Will round number to 3 significant digits if aDigits doesn't provide a different number of precision digits to convert to.
(available after ow.loadFormat())

ow.format.toCSLON

ow.format.toCSLON(aObj, cTheme) : String

Equivalent to ow.fornat.toSLON but includes ansi color.

ow.format.toDate

ow.format.toDate(aStringDate, aFormat, aTimeZone) : Date

Will convert aStringDate into a javascript Date given aFormat:

  G - Era descriptor (AD)
  y - Year (1996; 96)
  Y - Week year (2009; 09)
  M - Month in year (July; Jul; 07)
  w - Week in year (27)
  W - Week in month (2)
  D - Day in year (189)
  d - Day in month (10)
  F - Day of week in month (2)
  E - Day name in week (Tuesday; Tue)
  u - Day number of week (1 = Monday, ..., 7 = Sunday) (1)
  a - Am/pm number (PM)
  H - Hour in day (0-23)
  k - Hour in day (1-24)
  K - Hour in am/pm (0-11)
  h - Hour in am/pm (1-12)
  m - Minute in hour (30)
  s - Second in minute (55)
  S - Millisecond (978)
  z - Time zone (Pacific Standard Time; PST; GMT-08:00)
  Z - Time zone (-0800)
  X - Time zone (-08; -0800; -08:00)

Optionally you can also provide the original aTimeZone (like 'America/New_York', 'Europe/London', 'UTC', ...)
(available after ow.loadFormat())

ow.format.toHex

ow.format.toHex(aNumber, aLength) : String

Converts a provided aNumber to the hexadecimal representation. Optionally you can provide a length for 0 left pad.

ow.format.toLDAPDate

ow.format.toLDAPDate(aDate) : Number

Converts a javascript Date into a LDAP date (also known as Windows NT time format, Active Directory timestamps)

ow.format.toOctal

ow.format.toOctal(aNumber, aLength) : String

Converts a provided aNumber to the octal representation. Optionally you can provide a length for 0 left pad.

ow.format.toSLON

ow.format.toSLON(aObj, cTheme) : String

Stringifies aObj into a Single Line Object Notation using a default scheme for human readability or a  custom cTheme map composed of:

   startMap "("
   sepMap   ", "
   endMap   ")"
   sepKV    ": "
   startArr "["
   sepArr   " | "
   endArr   "]"
   strQuote "'"


ow.format.toUnixDate

ow.format.toUnixDate(aDate) : Number

Returns a unix timestamp from the provided javascript aDate.

ow.format.toWedoDate

ow.format.toWedoDate(aStringDate, aFormat) : Map

Shortcut for using ow.format.toDate but converting the output into a wedo date.  
(available after ow.loadFormat())

ow.format.transposeArrayLines

ow.format.transposeArrayLines(anLineArray) : Array

Given anLineArray transposes into a new array of lines.

ow.format.unescapeHTML4

ow.format.unescapeHTML4(aString) : String

Uses Apache Commons Lang unescape HTML4 functionality to unconvert aString with HTML4 entities to the original string

ow.format.withMD

ow.format.withMD(aString, defaultAnsi) : String

Use aString with simple markdown and convert it to ANSI. Optionally you can add a defaultAnsi string to return back  after applying the ansi styles for markdown (use ansiColor function to provide the defaultAnsi). Currently supports only: bold, italic, tables, simple code blocks, line rule, bullets, numbered lines, links and blocks.

ow.format.withSideLine

ow.format.withSideLine(aString, aSize, ansiLine, ansiText, aTheme, aExtra) : String

Generates a ansi escaped line with a "left side line" to display aString which will be word-wrap given  aSize (default to the current console size). Optionally ansi colors for ansiLine and ansiText can be provided (see ansiColor for possible values) and aTheme (using ow.format.withSideLineThemes, for example). For closed rectangle themes aExtra map can include a header, footer, headerAlign ( left or right or center) and footerAlign (left or right or center).

ow.format.xls.autoFilter

ow.format.xls.autoFilter(aXLS, aXLSSheet, aRange)

Applies a auto filter on the provided aXLS and aXLSSheet object (from XLS.getSheet) to aRange.

Example:

   ow.format.xls.autoFilter(sheet, "A1:D1");


ow.format.xls.getStyle

ow.format.xls.getStyle(aXLS, aStyleMap)

Creates a cell styler object, for the aXLS object (XLS plugin object instance), given the provided aStyleMap. The aStyleMap can have the following keys to define a style:

  - bold (boolean)
  - italic (boolean)
  - underline (boolean)
  - strikeout (boolean)
  - fontPoints (number)
  - fontName (string)
  - fontColor (string)
  - wrapText (boolean)
  - shrinkToFit (boolean)
  - backgroundColor (string)
  - foregroundColor (string)
  - borderBottom (string)
  - borderLeft (string)
  - borderRight (string)
  - borderTop (string)
  - borderBottom (string)
  - borderLeftColor (string)
  - borderRightColor (string)
  - borderTopColor (string)
  - borderBottomColor (string)
  - rotation (number)
  - indention (number)
  - valign ("top", "bottom", "center", "justify")
  - align ("center", "centerSelection", "fill", "general", "justify", "left", "right")

Color names:\  
aqua,auto,black,blue,blue_grey,bright_green,brown,coral,cornflower_blue,dark_blue,dark_green,dark_red,dark_teal, dark_yellow,gold,green,grey25,grey40,grey50,grey80,indigo,lavender,lemon_chiffon,light_blue,light_cornflower_blue, light_green,light_orange,light_turquoise,light_yellow,lime,maroon,olive_green,orange,orchid,pale_blue,pink,plum, red,rose,royal_blue,sea_green,sky_blue,tan,teal,turquoise,violet,white,yellow

Border names:

dash_dot,dash_dot_dot,dashed,dotted,double,hair,medium,medium_dash_dot,medium_dash_dot_dot,medium_dashed,none, slanted_dash_dot,thick,thin

Fill patterns:

solid_foreground


ow.format.xls.setTable

ow.format.xls.setTable(aXLS, aSheet, aColumn, aRow, anArray, shouldAutoFilter, headerStyle, linesStyle)

Shortcut for xls.setTable that given aXLS object, a corresponding aSheet object will try to set the contents of  anArray of maps starting in aColumn and aRow performing auto size for all columns. If shouldAutoFilter = true is will also add an autofilter to all columns. It's possible also to customize the headerStyle and linesStyle.