String Filters

String filters manipulate the output of strings.

append

Add string to the end.

Parameters

Parameter Description
type (required) Must be append
string (required) A string to append.

Example

input: foo
schema:
  type: string
  filter:
    type: append
    string: bar

Outputs:

foobar

clean

Remove duplicate line-breaks & white-space.

Parameters

Parameter Description
type (required) Must be clean

Example

input: |
  some

       badly      formated
    string
schema:
  type: string
  filter:
    type: sanitize

Outputs:

some
badly formatted
string

downcase

Convert a string to lower-case.

Parameters

Parameter Description
type (required) Must be downcase

Example

input: hElLo WoRld
schema:
  type: string
  filter:
    type: downcase

Outputs:

hello world

date

Format date strings.

Parameters

Parameter Description
type (required) Must be date.
parse The date format of the input. Defaults to YYYY-MM-DD.
format (required) The date format to output.

Syntax

This syntax used by both parse and format.

Code Description
M month (1)
MM month (01)
MMM month (Jan)
MMMM month (January)
D day (2)
DD day (02)
DDD day (Mon)
DDDD day (Monday)
YY year (06)
YYYY year (2006)
hh hours (15)
mm minutes (04)
ss seconds (05)
AM/PM hours

To display time in AM/PM hours, append pm to your time format e.g.

Code Description
hpm hours (03PM)
h:mmpm hours:minutes (03:04PM)
h:mm:sspm hours:minutes:seconds (03:04:05PM)
Time zones

To specify a time zone format, append ‘ZZZZ’, ‘ZZZ’ or ‘ZZ’ to your time format e.g.

Code Description
hh:mm:ss ZZZZ (16:05:06 +0100)
hh:mm:ss ZZZ (16:05:06 CET)
hh:mm:ss ZZ (16:05:06 +01:00)

Example

input: Tue, 09 Jun 2020 18:25:01 CET
schema:
  type: string
  filter:
    type: date
    parse: DDD, DD MMM YYYY hh:mm:ss ZZZ
    format: YYYY-MM-DD hh:mm:ss

Outputs:

2020-06-09 17:25:01

Inserting the current date/time

If the date input is they keyword now the date filter will use the current date. You can use the default property to pass in the keyword.

input: ''
schema:
  type: string
  default: now
  filter:
    type: date
    format: YYYY-MM-DD hh:mm:ss

downcase

Convert a string to lower-case.

Parameters

Parameter Description
type (required) Must be downcase

Example

input: hElLo WoRld
schema:
  type: string
  filter:
    type: downcase

Outputs:

hello world

phone

Normalise a phone or fax number to a standard format.

Parameters

Parameter Description
type (required) Must be phone
country Default ISO 3166 country code to use (eg. GB). See full list of country codes.
format Can be national, international, E.164 or RFC3966. Defaults to E.164.

Formats

Format Description
national e.g. 044 668 1800
international e.g. +41 44 668 1800
E.164 international format with no formatting applied e.g. +41446681800
RFC3966 international format with spaces and other symbols replaced by hyphens, and extensions appended with “;ext=“. It also will have a prefix of “tel:” added, e.g. tel:+41-44-668-1800;ext=100.

Example

input:
  - 0207 123 456
  - 0049 421 123456
schema:
  type: string
  filter:
    type: phone
    country: GB

Outputs:

+44207123456
+49421123456

prepend

Add string to the beginning.

Parameters

Parameter Description
type (required) Must be prepend
string (required) A string to prepend.

Example

input: foo
schema:
  type: string
  filter:
    type: prepend
    string: bar

Outputs:

barfoo

regex

Extract a substring using regular expressions. The syntax of the regular expressions accepted is the same general syntax used by Perl, Python, and other languages. For more information about the syntax visit https://github.com/google/re2/wiki/Syntax.

Parameters

Parameter Description
type (required) Must be regex
expression (required) Regular expression (eg. ^Phone number: ([0-9]+)$)

Example

input: 'Phone number: 0207123456'
schema:
  type: string
  filter:
    type: regex
    expression: '^Phone number: ([0-9]+)$'

Outputs:

0207123456

replace

Replace a matching substring.

Parameters

Parameter Description
type (required) Must be replace.
find (required) A string that is to be replaced.
replace (required) The string that replaces the substring specified in find.

Example

input: Hello World!
schema:
  type: string
  filter:
    type: replace
    find: World
    replace: Mars

Outputs:

Hello Mars!

sanitize

Remove line-breaks & duplicate white-space.

Parameters

Parameter Description
type (required) Must be sanitize

Example

input: |
  some

       badly      formated
    string
schema:
  type: string
  filter:
    type: sanitize

Outputs:

'some badly formatted string'

split

Split a string into an array of substrings.

Parameters

Parameter Description
type (required) Must be split.
separator (required) Character or string to use as delimiter. If the input does not contain it the full string will be returned.

Example

input: foo bar baz
schema:
  type: string
  filter:
    type: split
    separator: ' '

Outputs:

['foo', 'bar', 'baz']

trim_lines

Remove blank lines and leading & trailing white-space from each line.

Parameters

Parameter Description
type (required) Must be trim

Example

input: |
  some

       badly      formated
    string
schema:
  type: string
  filter: trim_lines

Outputs:

some
badly      formatted
string

trim_prefix

Remove matching string from beginning.

Parameters

Parameter Description
type (required) Must be trim_prefix
prefix (required) Substring to remove.

Example

input: foobar
schema:
  type: string
  filter:
    type: trim_prefix
    prefix: foo

Outputs:

bar

trim_suffix

Remove matching string from end.

Parameters

Parameter Description
type (required) Must be trim_suffix
trim_suffix (required) Substring to remove.

Example

input: foobar
schema:
  type: string
  filter:
    type: trim_suffix
    suffix: bar

Outputs:

foo

trim

Remove leading and trailing white-space.

Parameters

Parameter Description
type (required) Must be trim

Example

input: '             some badly formated string   '
schema:
  type: string
  filter: trim

Outputs:

'some badly formated string'

upcase

Turn a string to upper-case.

Parameters

Parameter Description
type (required) Must be upcase

Example

input: hElLo WoRld
schema:
  type: string
  filter:
    type: upcase

Outputs:

HELLO WORLD