google / google/jsonnet

stdlib feature request: trimSuffix/trimPrefix

Open
#1,322 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
Jsonnet
Stars
7.6k
Forks
475
PR merge metrics
No merged PRs in 30d

Description

I suspect that these are common enough needs that it would be nice to have them in the standard library.
Of course I know that I can already accomplish it with `std.endsWith`/`std.startsWith`, `std.length` and `slice` syntax:
```jsonnet
local trimSuffix(str, suffix) =
if std.endsWith(str, suffix) then
str[0:std.length(str) - std.length(suffix)]
else
str;
```
I could also use `std.strReplace` if I was 100% sure the prefix/suffix would never exist anywhere else in the string.

I'm not sure what the goal of the standard library is. Perhaps you just want to provide the minimum set of building blocks for people to make their own methods like above. If the goal is instead to provide a suite of commonly used functions, these would be a great addition to it.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.