jorgengranseth / elm-string-format / String.Format

Simple, pipable helpers to avoid difficult-to-read String concatenation by interpolating String values.

You can either specify placeholder names or push values into the next empty placeholder.

"""
{{ named }} is replaced everywhere {{ named }},
whereas empty placeholders: {{ }} and {{ }},
act as unique slots for the value function
"""
    |> String.Format.value "first"
    |> String.Format.namedValue "named" "yay!"
    |> String.Format.value "second"

-- """
-- yay! is replaced everywhere yay!,
-- whereas empty placeholders: first and second,
-- act as unique slots for the value function
-- """

Formatters

namedValue : String -> String -> String -> String

Interpolate a named placeholder

"What happened to the {{ food }}? Maybe {{ person }} ate it?"
    |> String.Format.namedValue "food" "cake"
    |> String.Format.namedValue "person" "Joe"

-- "What happened to the cake? Maybe Joe ate it?"

value : String -> String -> String

Interpolate the next unnamed placeholder

"{{ }} comes before {{ }}"
    |> String.Format.value "dinner"
    |> String.Format.value "dessert"

-- "dinner comes before dessert"