Document that std.stripChars/lstripChars/rstripChars accept array as chars parameter
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 88/100
- Issue type
- Documentation
- Clarity
- Clearly specified
- Activity status
- Quiet
- Domain
- documentation
Research direction
Update doc/ref/stdlib.html at the entries for std.stripChars, std.lstripChars, and std.rstripChars. Document that chars accepts a string or array, and explain that arrays use only single-character string elements while ignoring other elements. Done means all three reference entries describe this behavior consistently.
Written by the indexing model from the issue text.
Description
Summary
The documentation for std.stripChars, std.lstripChars, and std.rstripChars currently only shows string arguments for the chars parameter. However, the reference implementation in stdlib/std.jsonnet inherently supports arrays because it uses std.member(chars, str[0]), which works with both strings and arrays.
Current behavior
When chars is an array, std.member checks if the character is an element of the array. This means:
- Single-character string elements are used as characters to strip
- Multi-character strings, numbers, booleans, null, objects, arrays are silently ignored (they never match a single character)
Examples
// Works with string (documented)
std.lstripChars("aaabcdef", "a") // "bcdef"
// Works with array (undocumented but functional)
std.lstripChars("forward", ["f", "o"]) // "rward"
std.stripChars("UwU Lel Stosh", ["h", "U", "s", {}, [], null, "w"]) // " Lel Sto"
std.lstripChars("123abc", [1, 2, 3]) // "123abc" (numbers ignored)
std.lstripChars("aabc", ["ab"]) // "aabc" (multi-char string ignored)
Cross-implementation verification
All major implementations support this behavior:
| Expression | cpp-jsonnet | go-jsonnet | sjsonnet | jrsonnet |
|---|---|---|---|---|
std.lstripChars("forward", ["f","o"]) |
"rward" |
"rward" |
"rward" |
"rward" |
std.rstripChars("cool just cool", ["o","l"]) |
"cool just c" |
"cool just c" |
"cool just c" |
"cool just c" |
std.stripChars("UwU Lel Stosh", ["h","U","s",{},[],null,"w"]) |
" Lel Sto" |
" Lel Sto" |
" Lel Sto" |
" Lel Sto" |
Proposal
Document the array parameter support in doc/ref/stdlib.html for std.stripChars, std.lstripChars, and std.rstripChars, noting that:
charscan be a string or an array- When an array is provided, only single-character string elements are used as characters to strip
- Non-string and multi-character string elements are silently ignored
- Dominant language
- Jsonnet
- Stars
- 7.6k
- Forks
- 475
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from google/jsonnet
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
Difficulty 3/5 1-2 days Newbie friendliness 78/100
-
std.format: wrong digits for %f/%d on large values; malformed output for non-integer * precision Open
Difficulty 4/5 3-5 days Newbie friendliness 52/100
-
Difficulty 5/5 Over a week Newbie friendliness 42/100
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
Similar issues
-
user-reported
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Kong/developer.konghq.com#7316 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
bug triage:deciding
Difficulty 1/5 Under an hour Newbie friendliness 88/100
open-telemetry/otel-arrow#4132 ·
-
Ecosystem: ClawMetry — the Qwen Code reader is now free and open source (follow-up to #9294 / #9338) Opencategory/integration priority/P3 scope/documentation status/ready-for-human type/feature-request
Difficulty 1/5 Under an hour Newbie friendliness 84/100