Skip to content

Add trim functionality with tests and update package exports#219

Open
ayoubjemai wants to merge 1 commit into
mattpocock:mainfrom
ayoubjemai:trim
Open

Add trim functionality with tests and update package exports#219
ayoubjemai wants to merge 1 commit into
mattpocock:mainfrom
ayoubjemai:trim

Conversation

@ayoubjemai

@ayoubjemai ayoubjemai commented May 5, 2025

Copy link
Copy Markdown

🧹 Fix: Improve typings for trim, trimStart, trimEnd, trimLeft, and trimRight on String
This PR enhances the type definitions for string trimming methods by introducing compile-time evaluation of the trimmed result. The updated types provide more precise behavior when working with string literals.

❓ Why
This makes the trimming methods more type-safe and predictable when working with string literals, especially in utility-heavy codebases where precise typing can improve DX and static analysis.

Let me know if you'd like tests or further refinements — happy to collaborate!

✅ Changes

  • Added a Whitespace type to define characters considered whitespace (" ", "\n", "\t").
  • Implemented TrimLeft and TrimRight recursive utility types to trim leading and trailing whitespace at the type level.
  • Updated the String interface to:
    • Type trim as TrimLeft<TrimRight<S>>
    • Type trimStart and trimLeft as TrimLeft<S>
    • Type trimEnd and trimRight as TrimRight<S>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants