Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Built-in filters #6

Open
34 tasks
rossmacarthur opened this issue Oct 1, 2022 · 1 comment
Open
34 tasks

Built-in filters #6

rossmacarthur opened this issue Oct 1, 2022 · 1 comment
Labels
feature New feature or request

Comments

@rossmacarthur
Copy link
Owner

rossmacarthur commented Oct 1, 2022

There are a number of filter functions which might be common or useful enough to provide by default. Some options:

Examples

General

Type conversion filters could be useful, e.g.

  • bool: convert a value to a boolean using "truthy" logic, e.g. empty string, list, and map is false, zero integer and float is false.
  • int: convert from boolean and float to int
  • list: convert map to a list of lists of length two.

Booleans

These would be useful for if statements

  • eq, ne
  • gt, gte, lt, lte
  • and, or
  • not

Numbers

  • abs: returns the absolute value of the number
  • add <v>, sub <v>
  • mul <v>, div <v>
  • round: rounds to the given precision

Strings

  • len / length / size: return the length of the string
  • lower: convert a string to lowercase
  • upper: convert a string to uppercase
  • title: convert a string to titlecase
  • trim / strip: trims whitespace from a string
  • ltrim / lstrip, rtrim / rstrip: trims whitespace from a string from the one end
  • reverse: reverses the list
  • replace <from> <to>: replaces a substring with another
  • append <s>: appends the given string
  • prepend <s>: prepends the given string

Lists

  • len / length / size: return the length of the list
  • first: return the first item in a list
  • last: return the last item in a list
  • slice: slice a list
  • nth <n>: return the nth item in a list
  • join <sep> / concat <sep>: join a sequence by separator
  • uniq: remove any duplicate items from the list
  • sorted: sorts the list (? how should differently typed Values be ordered?)

Maps

  • len / length / size: return the length of the map
  • keys: returns a list of the keys in the map
  • values: returns a list of the values in the map
  • first: return the first item in the map
  • last: return the last item in the map
@qq253498229
Copy link

qq253498229 commented Aug 23, 2024

I think json and date are also commonly used.

{{ my_object_instance | json }} => {"field1" : "text1"}
{{ create_time | date: "yyyy-MM-dd HH:mm:ss.SSS" }} => 2024-08-23 10:00:00.000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants