Skip to main content

B5.Function List

trydoforOriginalMeepoTemplateAbout 2 min

B5.Function List

For more details on function usage, see the [Dictionary Engine Map] for pipeline conventions and function rules.

Both full function names and aliases start with fun:; if there is no conflict in pipeline, the prefix can be omitted.

The following conventions for describing functions are used in the example,

  • obj - Specifies pipeline output, or null if unavailable
  • arg... - arg is a variable arguments
  • arg? - arg can be null
  • &opt - opt is the default value
  • String:javaEval - Return type String, function type is javaEval

The following forms are available to use in the template,

  • {{ now }} - use directly
  • {{ index | mod even odd | BIG_SNAKE }} - pipeline function

B5.1.Type of Date/Time

Focuse on Date and time, mainly value and format.

1a.Current Data/Time now

Usage: String:javaEval, output the current date/time in specified format
Syntax: fun:now ptn?

  • obj - if java.util.Date or TemporalAccessor, then formatted,
  • if null or other, use LocalDateTime.now()
  • ptn - in DateTimeFormatter format.
  • now - without parameter, then yyyy-MM-dd HH:mm:ss
  • now.date - without parameter, output yyyy-MM-dd
  • now.time - without parameter output HH:mm:ss
# ptn contains spaces surrounded by quotes
{{ now 'yyyy-MM-dd HH:mm:ss' }}
# output 2021-01-05 10:01:31
// RNA:USE /date/fun:now/

B5.2.Type of Number

Focuse on Number, mainly Long and BigDecimal

2a.Modulo and Remainder mod

Usage: String:javaEval, Take MOD(obj, args.length) as index(0-based) to get the index element in args
Syntax: fun:mod obj arg...
Return: using mod as index, get element in args, then get value from context

  • obj - can convert to Number.intValue, take the remainder of arg.length
    • Boolean, false=0, true=1
    • Number, intValue
    • Else, toString then to BigDecimal
  • arg - must have value, can be string or number
# index = 3; count = 4;
{{ index | mod even odd }}
{{ count | mod even "" }}
# output odd even

2b.Absolute Value abs

Usage: String:javaEval, Take the absolute value of the number
Syntax: fun:abs obj
Return: Absolute value in Long or BigDecimal type

  • obj - can convert to Number, return Long or BigDecimal
# npi = -3.14; count = 4;
{{ npi | abs }}
{{ count | abs }}
# output 3.14 4

B5.3.Formatting fmt

Formatting object as string

3a.printf

Usage: String:javaEval, use String.printf to format object
Syntax: fun:fmt obj ptn
Return: String in specified pattern

  • obj - any object
  • ptn - java's formatting, call String.format(ptn,obj)
# amount = 1000
{{ amount | fmt '$%,d' }}
# output $1,000

B5.4.Type of String

Focuse on String

4a.Naming Style

Usage: String:javaEval, Naming style conversion for obj
Syntax: fun:### obj arg?, ### is the following function and aliase
Return: String in specified style

  • upperCase - All uppercase, support locale
  • lowerCase - All lowercase, support locale
  • dotCase - . separated, customizable case, eg. try.do.for
  • kebabCase, kebab-case - - separated, customizable case, eg. try-do-for
  • bigKebab, BIG-KEBAB - - separated, all uppercase, eg. TRY-DO-FOR
  • camelCase - camel, first lowercase, eg. tryDoFor
  • pascalCase, PascalCase - Pascal , first upcasecase eg. TryDoFor
  • snakeCase, snake_case - _ separated, customizable case, eg. try_do_for
  • bigSnake, BIG_SNAKE - _ separated, all uppercase, eg. TRY_DO_FOR

Parameter Description,

  • obj - String, or toString, null returns empty
  • arg - in upperCase or lowerCase, is locale format
  • arg - in dotCase,snakeCase,kebabCase, is lower,upper,keep
  • others function without arg, no customizable case
# author = try&DO&for
{{ author | upperCase zh-cn }} #output TRY&DO&FOR
{{ author | lowerCase zh-cn }} #output try&do&for
{{ author | dotCase }}         #output try.do.for
{{ author | dotCase lower }}   #output try.do.for
{{ author | dotCase upper }}   #output TRY.DO.FOR
{{ author | dotCase keep }}    #output try.DO.for
{{ author | kebab-case }}      #output try-do-for
{{ author | BIG-KEBAB }}       #output TRY-DO-FOR
{{ author | camelCase }}       #output tryDoFor
{{ author | PascalCase }}      #output TryDoFor
{{ author | snake_case }}      #output try_do_for
{{ author | BIG_SNAKE }}       #output TRY_DO_FOR

B5.5.Condition Control

Simple conditional output control.

5a.Output visible see

Usage: String:javaEval, output the first visiable value in arg
Syntax: fun:see obj arg...
Return: The first non-null or non-empty string in arg or obj itself

  • obj - any object
  • arg - String or other objects
# ctx.put("nil", null);
#  ctx.put("empty", "");
#  ctx.put("value", "got");
{{ fun:see nil empty value }}
{{ nil | fun:see empty value }}
# output got