-
Notifications
You must be signed in to change notification settings - Fork 6
ow.format
- ow.format.addNumberSeparator
- ow.format.cron.isCronMatch
- ow.format.cron.nextScheduled
- ow.format.cron.parse
- ow.format.cron.prevScheduled
- ow.format.cron.sleepUntilNext
- ow.format.cron.timeUntilNext
- ow.format.dateDiff.inDays
- ow.format.dateDiff.inHours
- ow.format.dateDiff.inMinutes
- ow.format.dateDiff.inMonths
- ow.format.dateDiff.inSeconds
- ow.format.dateDiff.inWeeks
- ow.format.dateDiff.inYears
- ow.format.elapsedTime
- ow.format.elapsedTime4ms
- ow.format.escapeHTML
- ow.format.escapeString
- ow.format.fromBinary
- ow.format.fromByte
- ow.format.fromDate
- ow.format.fromHex
- ow.format.fromOctal
- ow.format.fromUnixDate
- ow.format.fromWedoDate
- ow.format.fromWedoDateToDate
- ow.format.getActualTime
- ow.format.getPublicIP
- ow.format.isWedoDate
- ow.format.round
- ow.format.string.bestPrefix
- ow.format.string.closest
- ow.format.string.distance
- ow.format.string.leftPad
- ow.format.string.lsHash
- ow.format.string.lsHashDiff
- ow.format.string.progress
- ow.format.string.rightPad
- ow.format.string.separatorsToUnix
- ow.format.string.separatorsToWindows
- ow.format.string.wordWrap
- ow.format.testPort
- ow.format.testPublicPort
- ow.format.timeago
- ow.format.toAbbreviation
- ow.format.toBinary
- ow.format.toBytesAbbreviation
- ow.format.toDate
- ow.format.toHex
- ow.format.toOctal
- ow.format.toUnixDate
- ow.format.toWedoDate
- ow.format.transposeArrayLines
- ow.format.xls.autoFilter
- ow.format.xls.getStyle
ow.format.addNumberSeparator(aNumber, aSeparator) : StringReturns a formatted number with decimal separators (default is comma but you can provide a custom aSeparator).
(available after ow.loadFormat())
ow.format.cron.isCronMatch(aDate, aCronExpression) : booleanReturns trues if the provided aDate is a match for the provided aCronExpression. Otherwise returns false.
ow.format.cron.nextScheduled(expr, count, start, end) : DateGiven 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(aCronExpression) : MapParses 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(expr, count, start, end) : DateGiven 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.sleepUntilNext(expr)Sleeps until the cron expr is expected to be true.
ow.format.cron.timeUntilNext(expr) : NumberReturns a number of ms until the cron expr is expected to be true.
ow.format.dateDiff.inDays(dateBefore, dateAfter, shouldRound) : NumberDifference between dateAfter and dateBefore in days. If shouldRound = true will round from the previous time unit.
ow.format.dateDiff.inHours(dateBefore, dateAfter, shouldRound) : NumberDifference between dateAfter and dateBefore in hours. If shouldRound = true will round from the previous time unit.
ow.format.dateDiff.inMinutes(dateBefore, dateAfter, shouldRound) : NumberDifference between dateAfter and dateBefore in minutes. If shouldRound = true will round from the previous time unit.
ow.format.dateDiff.inMonths(dateBefore, dateAfter) : NumberDifference between dateAfter and dateBefore in months.
ow.format.dateDiff.inSeconds(dateBefore, dateAfter, shouldRound) : NumberDifference between dateAfter and dateBefore in seconds. If shouldRound = true will round from the previous time unit.
ow.format.dateDiff.inWeeks(dateBefore, dateAfter, shouldRound) : NumberDifference between dateAfter and dateBefore in weeks. If shouldRound = true will round from the previous time unit.
ow.format.dateDiff.inYears(dateBefore, dateAfter) : NumberDifference between dateAfter and dateBefore in years.
ow.format.elapsedTime(aStartTime, aEndTime, aFormat) : StringShortcut for ow.format.elapsedTime4ms calculating the absolute difference, in ms, between aStartTime and aEndTime.
ow.format.elapsedTime4ms(aMs, aFormat) : StringGiven 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(aString) : StringWill escape, and return, aString for HTML/XML special characters.
(available after ow.loadFormat())
ow.format.escapeString(aString, aExceptString) : StringWill escape, and return, aString for RegExp special characters with the exception of any characters in aExceptString.
(available after ow.loadFormat())
ow.format.fromBinary(aString) : NumberConverts a provided binary aString into the decimal number.
ow.format.fromByte(aByte) : NumberConverts a byte info a decimal number.
ow.format.fromDate(aDate, aFormat, aTimeZone) : StringWill 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(aString) : NumberConverts a provided hexadecimal aString into the decimal number.
ow.format.fromOctal(aString) : NumberConverts a provided octal aString into the decimal number.
ow.format.fromUnixDate(aUnixDate) : DateConverts aUnixDate timestamp into a javascript Date.
ow.format.fromWedoDate(aWedoDate, aFormat) : StringShortcut for ow.format.fromDate but using a wedo date. See ow.format.fromDate for more help.
(available after ow.loadFormat())
ow.format.fromWedoDateToDate(aWedoDate) : DateReturns a date object from a wedo date. (available after ow.loadFormat())
ow.format.getActualTime(useAlternative) : DateRetrieves the current actual time from NIST (through https). The current actual time will be returned in a Date. If useAlternative = true it will use now.httpbin.org (through http)
ow.format.getPublicIP() : MapUses 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.isWedoDate(aWedoDate) : booleanDetermines if the aWedoDate object is a wedo date type (returns true if yes, false otherwise).
(available after ow.loadFormat())
ow.format.round(aNumber, aDigits) : StringWill return aNumber rounded to 0 decimal digits or aDigits decimal digits.
(available after ow.loadFormat())
ow.format.string.bestPrefix(aString, anArrayOfStrings) : aStringGiven 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.closest(aString, anArrayOfStrings, aThreshold) : aStringGiven 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.distance(aStringA, aStringB, maxOffset) : NumberCalculates 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.leftPad(aString, length, padExpression) : StringUsing a padExpression will left pad aString for the given length.
ow.format.string.lsHash(aStringA, aStringB, dontCareDiffSize) : StringGenerates 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(aHashA, aHashB, dontCareDiffSize) : StringFrom 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.progress(aNumericValue, aMax, aMin, aSize, aIndicator, aSpace) : StringOutputs 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 5, aIndicator defaults to "#" and aSpace defaults to " ". 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.rightPad(aString, length, padExpression) : StringUsing a padExpression will right pad aString for the given length.
ow.format.string.separatorsToUnix(aFilenamePath) : StringTries to convert the provided aFilenamePath into a path with unix folder separators.
ow.format.string.separatorsToWindows(aFilenamePath) : StringTries to convert the provided aFilenamePath into a path with windows folder separators.
ow.format.string.wordWrap(aString, maxWidth, newLineSeparator) : StringGiven aString word wraps the text on it given the maxWidth length per line. Optionally you can provide a newLineSeparator otherwise '\n' will be used. (available after ow.loadFormat())
ow.format.testPort(aAddress, aPort, aCustomTimeout) : booleanTries 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.testPublicPort(aPort) : MapUses 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.timeago(aDate) : StringWill output how much time ago aDate is (e.g. 2 years ago, 30 minutes ago, etc...).
(available after ow.loadFormat())
ow.format.toAbbreviation(aNumber, aDigits) : StringReturns 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.toBinary(aNumber, aLength) : StringConverts a provided aNumber to the binary representation. Optionally you can provide a length for 0 left pad.
ow.format.toBytesAbbreviation(aNumber, aDigits) : StringReturns 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.toDate(aStringDate, aFormat) : DateWill 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)
(available after ow.loadFormat())
ow.format.toHex(aNumber, aLength) : StringConverts a provided aNumber to the hexadecimal representation. Optionally you can provide a length for 0 left pad.
ow.format.toOctal(aNumber, aLength) : StringConverts a provided aNumber to the octal representation. Optionally you can provide a length for 0 left pad.
ow.format.toUnixDate(aDate) : NumberReturns a unix timestamp from the provided javascript aDate.
ow.format.toWedoDate(aStringDate, aFormat) : MapShortcut for using ow.format.toDate but converting the output into a wedo date.
(available after ow.loadFormat())
ow.format.transposeArrayLines(anLineArray) : ArrayGiven anLineArray transposes into a new array of lines.
ow.format.xls.autoFilter(aXLSSheet, aRange)Applies a auto filter on the provided aXLSSheet object (from XLS.getSheet) to aRange.
Example:
ow.format.xls.autoFilter(sheet, "A1:D1");
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