Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

chore: add hcl replace #3522

Merged
merged 3 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3522.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
core: Adds string `replace` function for HCL configs
```
1 change: 1 addition & 0 deletions pkg/config/funcs/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func Docs() map[string]string {
"range": "generate a list of numbers",
"regex": "match the given string against the given regular expression pattern, returning captures if defined",
"regexall": "same as regex but look for all matches of the given pattern rather than just the first",
"replace": "searches a given string for another given substring, and replaces each occurrence with a given replacement string.",
"reverse": "reverse the order of the elements in the list",
"selectormatch": "applies a selector to a map and returns true if the selector matches",
"selectorlookup": "applies a map of selectors to a map of labels. The value for the first matching selector is returned. If none match, the default is returned.",
Expand Down
1 change: 1 addition & 0 deletions pkg/config/funcs/stdlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func Stdlib() map[string]function.Function {
"range": stdlib.RangeFunc,
"regex": stdlib.RegexFunc,
"regexall": stdlib.RegexAllFunc,
"replace": stdlib.ReplaceFunc,
"reverse": stdlib.ReverseListFunc,
"setintersection": stdlib.SetIntersectionFunc,
"setproduct": stdlib.SetProductFunc,
Expand Down
8 changes: 8 additions & 0 deletions website/content/partials/funcs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,14 @@ regexall(pattern, string) list of dynamic

same as regex but look for all matches of the given pattern rather than just the first

## `replace`

```hcl
replace(str, substr, replace) string
```

searches a given string for another given substring, and replaces each occurrence with a given replacement string.

## `reverse`

```hcl
Expand Down