Skip to content

RPT Filters

Peter Johnson edited this page Feb 13, 2023 · 42 revisions

rpt Filters

⚠️⚠️ THIS WIKI IS BEING USED TO JOT DOWN IDEAS AT PRESENT. DON'T ASSUME ANYTHING IS FIXED. ⚠️⚠️

⚒️ MORE TO COME: Check back later

The filters listed on this page are unique to rpt, they are not copies of Liquid filters.

Filters that are not yet implemented are marked with a ⛔ symbol.

Mathematical Filters

Filter Parameters Input Type Output Type Notes
div ⛔ Int Int Int Returns the input divided by the parameter using integer division. The parameter must not be zero.
divide ⛔ Int or Float Int or Float Float Returns the input divided by the parameter using floating point division. The parameter must not be zero.
mod ⛔ Int Int Int Returns the remainder after dividing the input by the parameter using integer division. The parameter must not be zero.
clamp ⛔ (min) Numeric, (max) Numeric Numeric Numeric Clamps the input value between (min) and (max). If input is less than (min) then (min) is returned. If input is greater than (max) then (max) is returned. Otherwise input is returned. If all of input, (min) and (max) are type Int then output is also Int, otherwise output has type Float.

NOTE: div and divide are both subtlety different to the Liquid divided_by filter. Similarly mod differs from the Liquid modulo filter.

Text Filters

Filter Parameters Input Type Output Type Notes
capitalize-first ⛔ none Text Text Makes the first character of the input text string capitalized and outputs the result. Leaves the rest of the input unchanged. See also the similar, but different, Liquid capitalize filter.
newline-chars ⛔ none Text Text Detects type of newline character(s) used in input text, if any, and writes them to output. First newline found is assumed to be used consistently throughout text. Return value can be any of \n, \r, \r\n or, if text doesn't contain a newline, an empty string.
replace-newlines ⛔ Text Text Text Replaces all newline character(s) in input text with text passed in parameter. Newlines of form LF, CR & CRLF are all replaced. E.g. to standardise on Windows CRLF new lines set parameter to "\r\n".
fixup-newlines ⛔ none Text Text Replaces all newline sequences in the input text with the correct newline for the operating system, i.e. \r\n in Windows or \n on Unix/Linux based systems.
fixup-file-paths ⛔ none Text Text Replaces all file path separators in the input with the correct separators for the operating system, i.e. \ on Windows or / on Unix/Linux based systems.
reverse-str ⛔ none Text Text Reverses text read from input.

Date Filters

Filter Parameters Input Type Output Type Notes
year ⛔ none DateTime Int Year number.
month ⛔ none DateTime Int Month number within year (1..12).
day ⛔ none DateTime Int Day of month (1..31).
hour ⛔ none DateTime Int Hour of day (1..24).
minute ⛔ none DateTime Int Minute of hour (0..59).
second ⛔ none DateTime Int Second of minute (0..59).
millis ⛔ none DateTime Int Millisecond of minute (0..999).
day-of-week ⛔ none DateTime Int Day of week (1..7) per ISO 8601.
day-of-year ⛔ none DateTime Int Day of year per ISO 8601.
week-of-year ⛔ none DateTime Int Week of year per ISO 8601.
month-name ⛔ none DateTime Text Full name of month in current locale.
month-abbrev ⛔ none DateTime Text Abbreviated name of month in current locale.
day-name ⛔ none DateTime Text Full name of day of week in current locale.
day-abbrev ⛔ none DateTime Text Abbreviated name of day of week in current locale.
iso-datetime ⛔ Boolean DateTime Text Date and time value in ISO 8601 format. If the parameter is true then date is in UTC format, else date is in local time for the current locale. The UTC form of this function is the DateTime default string.
am-pm ⛔ none DateTime Text AM or PM indicator in current locale.
time-am-pm ⛔ none DateTime Text Time rendered using 12 hr clock with AM or PM indicator in current locale.
utc-to-local ⛔ none DateTime DateTime Converts a DateTime in UTC to a local DateTime in the current locale.
local-to-utc ⛔ none DateTime DateTime Converts a local DateTime in the current locale to a DateTime in UTC.
era ⛔ none DateTime Int Era number.
era-name ⛔ none DateTime Text Full name of era.
era-abbrev ⛔ none DateTime Text Abbreviated name of era.
inc-day ⛔ Int DateTime DateTime Outputs date from input shifted by number of days specified by parameter.
inc-hour ⛔ Int DateTime DateTime Outputs date from input shifted by number of hours specified by parameter.
inc-millis ⛔ Int DateTime DateTime Outputs date from input shifted by number of milliseconds specified by parameter.
inc-minute ⛔ Int DateTime DateTime Outputs date from input shifted by number of minutes specified by parameter.
inc-month ⛔ Int DateTime DateTime Outputs date from input shifted by number of months specified by parameter.
inc-second ⛔ Int DateTime DateTime Outputs date from input shifted by number of seconds specified by parameter.
inc-week ⛔ Int DateTime DateTime Outputs date from input shifted by number of weeks specified by parameter.
inc-year ⛔ Int DateTime DateTime Outputs date from input shifted by number of years specified by parameter.

Formatting Filters

Filter Parameters Input Type Output Type Notes
pad-left ⛔ (x) Int, (y) Text Text Text Pads the input text on the left to a maximum width of (x) characters. The text is padded with text (y), which should normally be a single character.
pad-right ⛔ (x) Int, (y) Text Text Text Pads the input text on the right to a maximum width of (x) characters. The text is padded with text (y), which should normally be a single character.
fmt-float ⛔ (x) Text Float Text Formats the input float per format string (x). The format string is the same as that used by the Delphi Pascal Format function, except that only the e, f, g, m & n value types may be used.
fmt-date ⛔ (x) Text DateTime Text Formats date on input according to format string (x). The format string is the same as that used by the Delphi Pascal DateTimeToString function.
int-to-hex ⛔ (x) Int Int Text Converts input Int to hexadecimal format, with the minimum number of digits specified by (x). Values that are shorter than (x) are left padded with zeros.

Type Conversion & Checking Filters

Filter Parameters Input Type Output Type Notes
parse-int ⛔ none Textish Int or Null Parses the input Text as an integer. If the conversion fails then Null is returned.
parse-float ⛔ none Text or Int Float or Null Parses the input as a floating point value. Text input is converted a float if possible, otherwise Null is returned. Int values always converted.
parse-date ⛔ none Textish DateTime or Null Parses the input Text as a DateTime value. If the conversion fails then Null is returned.
parse-bool ⛔ none Any Boolean Parses the input as a Boolean value. Always returns the truthiness value as defined for the input type.
int-to-float ⛔ none Int Float Converts the input Int to a Float.
hex-to-int ⛔ none Text Int or Null Converts the input hexadecimal Text into an integer. If the conversion fails then Null is returned.
to-string ⛔ none Any Text Converts any type to Text in the default format for the type.
to-file ⛔ none Text File or Null Converts the input Text value to a File object, providing the input is a valid file path. Null is returned otherwise.
to-dir ⛔ none Text Directory or Null Converts the input Text value to a Directory object, providing the input is a valid directory path. Null is returned otherwise.
null ⛔ none Any Null Returns a null value regardless of input. The main use case is to optionally return a null value from one branch of an @if command. Note: to unconditionally return Null from a placeholder use the ; operator instead of this filter.
is-null ⛔ none Any Boolean Checks if the type of the input is Null and returns @true if so and @false if not.
is-int ⛔ none Any Boolean Checks if the type of the input is Int and returns @true if so and @false if not.
is-float ⛔ none Any Boolean Checks if the type of the input is Float and returns @true if so and @false if not.
is-numeric ⛔ none Any Boolean Checks if the type of the input is Numeric (i.e. Int or Float) and returns @true if so and @false if not.
is-datetime ⛔ none Any Boolean Checks if the type of the input is DateTime and returns @true if so and @false if not.
is-boolean ⛔ none Any Boolean Checks if the type of the input is Boolean and returns @true if so and @false if not.
is-text ⛔ none Any Boolean Checks if the type of the input is Text and returns @true if so and @false if not.
is-file ⛔ none Any Boolean Checks if the type of the input is File and returns @true if so and @false if not.
is-directory ⛔ none Any Boolean Checks if the type of the input is Directory and returns @true if so and @false if not.
is-url ⛔ none Any Boolean Checks if the type of the input is URL and returns @true if so and @false if not.
is-array ⛔ none Any Boolean Checks if the type of the input is Array and returns @true if so and @false if not.
is-os ⛔ none Any Boolean Checks if the type of the input is OS and returns @true if so and @false if not.
is-empty ⛔ none Text, Boolean & Null Boolean Checks if the input is empty. Returns @true if Text input is an empty string, if Boolean input is a @false or if input is Null, otherwise returns @false.

Unit Conversion Filters

Filter Parameters Input Type Output Type Notes
c-to-f ⛔ none Int or Float Float Converts the input number from degrees Centigrade to degrees Fahrenheit.
f-to-c ⛔ none Int or Float Float Converts the input number from degrees Fahrenheit to degrees Centigrade.
c-to-k ⛔ none Int or Float Float or Null Converts the input number from degrees Centigrade to Kelvin. If the input value is less than -273.15℃ then Null is returned.
k-to-c ⛔ none Int or Float Float or Null Converts the input number from Kelvin to degrees Centigrade. If the input value is less than 0K then Null is returned.

File System Filters

File system filters operate of File and/or Directory objects.

Filter Parameters Input Type Output Type Notes
fs-path ⛔ none File or Directory Text Full path to file or directory. 🗒 This is the default text for File and Directory objects.
fs-name ⛔ none File or Directory Text Name of file or directory without path.
fs-parent ⛔ none File or Directory Directory Parent directory of file of directory.
fs-extension ⛔ none File or Directory Text Extension or file or directory. Empty string if no extension present.
fs-base-name ⛔ none File or Directory Text Name of file or directory without path or extension.
fs-drive ⛔ none File or Directory Text Drive on which file or directory is located (empty string on Linux/Unix based systems).
fs-share ⛔ none File or Directory Text Name of network share on which file or directory is located (empty string on Linux/Unix based systems).
fs-mod-date ⛔ none File or Directory DateTime Date & time file or directory was last modified.
fs-create-date ⛔ none File or Directory DateTime Date & time file or directory was created.
fs-access-date ⛔ none File or Directory DateTime Date & time file or directory was last accessed.

Comparison & Logical Filters

Filter Parameters Input Type Output Type Notes
if ⛔ (a) Any, (b) Any Any Any If filter input is truthy then (a) is copied to output else (b) is copied to output. Type of output is the same as that of copied parameter. Parameter (b) may be omitted, in which case Null is returned if input is falsey.
unless ⛔ (a) Any, (b) Any Any Any If filter input is falsey then (a) is copied to output else (b) is copied to output. Type of output is the same as that of copied parameter. Parameter (b) may be omitted, in which case Null is returned if input is truthy.
not ⛔ none Any Boolean Inverts the logical value of the input. If input is truthy then @false is returned or if the input is falsey then @true is returned.
and ⛔ Any Any Boolean Performs a logical and operation on the truthiness of the input and the parameter and returns it.
or ⛔ Any Any Boolean Performs a logical or operation on the truthiness of the input and the parameter and returns it.
xor ⛔ Any Any Boolean Performs a logical xor operation on the truthiness of the input and the parameter and returns it.
eq ⛔ Text Text Boolean Performs a case sensitive comparison of the input text with the text parameter and returns @true if they are equal or @false if not.
eq ⛔ Numeric Numeric Boolean Compares the input Text with the parameter and returns @true if they are equal or @false if not. If the input is Int and the parameter is Float, or vice versa, then the Int value is converted to a Float first.
eq ⛔ Boolean Boolean Boolean Compares the input Boolean with the parameter and returns @true if they are equal or @false if not.
eq ⛔ DateTime DateTime Boolean Compares the input DateTime with the parameter and returns @true if they are equal or @false if not.
neq ⛔ Text, Numeric, Boolean & DateTime Text, Numeric, Boolean & DateTime Boolean Similar to eq for each of the given types except that @false is returned when the input equals the parameter and @true if not.
lt ⛔ Text, Numeric, & DateTime Text, Numeric & DateTime Boolean Similar to eq for each of the given types except that @true is returned when the input is less than the parameter and @false if not.
lte ⛔ Text, Numeric, & DateTime Text, Numeric & DateTime Boolean Similar to eq for each of the given types except that @true is returned when the input is less than or equal to the parameter and @false if not.
gt ⛔ Text, Numeric, & DateTime Text, Numeric & DateTime Boolean Similar to eq for each of the given types except that @true is returned when the input is greater than the parameter and @false if not.
gte ⛔ Text, Numeric, & DateTime Text, Numeric & DateTime Boolean Similar to eq for each of the given types except that @true is returned when the input is greater than or equal to the parameter and @false if not.
eq-text ⛔ Text Text Boolean Performs a case insensitive comparison of the input text with the text parameter and returns @true if they are equal or @false if not.
neq-text ⛔ Text Text Boolean Performs a case insensitive comparison of the input text with the text parameter and returns @false if they are equal or @true if not.