Skip to main content

Repeat

Mutate

Synopsis

Repeats the string in a field a given number of times, optionally joining the copies with a delimiter.

Schema

- repeat:
field: <ident>
count: <numeric>
delimiter: <string>
description: <text>
if: <script>
ignore_failure: <boolean>
ignore_missing: <boolean>
on_failure: <processor[]>
on_success: <processor[]>
tag: <string>
target_field: <ident>

Configuration

The following fields are used to define the processor:

FieldRequiredDefaultDescription
fieldY-Field containing the string to repeat
countY-Number of copies. Must be between 0 and 1024; 0 is accepted and yields an empty string
delimiterN-String inserted between copies. Empty by default, so the copies are concatenated
descriptionN-Explanatory note
ifN-Condition to run
ignore_failureNfalseSee Handling Failures
ignore_missingNfalseIf true, quietly exit if field doesn't exist
on_failureN-See Handling Failures
on_successN-See Handling Success
tagN-Identifier
disabledNfalseWhen true, the processor is skipped and the event continues to the next one. Lets you take a processor out of the path without removing its configuration
target_fieldNfieldField to store the result. Defaults to field, replacing the original

Details

The delimiter goes between copies, not after each one, so n copies carry n - 1 delimiters and the result never ends with a trailing separator.

Two counts are worth knowing:

  • count: 0 produces an empty string rather than leaving the field alone. It is a valid setting, not a no-op.
  • A negative count is an error, as is anything above 1024. The cap is a guard against a configuration that would otherwise build an arbitrarily large string in memory.

The field must hold a string. An array, a number or an object is an error.

Examples

Simple Repetition

Repeating a string with no delimiter...

{
"separator": "-"
}
- repeat:
field: separator
count: 20
target_field: rule

concatenates the copies:

{
"separator": "-",
"rule": "--------------------"
}

With a Delimiter

A delimiter is placed between copies, never after the last...

{
"placeholder": "?"
}
- repeat:
field: placeholder
count: 3
delimiter: ", "
target_field: bind_list

giving two delimiters for three copies:

{
"placeholder": "?",
"bind_list": "?, ?, ?"
}

Zero Copies

A count of zero is legitimate and produces an empty string...

{
"padding": "*",
"width": 0
}
- repeat:
field: padding
count: 0
target_field: pad

rather than leaving the target unset:

{
"padding": "*",
"width": 0,
"pad": ""
}