Skip to content

Conversation

lionel-rowe
Copy link
Contributor

@lionel-rowe lionel-rowe commented Jul 29, 2025

Resolves #6265 (another attempt at abandoned #6286). Similar functionality to PHP trim/ltrim/rtrim.

  • No replacement functionality, just removal
  • Identical naming to String#trim family (not strip etc). Is this too confusing vs String#trim? Really it's the same as String#trim, just with an additional argument that can be configured (the pattern to trim).
  • Pattern arg:
    • Iterable of strings interpreted as its constituent members
    • Strips all matches (i.e. trim('aaxxbb', /[ab]/) gives xx, not axxb or axxbb)

Copy link

codecov bot commented Jul 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.19%. Comparing base (3650bce) to head (4123c75).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6778      +/-   ##
==========================================
+ Coverage   94.14%   94.19%   +0.05%     
==========================================
  Files         588      590       +2     
  Lines       42512    42577      +65     
  Branches     6701     6718      +17     
==========================================
+ Hits        40022    40106      +84     
+ Misses       2440     2421      -19     
  Partials       50       50              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kt3k
Copy link
Member

kt3k commented Jul 30, 2025

How about naming these like trimBy, trimStartBy, and trimEndBy? I think that makes it clear that these are different from builtin String#trim* APIs, and they take the 2nd args.

@lionel-rowe
Copy link
Contributor Author

How about naming these like trimBy, trimStartBy, and trimEndBy? I think that makes it clear that these are different from builtin String#trim* APIs, and they take the 2nd args.

Done. I also removed the option to use a scalar string as the argument, because IMO the behavior of treating it as chars is kinda confusing (even though that's what the equivalent PHP functions do).

@kt3k
Copy link
Member

kt3k commented Aug 7, 2025

Sorry for the delay in review.

because IMO the behavior of treating it as chars is kinda confusing

I agree with this, but how about treating trimBy(foo, bar) like trimBy(foo, [bar]) when bar is a string? I think that would cover better the original suggestion of stripPrefix

@kt3k kt3k changed the title feat(text/unstable): add trim functions feat(text/unstable): add trimBy functions Aug 12, 2025
Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you for updating! (I added some examples in docs)

@kt3k kt3k merged commit 488b387 into denoland:main Aug 12, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suggestion: stripPrefix/stripSuffix functions
2 participants