Skip to content

Commit

Permalink
Add docs to format function
Browse files Browse the repository at this point in the history
  • Loading branch information
LilyRose2798 committed Mar 19, 2024
1 parent b9f6823 commit f516abc
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/sprinkle.gleam
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import gleam/string
import gleam/list

/// Replaces any placeholders in the given format_string
/// with the values given in the data argument.
///
/// ## Examples
///
/// ```gleam
/// format("My name is {name}!", [#("name", "Lily")])
/// // -> "My name is Lily!"
/// ```
///
pub fn format(format_string: String, data: List(#(String, String))) -> String {
list.fold(data, format_string, fn(acc, cur) {
string.replace(acc, each: "{" <> cur.0 <> "}", with: cur.1)
Expand Down

0 comments on commit f516abc

Please sign in to comment.