Document that std.stripChars/lstripChars/rstripChars accept array as chars parameter

Open Beginner friendly
#1,325 0 comments 0 reactions 0 assignees View on GitHub

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:

  1. chars can be a string or an array
  2. When an array is provided, only single-character string elements are used as characters to strip
  3. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from google/jsonnet

All issues in google/jsonnet

Similar issues

More Documentation issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.